当前位置: 首页>>代码示例>>Python>>正文


Python events.EditDocumentEvent类代码示例

本文整理汇总了Python中kitsune.wiki.events.EditDocumentEvent的典型用法代码示例。如果您正苦于以下问题:Python EditDocumentEvent类的具体用法?Python EditDocumentEvent怎么用?Python EditDocumentEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EditDocumentEvent类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: watch_document

def watch_document(request, document_slug):
    """Start watching a document for edits."""
    document = get_object_or_404(
        Document, locale=request.LANGUAGE_CODE, slug=document_slug)
    EditDocumentEvent.notify(request.user, document)
    statsd.incr('wiki.watches.document')
    return HttpResponseRedirect(document.get_absolute_url())
开发者ID:atishrails,项目名称:kitsune,代码行数:7,代码来源:views.py

示例2: unwatch_document

def unwatch_document(request, document_slug):
    """Stop watching a document for edits."""
    document = get_object_or_404(
        Document, locale=request.LANGUAGE_CODE, slug=document_slug)
    EditDocumentEvent.stop_notifying(request.user, document)
    return HttpResponseRedirect(document.get_absolute_url())
开发者ID:atishrails,项目名称:kitsune,代码行数:6,代码来源:views.py

示例3: translate


#.........这里部分代码省略.........
        # localization", this will first try to find an approved revision, then
        # an unrejected one, then give up.
        instance = doc and doc.localizable_or_latest_revision()

        rev_form = RevisionForm(instance=instance, initial=initial)
        base_rev = base_rev or instance

    if request.method == 'POST':
        which_form = request.POST.get('form', 'both')
        doc_form_invalid = False

        if doc is not None:
            _document_lock_clear(doc.id, user.username)

        if user_has_doc_perm and which_form in ['doc', 'both']:
            disclose_description = True
            post_data = request.POST.copy()
            post_data.update({'locale': request.LANGUAGE_CODE})
            doc_form = DocumentForm(post_data, instance=doc)
            doc_form.instance.locale = request.LANGUAGE_CODE
            doc_form.instance.parent = parent_doc
            if which_form == 'both':
                rev_form = RevisionForm(request.POST)

            # If we are submitting the whole form, we need to check that
            # the Revision is valid before saving the Document.
            if doc_form.is_valid() and (which_form == 'doc' or
                                        rev_form.is_valid()):
                doc = doc_form.save(parent_doc)

                # Possibly schedule a rebuild.
                _maybe_schedule_rebuild(doc_form)

                if which_form == 'doc':
                    url = urlparams(reverse('wiki.edit_document',
                                            args=[doc.slug]),
                                    opendescription=1)
                    return HttpResponseRedirect(url)

                doc_slug = doc_form.cleaned_data['slug']
            else:
                doc_form_invalid = True
        else:
            doc_slug = doc.slug

        if doc and user_has_rev_perm and which_form in ['rev', 'both']:
            rev_form = RevisionForm(request.POST)
            rev_form.instance.document = doc  # for rev_form.clean()

            if rev_form.is_valid() and not doc_form_invalid:
                if 'no-update' in request.POST:
                    # Keep the old based_on.
                    based_on_id = base_rev.based_on_id
                else:
                    # Keep what was in the form.
                    based_on_id = None

                _save_rev_and_notify(rev_form, request.user, doc, based_on_id,
                                     base_rev=base_rev)

                if 'notify-future-changes' in request.POST:
                    EditDocumentEvent.notify(request.user, doc)

                url = reverse('wiki.document_revisions',
                              args=[doc_slug])

                return HttpResponseRedirect(url)

    show_revision_warning = _show_revision_warning(doc, base_rev)

    # A list of the revisions that have been approved since the last
    # translation.
    recent_approved_revs = parent_doc.revisions.filter(
        is_approved=True, id__lte=based_on_rev.id)
    if doc and doc.current_revision and doc.current_revision.based_on_id:
        recent_approved_revs = recent_approved_revs.filter(
            id__gt=doc.current_revision.based_on_id)

    if doc:
        locked, locked_by = _document_lock(doc.id, user.username)
    else:
        locked, locked_by = False, None

    product_slugs = [p.slug for p in (doc or parent_doc).products.all()]
    fxos_l10n_warning = ('firefox-os' in product_slugs and
                         request.LANGUAGE_CODE not in settings.FXOS_LANGUAGES)

    return render(request, 'wiki/translate.html', {
        'parent': parent_doc,
        'document': doc,
        'document_form': doc_form,
        'revision_form': rev_form,
        'locale': request.LANGUAGE_CODE,
        'based_on': based_on_rev,
        'disclose_description': disclose_description,
        'show_revision_warning': show_revision_warning,
        'recent_approved_revs': recent_approved_revs,
        'locked': locked,
        'locked_by': locked_by,
        'fxos_l10n_warning': fxos_l10n_warning})
