Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
create queue for re-reviewed themes (bug 851882)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin committed May 13, 2013
1 parent 2d07e3b commit bec27ef
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 157 deletions.
62 changes: 59 additions & 3 deletions mkt/reviewers/forms.py
@@ -1,3 +1,6 @@
import datetime
import logging

from django import forms

import happyforms
Expand All @@ -12,7 +15,10 @@
from mkt.reviewers.utils import ReviewHelper

from .models import ThemeLock
from .tasks import send_mail
from .tasks import approve_rereview, reject_rereview, send_mail


log = logging.getLogger('z.reviewers.forms')


class ReviewAppAttachmentForm(happyforms.Form):
Expand Down Expand Up @@ -145,13 +151,63 @@ def clean_comment(self):
return comment

def save(self):
action = self.cleaned_data['action']
comment = self.cleaned_data.get('comment')
reject_reason = self.cleaned_data.get('reject_reason')
theme = self.cleaned_data['theme']
is_rereview = theme.rereviewqueuetheme_set.exists()

theme_lock = ThemeLock.objects.get(theme=self.cleaned_data['theme'])
send_mail(self.cleaned_data, theme_lock)

mail_and_log = True
if action == rvw.ACTION_APPROVE:
if is_rereview:
approve_rereview(theme)
theme.addon.update(status=amo.STATUS_PUBLIC)
theme.approve = datetime.datetime.now()
theme.save()

elif action == rvw.ACTION_REJECT:
if is_rereview:
reject_rereview(theme)
else:
theme.addon.update(status=amo.STATUS_REJECTED)

elif action == rvw.ACTION_DUPLICATE:
if is_rereview:
reject_rereview(theme)
else:
theme.addon.update(status=amo.STATUS_REJECTED)

elif action == rvw.ACTION_FLAG:
if is_rereview:
mail_and_log = False
else:
theme.addon.update(status=amo.STATUS_REVIEW_PENDING)

elif action == rvw.ACTION_MOREINFO:
if is_rereview:
mail_and_log = False
else:
theme.addon.update(status=amo.STATUS_REVIEW_PENDING)

if mail_and_log:
send_mail(self.cleaned_data, theme_lock)

# Log.
amo.log(amo.LOG.THEME_REVIEW, theme.addon, details={
'action': action,
'reject_reason': reject_reason,
'comment': comment}, user=theme_lock.reviewer)
log.info('%sTheme %s (%s) - %s' % (
'[Rereview] ' if is_rereview else '', theme.addon.name,
theme.id, action))

theme_lock.delete()


class ThemeSearchForm(forms.Form):
q = forms.CharField(
required=False, label=_lazy(u'Search'),
widget=forms.TextInput(attrs={'autocomplete': 'off',
'placeholder': _lazy(u'Search')}))
'placeholder': _lazy(u'Search')}))
3 changes: 3 additions & 0 deletions mkt/reviewers/helpers.py
Expand Up @@ -126,6 +126,9 @@ def queue_tabnav_themes(context):
tabs.append((
'themes', 'flagged', 'queue_flagged', _('Flagged'),
))
tabs.append((
'themes', 'rereview', 'queue_rereview', _('Re-review'),
))
return tabs


Expand Down
54 changes: 33 additions & 21 deletions mkt/reviewers/tasks.py
@@ -1,33 +1,29 @@
import datetime
import logging

from django.conf import settings

from celeryutils import task
from tower import ugettext as _

import amo
from amo.utils import send_mail_jinja
from amo.storage_utils import move_stored_file
from amo.utils import LocalFileStorage, send_mail_jinja
import mkt.constants.reviewers as rvw


log = logging.getLogger('z.task')


@task
def send_mail(cleaned_data, theme_lock):
"""
Send emails out for respective review actions taken on themes.
"""
theme = cleaned_data['theme']
action = cleaned_data['action']
comment = cleaned_data['comment']
reject_reason = cleaned_data['reject_reason']

reason = None
if reject_reason:
reason = rvw.THEME_REJECT_REASONS[reject_reason]
elif action == rvw.ACTION_DUPLICATE:
reason = _('Duplicate Submission')
comment = cleaned_data['comment']

emails = set(theme.addon.authors.values_list('email', flat=True))
cc = settings.THEMES_EMAIL
Expand All @@ -47,17 +43,14 @@ def send_mail(cleaned_data, theme_lock):
elif action == rvw.ACTION_REJECT:
subject = _('A problem with your Theme submission')
template = 'reviewers/themes/emails/reject.html'
theme.addon.update(status=amo.STATUS_REJECTED)

elif action == rvw.ACTION_DUPLICATE:
subject = _('A problem with your Theme submission')
template = 'reviewers/themes/emails/reject.html'
theme.addon.update(status=amo.STATUS_REJECTED)

elif action == rvw.ACTION_FLAG:
subject = _('Theme submission flagged for review')
template = 'reviewers/themes/emails/flag_reviewer.html'
theme.addon.update(status=amo.STATUS_REVIEW_PENDING)

# Send the flagged email to themes email.
emails = [settings.THEMES_EMAIL]
Expand All @@ -67,18 +60,37 @@ def send_mail(cleaned_data, theme_lock):
subject = _('A question about your Theme submission')
template = 'reviewers/themes/emails/moreinfo.html'
context['reviewer_email'] = theme_lock.reviewer.email
theme.addon.update(status=amo.STATUS_REVIEW_PENDING)

