本文整理汇总了Python中wiki.models.get_current_or_latest_revision函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_or_latest_revision函数的具体用法?Python get_current_or_latest_revision怎么用?Python get_current_or_latest_revision使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_current_or_latest_revision函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_latest_rejected
def test_latest_rejected(self):
"""Return latest rejected revision when no current exists."""
r1 = revision(is_approved=False, reviewed=None, save=True,
created=datetime.now() - timedelta(days=1))
r2 = revision(is_approved=False, save=True, document=r1.document)
eq_(r2, get_current_or_latest_revision(r1.document,
reviewed_only=False))
示例2: test_approved_over_most_recent
def test_approved_over_most_recent(self):
"""Should return most recently approved when there is a more recent
unreviewed revision."""
r1 = revision(is_approved=True, save=True,
created=datetime.now() - timedelta(days=1))
r2 = revision(is_approved=False, reviewed=None, save=True,
document=r1.document)
eq_(r1, get_current_or_latest_revision(r2.document))
示例3: review_revision
def review_revision(request, document_slug, revision_id):
"""Review a revision of a wiki document."""
rev = get_object_or_404(Revision, pk=revision_id,
document__slug=document_slug)
doc = rev.document
form = ReviewForm()
# Don't ask significance if this doc is a translation or if it has no
# former approved versions:
should_ask_significance = not doc.parent and doc.current_revision
if request.method == 'POST':
form = ReviewForm(request.POST)
if form.is_valid() and not rev.reviewed:
# Don't allow revisions to be reviewed twice
rev.is_approved = 'approve' in request.POST
rev.reviewer = request.user
rev.reviewed = datetime.now()
if should_ask_significance and form.cleaned_data['significance']:
rev.significance = form.cleaned_data['significance']
rev.save()
# Send an email (not really a "notification" in the sense that
# there's a Watch table entry) to revision creator.
msg = form.cleaned_data['comment']
send_reviewed_notification.delay(rev, doc, msg)
# If approved, send approved notification
ApproveRevisionInLocaleEvent(rev).fire(exclude=rev.creator)
# Schedule KB rebuild?
schedule_rebuild_kb()
return HttpResponseRedirect(reverse('wiki.document_revisions',
args=[document_slug]))
if doc.parent: # A translation
parent_revision = get_current_or_latest_revision(doc.parent)
template = 'wiki/review_translation.html'
else:
parent_revision = None
template = 'wiki/review_revision.html'
data = {'revision': rev, 'document': doc, 'form': form,
'parent_revision': parent_revision,
'should_ask_significance': should_ask_significance}
data.update(SHOWFOR_DATA)
return jingo.render(request, template, data)
示例4: test_multiple_approved
def test_multiple_approved(self):
"""When multiple approved revisions exist, return the most recent."""
r1 = revision(is_approved=True, save=True)
r2 = revision(is_approved=True, save=True, document=r1.document)
eq_(r2, get_current_or_latest_revision(r2.document))
示例5: test_single_rejected
def test_single_rejected(self):
"""No approved revisions available should return None."""
rev = revision(is_approved=False)
eq_(None, get_current_or_latest_revision(rev.document))
示例6: test_single_approved
def test_single_approved(self):
"""Get approved revision."""
rev = revision(is_approved=True, save=True)
eq_(rev, get_current_or_latest_revision(rev.document))
示例7: translate
def translate(request, document_slug, revision_id=None):
"""Create a new translation of a wiki document.
* document_slug is for the default locale
* translation is to the request locale
"""
# TODO: Refactor this view into two views? (new, edit)
# That might help reduce the headache-inducing branchiness.
parent_doc = get_object_or_404(
Document, locale=settings.WIKI_DEFAULT_LANGUAGE, slug=document_slug)
user = request.user
if settings.WIKI_DEFAULT_LANGUAGE == request.locale:
# Don't translate to the default language.
return HttpResponseRedirect(reverse(
'wiki.edit_document', locale=settings.WIKI_DEFAULT_LANGUAGE,
args=[parent_doc.slug]))
if not parent_doc.is_localizable:
message = _lazy(u'You cannot translate this document.')
return jingo.render(request, 'handlers/400.html',
{'message': message}, status=400)
based_on_rev = get_current_or_latest_revision(parent_doc,
reviewed_only=False)
disclose_description = bool(request.GET.get('opendescription'))
try:
doc = parent_doc.translations.get(locale=request.locale)
except Document.DoesNotExist:
doc = None
disclose_description = True
user_has_doc_perm = ((not doc) or (doc and doc.allows_editing_by(user)))
user_has_rev_perm = ((not doc) or (doc and doc.allows_revision_by(user)))
if not user_has_doc_perm and not user_has_rev_perm:
# User has no perms, bye.
raise PermissionDenied
doc_form = rev_form = None
if user_has_doc_perm:
doc_initial = _document_form_initial(doc) if doc else None
doc_form = DocumentForm(initial=doc_initial,
can_create_tags=user.has_perm('taggit.add_tag'))
if user_has_rev_perm:
initial = {'based_on': based_on_rev.id, 'comment': ''}
if revision_id:
r = Revision.objects.get(pk=revision_id)
initial.update(content=r.content, summary=r.summary,
keywords=r.keywords)
elif not doc:
initial.update(content=based_on_rev.content,
summary=based_on_rev.summary,
keywords=based_on_rev.keywords)
instance = doc and get_current_or_latest_revision(doc)
rev_form = RevisionForm(instance=instance, initial=initial)
if request.method == 'POST':
which_form = request.POST.get('form', 'both')
doc_form_invalid = False
if user_has_doc_perm and which_form in ['doc', 'both']:
disclose_description = True
post_data = request.POST.copy()
post_data.update({'locale': request.locale})
doc_form = DocumentForm(post_data, instance=doc,
can_create_tags=user.has_perm('taggit.add_tag'))
doc_form.instance.locale = request.locale
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:
#.........这里部分代码省略.........