开发者ID:atishrails,项目名称:kitsune,代码行数:101,代码来源:views.py

示例4: edit_document

def edit_document(request, document_slug, revision_id=None):
    """Create a new revision of a wiki document, or edit document metadata."""
    doc = get_object_or_404(
        Document, locale=request.LANGUAGE_CODE, slug=document_slug)
    user = request.user

    can_edit_needs_change = doc.allows(user, 'edit_needs_change')
    can_archive = doc.allows(user, 'archive')

    # If this document has a parent, then the edit is handled by the
    # translate view. Pass it on.
    if doc.parent:
        return translate(request, doc.parent.slug, revision_id)
    if revision_id:
        rev = get_object_or_404(Revision, pk=revision_id, document=doc)
    else:
        rev = doc.current_revision or doc.revisions.order_by('-created',
                                                             '-id')[0]

    disclose_description = bool(request.GET.get('opendescription'))
    doc_form = rev_form = None
    if doc.allows(user, 'create_revision'):
        rev_form = RevisionForm(
            instance=rev,
            initial={'based_on': rev.id, 'comment': ''})
    if doc.allows(user, 'edit'):
        doc_form = DocumentForm(
            initial=_document_form_initial(doc),
            can_archive=can_archive,
            can_edit_needs_change=can_edit_needs_change)

    if request.method == 'GET':
        if not (rev_form or doc_form):
            # You can't do anything on this page, so get lost.
            raise PermissionDenied

    else:  # POST
        # Comparing against localized names for the Save button bothers me, so
        # I embedded a hidden input:
        which_form = request.POST.get('form')

        _document_lock_clear(doc.id, user.username)

        if which_form == 'doc':
            if doc.allows(user, 'edit'):
                post_data = request.POST.copy()
                post_data.update({'locale': request.LANGUAGE_CODE})
                doc_form = DocumentForm(
                    post_data,
                    instance=doc,
                    can_archive=can_archive,
                    can_edit_needs_change=can_edit_needs_change)
                if doc_form.is_valid():
                    # Get the possibly new slug for the imminent redirection:
                    doc = doc_form.save(None)

                    # Do we need to rebuild the KB?
                    _maybe_schedule_rebuild(doc_form)

                    return HttpResponseRedirect(
                        urlparams(reverse('wiki.edit_document',
                                          args=[doc.slug]),
                                  opendescription=1))
                disclose_description = True
            else:
                raise PermissionDenied
        elif which_form == 'rev':
            if doc.allows(user, 'create_revision'):
                rev_form = RevisionForm(request.POST)
                rev_form.instance.document = doc  # for rev_form.clean()
                if rev_form.is_valid():
                    _save_rev_and_notify(rev_form, user, doc, base_rev=rev)
                    if 'notify-future-changes' in request.POST:
                        EditDocumentEvent.notify(request.user, doc)

                    return HttpResponseRedirect(
                        reverse('wiki.document_revisions',
                                args=[document_slug]))
            else:
                raise PermissionDenied

    show_revision_warning = _show_revision_warning(doc, rev)
    locked, locked_by = _document_lock(doc.id, user.username)

    return render(request, 'wiki/edit.html', {
        'revision_form': rev_form,
        'document_form': doc_form,
        'disclose_description': disclose_description,
        'document': doc,
        'show_revision_warning': show_revision_warning,
        'locked': locked,
        'locked_by': locked_by})
开发者ID:atishrails,项目名称:kitsune,代码行数:92,代码来源:views.py

