def render_readouts(request, readouts, template, locale=None, extra_data=None, product=None): """Render a readouts, possibly with overview page. Use the given template, pass the template the given readouts, limit the considered data to the given locale, and pass along anything in the `extra_data` dict to the template in addition to the standard data. """ current_locale = locale or request.LANGUAGE_CODE on_default_locale = request.LANGUAGE_CODE == settings.WIKI_DEFAULT_LANGUAGE data = { 'readouts': SortedDict((slug, class_(request, locale=locale, product=product)) for slug, class_ in readouts.iteritems() if class_.should_show_to(request)), 'default_locale': settings.WIKI_DEFAULT_LANGUAGE, 'default_locale_name': LOCALES[settings.WIKI_DEFAULT_LANGUAGE].native, 'current_locale': current_locale, 'current_locale_name': LOCALES[current_locale].native, 'request_locale_name': LOCALES[request.LANGUAGE_CODE].native, 'is_watching_default_approved': ApproveRevisionInLocaleEvent.is_notifying( request.user, locale=settings.WIKI_DEFAULT_LANGUAGE), 'is_watching_other_approved': None if on_default_locale else ApproveRevisionInLocaleEvent.is_notifying( request.user, locale=request.LANGUAGE_CODE), 'is_watching_default_locale': ReviewableRevisionInLocaleEvent.is_notifying( request.user, locale=settings.WIKI_DEFAULT_LANGUAGE), 'is_watching_other_locale': None if on_default_locale else ReviewableRevisionInLocaleEvent.is_notifying( request.user, locale=request.LANGUAGE_CODE), 'is_watching_default_ready': ReadyRevisionEvent.is_notifying(request.user), 'on_default_locale': on_default_locale, 'announce_form': AnnouncementForm(), 'announcements': Announcement.get_for_locale_name(current_locale), 'product': product, 'products': Product.objects.filter(visible=True), } if extra_data: data.update(extra_data) return render(request, 'dashboards/' + template, data)
def watch_approved(request): """Start watching approved revisions in a locale.""" if request.locale not in settings.SUMO_LANGUAGES: raise Http404 ApproveRevisionInLocaleEvent.notify(request.user, locale=request.locale) statsd.incr('wiki.watches.approved') return HttpResponse()
def _kb_main(request, readouts, template, locale=None, extra_data=None): """Render a KB statistics overview page. Use the given template, pass the template the given readouts, limit the considered data to the given locale, and pass along anything in the `extra_data` dict to the template in addition to the standard data. """ data = { 'readouts': SortedDict((slug, class_(request, locale=locale)) for slug, class_ in readouts.iteritems()), 'default_locale': settings.WIKI_DEFAULT_LANGUAGE, 'default_locale_name': LOCALES[settings.WIKI_DEFAULT_LANGUAGE].native, 'current_locale_name': LOCALES[request.locale].native, 'is_watching_approved': ApproveRevisionInLocaleEvent.is_notifying(request.user, locale=request.locale), 'is_watching_locale': ReviewableRevisionInLocaleEvent.is_notifying(request.user, locale=request.locale), 'is_watching_approved_default': ApproveRevisionInLocaleEvent.is_notifying( request.user, locale=settings.WIKI_DEFAULT_LANGUAGE) } if extra_data: data.update(extra_data) return jingo.render(request, 'dashboards/' + template, data)
def unwatch_approved(request): """Stop watching approved revisions.""" if request.locale not in settings.SUMO_LANGUAGES: raise Http404 ApproveRevisionInLocaleEvent.stop_notifying(request.user, locale=request.locale) return HttpResponse()
def render_readouts(request, readouts, template, locale=None, extra_data=None): """Render a readouts, possibly with overview page. Use the given template, pass the template the given readouts, limit the considered data to the given locale, and pass along anything in the `extra_data` dict to the template in addition to the standard data. """ current_locale = locale or request.locale data = {'readouts': SortedDict((slug, class_(request, locale=locale)) for slug, class_ in readouts.iteritems()), 'default_locale': settings.WIKI_DEFAULT_LANGUAGE, 'default_locale_name': LOCALES[settings.WIKI_DEFAULT_LANGUAGE].native, 'current_locale': current_locale, 'current_locale_name': LOCALES[current_locale].native, 'is_watching_approved': ApproveRevisionInLocaleEvent.is_notifying( request.user, locale=request.locale), 'is_watching_locale': ReviewableRevisionInLocaleEvent.is_notifying( request.user, locale=request.locale), 'is_watching_approved_default': ApproveRevisionInLocaleEvent.is_notifying( request.user, locale=settings.WIKI_DEFAULT_LANGUAGE)} if extra_data: data.update(extra_data) return jingo.render(request, 'dashboards/' + template, data)
def unwatch_approved(request): """Stop watching approved revisions.""" locale = request.POST.get('locale') if locale not in settings.SUMO_LANGUAGES: raise Http404 ApproveRevisionInLocaleEvent.stop_notifying(request.user, locale=locale) return HttpResponseRedirect(_get_next_url_fallback_localization(request))
def unwatch_approved(request): """Stop watching approved revisions.""" locale = request.POST.get('locale') if locale not in settings.SUMO_LANGUAGES: raise Http404 ApproveRevisionInLocaleEvent.stop_notifying(request.user, locale=locale) return HttpResponseRedirect(reverse('dashboards.localization'))
def setUp(self): """Have a user watch for revision approval. Log in.""" self.approved_watcher = user(email='*****@*****.**', save=True) ApproveRevisionInLocaleEvent.notify(self.approved_watcher, locale='en-US') approver = user(save=True) add_permission(approver, Revision, 'review_revision') add_permission(approver, Revision, 'mark_ready_for_l10n') self.client.login(username=approver.username, password='******')
def render_readouts(request, readouts, template, locale=None, extra_data=None, product=None): """Render a readouts, possibly with overview page. Use the given template, pass the template the given readouts, limit the considered data to the given locale, and pass along anything in the `extra_data` dict to the template in addition to the standard data. """ current_locale = locale or request.LANGUAGE_CODE on_default_locale = request.LANGUAGE_CODE == settings.WIKI_DEFAULT_LANGUAGE data = {'readouts': SortedDict((slug, class_(request, locale=locale, product=product)) for slug, class_ in readouts.iteritems() if class_.should_show_to(request.user)), 'default_locale': settings.WIKI_DEFAULT_LANGUAGE, 'default_locale_name': LOCALES[settings.WIKI_DEFAULT_LANGUAGE].native, 'current_locale': current_locale, 'current_locale_name': LOCALES[current_locale].native, 'request_locale_name': LOCALES[request.LANGUAGE_CODE].native, 'is_watching_default_approved': ApproveRevisionInLocaleEvent.is_notifying( request.user, locale=settings.WIKI_DEFAULT_LANGUAGE), 'is_watching_other_approved': None if on_default_locale else ApproveRevisionInLocaleEvent.is_notifying( request.user, locale=request.LANGUAGE_CODE), 'is_watching_default_locale': ReviewableRevisionInLocaleEvent.is_notifying( request.user, locale=settings.WIKI_DEFAULT_LANGUAGE), 'is_watching_other_locale': None if on_default_locale else ReviewableRevisionInLocaleEvent.is_notifying( request.user, locale=request.LANGUAGE_CODE), 'is_watching_default_ready': ReadyRevisionEvent.is_notifying(request.user), 'on_default_locale': on_default_locale, 'announce_form': AnnouncementForm(), 'announcements': Announcement.get_for_locale_name(current_locale), 'product': product, 'products': Product.objects.filter(visible=True), } if extra_data: data.update(extra_data) return jingo.render(request, 'dashboards/' + template, data)
def _kb_main(request, readouts, template, locale=None, extra_data=None): """Render a KB statistics overview page. Use the given template, pass the template the given readouts, limit the considered data to the given locale, and pass along anything in the `extra_data` dict to the template in addition to the standard data. """ data = { "readouts": SortedDict((slug, class_(request, locale=locale)) for slug, class_ in readouts.iteritems()), "default_locale": settings.WIKI_DEFAULT_LANGUAGE, "default_locale_name": LOCALES[settings.WIKI_DEFAULT_LANGUAGE].native, "current_locale_name": LOCALES[request.locale].native, "is_watching_approved": ApproveRevisionInLocaleEvent.is_notifying(request.user, locale=request.locale), "is_watching_locale": ReviewableRevisionInLocaleEvent.is_notifying(request.user, locale=request.locale), "is_watching_approved_default": ApproveRevisionInLocaleEvent.is_notifying( request.user, locale=settings.WIKI_DEFAULT_LANGUAGE ), } if extra_data: data.update(extra_data) return render(request, "dashboards/" + template, data)
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() 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 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 } data.update(SHOWFOR_DATA) return jingo.render(request, template, data)
def setUp(self): """Have a user watch for revision approval. Log in.""" self.approved_watcher = user(email='*****@*****.**', save=True) ApproveRevisionInLocaleEvent.notify(self.approved_watcher, locale='en-US') self.client.login(username='******', password='******')
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( initial={ 'needs_change': doc.needs_change, 'needs_change_comment': doc.needs_change_comment }) # 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 based_on_revs = doc.revisions.all() last_approved_date = getattr(doc.current_revision, 'created', datetime.fromordinal(1)) based_on_revs = based_on_revs.filter(created__gt=last_approved_date) revision_contributors = list( set(based_on_revs.values_list('creator__username', flat=True))) # Don't include the reviewer in the recent contributors list. if request.user.username in revision_contributors: revision_contributors.remove(request.user.username) 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'] # If document is localizable and revision was approved and # user has permission, set the is_ready_for_localization value. if (doc.is_localizable and rev.is_approved and request.user.has_perm('wiki.mark_ready_for_l10n')): rev.is_ready_for_localization = form.cleaned_data[ 'is_ready_for_localization'] rev.save() # Update the needs change bit (if approved, default language and # user has permission). if (doc.locale == settings.WIKI_DEFAULT_LANGUAGE and doc.allows_editing_by(request.user) and rev.is_approved): doc.needs_change = form.cleaned_data['needs_change'] doc.needs_change_comment = \ form.cleaned_data['needs_change_comment'] doc.save() # Send notifications of approvedness and readiness: if rev.is_ready_for_localization or rev.is_approved: events = [ApproveRevisionInLocaleEvent(rev)] if rev.is_ready_for_localization: events.append(ReadyRevisionEvent(rev)) ApprovedOrReadyUnion(*events).fire( exclude=[rev.creator, request.user]) # 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) send_contributor_notification(based_on_revs, rev, doc, msg) # Schedule KB rebuild? statsd.incr('wiki.review') schedule_rebuild_kb() return HttpResponseRedirect( reverse('wiki.document_revisions', args=[document_slug])) if doc.parent: # A translation # For diffing the based_on revision against, to help the user see if he # translated all the recent changes: parent_revision = doc.parent.localizable_or_latest_revision() 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, 'revision_contributors': list(revision_contributors), 'should_ask_significance': should_ask_significance } data.update(SHOWFOR_DATA) return jingo.render(request, template, data)
def setUp(self): """Have a user watch for revision approval. Log in.""" self.approved_watcher = user(email="*****@*****.**", save=True) ApproveRevisionInLocaleEvent.notify(self.approved_watcher, locale="en-US") self.client.login(username="******", password="******")