amo.log(amo.LOG.THEME_REVIEW, theme.addon, details={
'action': action,
'reject_reason': reject_reason,
'comment': comment}, user=theme_lock.reviewer)
log.info('Theme %s (%s) - %s' % (theme.addon.name, theme.id, action))

theme.approve = datetime.datetime.now()
theme.save()

send_mail_jinja(subject, template, context,
recipient_list=emails, cc=cc,
from_email=settings.ADDONS_EMAIL,
headers={'Reply-To': settings.THEMES_EMAIL})


@task
def approve_rereview(theme):
"""Replace original theme with pending theme on filesystem."""
# If reuploaded theme, replace old theme design.
storage = LocalFileStorage()
rereview = theme.rereviewqueuetheme_set.all()
reupload = rereview[0]

move_stored_file(
reupload.header_path, reupload.original_header_path,
storage=storage)
move_stored_file(
reupload.footer_path, reupload.original_footer_path,
storage=storage)
rereview.delete()


@task
def reject_rereview(theme):
"""Replace original theme with pending theme on filesystem."""
storage = LocalFileStorage()
rereview = theme.rereviewqueuetheme_set.all()
reupload = rereview[0]

storage.delete(reupload.header_path)
storage.delete(reupload.footer_path)
rereview.delete()
6 changes: 4 additions & 2 deletions mkt/reviewers/templates/reviewers/themes/queue.html
Expand Up @@ -71,10 +71,12 @@ <h2>{{ _('Keyboard Shortcuts') }}</h2>
<li><strong>A</strong> <span>{{ _('Approve') }}</span></li>
<li><strong>R</strong> <span>{{ _('Reject') }}</span></li>
<li><strong>D</strong> <span>{{ _('Duplicate') }}</span></li>
{% if not flagged %}
{% if not flagged and not rereview %}
<li><strong>F</strong> <span>{{ _('Flag') }}</span></li>
{% endif %}
<li><strong>M</strong> <span>{{ _('Request More Info') }}</span></li>
{% if not rereview %}
<li><strong>M</strong> <span>{{ _('Request More Info') }}</span></li>
{% endif %}
</ul>
</div>
{% endif %}
Expand Down
38 changes: 25 additions & 13 deletions mkt/reviewers/templates/reviewers/themes/themes.html
@@ -1,6 +1,11 @@
{% from 'includes/forms.html' import required %}

{% for theme, form in theme_formsets %}
{% if rereview %}
{% set header_url = theme.header_url %}
{% set footer_url = theme.footer_url %}
{% set theme = theme.theme %}
{% endif %}
<div class="theme" data-id="{{ loop.index0 + (initial_count or 0) }}">
{{ form }}
<h2><a href="{{ url('reviewers.themes.single', theme.addon.slug) }}">{{ theme.addon.name }}</a></h2>
Expand Down Expand Up @@ -33,13 +38,13 @@ <h2><a href="{{ url('reviewers.themes.single', theme.addon.slug) }}">{{ theme.ad
</dl>

<div class="preview">
<img src="{{ theme.header_url }}" width="1250" height="100">
<img src="{{ header_url or theme.header_url }}" width="1250" height="100">
</div>
<div class="header zoombox">
<img src="{{ theme.header_url }}" width="2500" height="200">
<img src="{{ header_url or theme.header_url }}" width="2500" height="200">
</div>
<div class="footer zoombox">
<img src="{{ theme.footer_url }}" width="2500" height="100">
<img src="{{ footer_url or theme.footer_url }}" width="2500" height="100">
</div>

{% if theme.addon.description %}
Expand All @@ -49,17 +54,22 @@ <h2><a href="{{ url('reviewers.themes.single', theme.addon.slug) }}">{{ theme.ad
{% endif %}
{% if flagged %}
<div class="desc"><strong>{{ _('Reason for Flagging') }}: </strong>
{{ theme.addon.addonlog_set.all()[0].activity_log.details.comment }}
{% set logs = theme.addon.addonlog_set.all() %}
{% if logs.exists() %}
{{ logs[0].activity_log.details.comment }}
{% endif %}
</div>
{% endif %}

{% if reviewable %}
<div class="choices">
<div class="group">
<button class="moreinfo">{{ _('Request More Info') }} &#9662;</button>
{% if not rereview %}
<button class="moreinfo">{{ _('Request More Info') }} &#9662;</button>
{% endif %}
</div>
<div class="group">
{% if not flagged %}
{% if not flagged and not rereview %}
<button class="flag">{{ _('Flag') }} &#9662;</button>
{% endif %}
<button class="duplicate">{{ _('Duplicate') }} &#9662;</button>
Expand Down Expand Up @@ -99,13 +109,15 @@ <h2><a href="{{ url('reviewers.themes.single', theme.addon.slug) }}">{{ theme.ad
{{ required_styled() }}
<button>{{ _('Continue') }}</button>
</div>
<div class="moreinfo-dropdown rq-dropdown">
<label>{{ _('Ask a question to the artist') }}:</label>
<textarea></textarea>
{{ required_styled() }}
<button>{{ _('Continue') }}</button>
</div>
{% if not flagged %}
{% if not rereview %}
<div class="moreinfo-dropdown rq-dropdown">
<label>{{ _('Ask a question to the artist') }}:</label>
<textarea></textarea>
{{ required_styled() }}
<button>{{ _('Continue') }}</button>
</div>
{% endif %}
{% if not flagged and not rereview %}
<div class="flag-dropdown rq-dropdown">
<label>{{ _('Describe your reason for flagging') }}:</label>
<textarea></textarea>
Expand Down

0 comments on commit bec27ef

Please sign in to comment.