示例5: is_watched_by

 def is_watched_by(self, user):
     """Return whether `user` is notified of edits to me."""
     from kitsune.wiki.events import EditDocumentEvent
     return EditDocumentEvent.is_notifying(user, self)
开发者ID:RobbyGenius73,项目名称:kitsune,代码行数:4,代码来源:models.py

示例6: edit_document

def edit_document(request, document_slug, revision_id=None):
    """Create a new revision of a wiki document, or edit document metadata."""
    doc = get_object_or_404(Document, locale=request.LANGUAGE_CODE, slug=document_slug)
    user = request.user

    can_edit_needs_change = doc.allows(user, "edit_needs_change")
    can_archive = doc.allows(user, "archive")

    # If this document has a parent, then the edit is handled by the
    # translate view. Pass it on.
    if doc.parent:
        return translate(request, doc.parent.slug, revision_id)
    if revision_id:
        rev = get_object_or_404(Revision, pk=revision_id, document=doc)
    else:
        rev = doc.current_revision or doc.revisions.order_by("-created", "-id")[0]

    disclose_description = bool(request.GET.get("opendescription"))
    doc_form = rev_form = None
    if doc.allows(user, "create_revision"):
        rev_form = RevisionForm(instance=rev, initial={"based_on": rev.id, "comment": ""})
    if doc.allows(user, "edit"):
        doc_form = DocumentForm(
            initial=_document_form_initial(doc), can_archive=can_archive, can_edit_needs_change=can_edit_needs_change
        )

    if request.method == "GET":
        if not (rev_form or doc_form):
            # You can't do anything on this page, so get lost.
            raise PermissionDenied

    else:  # POST
        # Comparing against localized names for the Save button bothers me, so
        # I embedded a hidden input:
        which_form = request.POST.get("form")

        _document_lock_clear(doc.id, user.username)

        if which_form == "doc":
            if doc.allows(user, "edit"):
                post_data = request.POST.copy()
                post_data.update({"locale": request.LANGUAGE_CODE})

                topics = []
                for t in post_data.getlist("topics"):
                    topics.append(long(t))
                post_data.setlist("topics", topics)

                doc_form = DocumentForm(
                    post_data, instance=doc, can_archive=can_archive, can_edit_needs_change=can_edit_needs_change
                )
                if doc_form.is_valid():
                    # Get the possibly new slug for the imminent redirection:
                    try:
                        doc = doc_form.save(None)
                    except (TitleCollision, SlugCollision) as e:
                        # TODO: .add_error() when we upgrade to Django 1.7
                        errors = doc_form._errors.setdefault("title", ErrorList())
                        message = "The {type} you selected is already in use."
                        message = message.format(type="title" if isinstance(e, TitleCollision) else "slug")
                        errors.append(_(message))
                    else:
                        # Do we need to rebuild the KB?
                        _maybe_schedule_rebuild(doc_form)

                        return HttpResponseRedirect(
                            urlparams(reverse("wiki.edit_document", args=[doc.slug]), opendescription=1)
                        )
                disclose_description = True
            else:
                raise PermissionDenied
        elif which_form == "rev":
            if doc.allows(user, "create_revision"):
                rev_form = RevisionForm(request.POST)
                rev_form.instance.document = doc  # for rev_form.clean()
                if rev_form.is_valid():
                    _save_rev_and_notify(rev_form, user, doc, base_rev=rev)
                    if "notify-future-changes" in request.POST:
                        EditDocumentEvent.notify(request.user, doc)

                    return HttpResponseRedirect(reverse("wiki.document_revisions", args=[document_slug]))
            else:
                raise PermissionDenied

    show_revision_warning = _show_revision_warning(doc, rev)
    locked, locked_by = _document_lock(doc.id, user.username)

    return render(
        request,
        "wiki/edit.html",
        {
            "revision_form": rev_form,
            "document_form": doc_form,
            "disclose_description": disclose_description,
            "document": doc,
            "show_revision_warning": show_revision_warning,
            "locked": locked,
            "locked_by": locked_by,
        },
    )
开发者ID:runt18,项目名称:kitsune,代码行数:100,代码来源:views.py


注:本文中的kitsune.wiki.events.EditDocumentEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。