From 371c1d26d79ab25128901477bb24e3e08930bff0 Mon Sep 17 00:00:00 2001 From: Jeff Balogh Date: Mon, 28 Jun 2010 17:52:32 -0700 Subject: [PATCH] enabling ajax review flagging --- apps/amo/fixtures/base/admin.json | 51 +++++++++++++++++++ apps/reviews/forms.py | 15 ++++++ apps/reviews/models.py | 21 ++++++-- apps/reviews/templates/reviews/review.html | 3 +- .../templates/reviews/review_list.html | 16 ++++++ apps/reviews/tests/test_views.py | 50 ++++++++++++++++++ apps/reviews/urls.py | 1 + apps/reviews/views.py | 31 +++++++++-- media/css/nojs.css | 4 ++ media/css/zamboni/zamboni.css | 10 ++-- media/js/zamboni/reviews.js | 37 ++++++++++++++ settings.py | 1 + 12 files changed, 229 insertions(+), 11 deletions(-) create mode 100644 apps/amo/fixtures/base/admin.json create mode 100644 apps/reviews/forms.py create mode 100644 media/js/zamboni/reviews.js diff --git a/apps/amo/fixtures/base/admin.json b/apps/amo/fixtures/base/admin.json new file mode 100644 index 0000000000..1205589c58 --- /dev/null +++ b/apps/amo/fixtures/base/admin.json @@ -0,0 +1,51 @@ +[ + { + "pk": 4043307, + "model": "auth.user", + "fields": { + "username": "jbalogh", + "first_name": "Jeff", + "last_name": "Balogh", + "is_active": 1, + "is_superuser": 1, + "is_staff": 1, + "last_login": "2010-01-13 17:17:23", + "groups": [], + "user_permissions": [], + "password": "sha512$7b5436061f8c0902088c292c057be69fdb17312e2f71607c9c51641f5d876522$08d1d370d89e2ae92755fd03464a7276ca607c431d04a52d659f7a184f3f9918073637d82fc88981c7099c7c46a1137b9fdeb675304eb98801038905a9ee0600", + "email": "jbalogh@mozilla.com", + "date_joined": "2009-02-02 11:50:31" + } + }, + { + "pk": 4043307, + "model": "users.userprofile", + "fields": { + "sandboxshown": 1, + "display_collections_fav": 1, + "display_collections": 1, + "occupation": "", + "confirmationcode": "", + "location": "", + "picture_type": "", + "averagerating": "", + "homepage": "http://jeffbalogh.org", + "email": "jbalogh@mozilla.com", + "notifycompat": 1, + "bio": null, + "firstname": "Jeff", + "deleted": 0, + "lastname": "Balogh", + "emailhidden": 0, + "user": 4043307, + "password": "sha512$7b5436061f8c0902088c292c057be69fdb17312e2f71607c9c51641f5d876522$08d1d370d89e2ae92755fd03464a7276ca607c431d04a52d659f7a184f3f9918073637d82fc88981c7099c7c46a1137b9fdeb675304eb98801038905a9ee0600", + "nickname": "jbalogh", + "resetcode_expires": "2010-01-12 15:28:07", + "resetcode": "", + "created": "2009-02-02 11:50:31", + "notes": "", + "modified": "2010-01-12 17:01:41", + "notifyevents": 1 + } + } +] diff --git a/apps/reviews/forms.py b/apps/reviews/forms.py new file mode 100644 index 0000000000..c2bea9b188 --- /dev/null +++ b/apps/reviews/forms.py @@ -0,0 +1,15 @@ +from django import forms + +from .models import ReviewFlag + + +class ReviewFlagForm(forms.ModelForm): + + class Meta: + model = ReviewFlag + + def clean(self): + data = super(ReviewFlagForm, self).clean() + if 'note' in data and data['note'].strip(): + data['flag'] = 'other' + return data diff --git a/apps/reviews/models.py b/apps/reviews/models.py index 9205c1d0b2..4728739339 100644 --- a/apps/reviews/models.py +++ b/apps/reviews/models.py @@ -3,6 +3,8 @@ import itertools from django.db import models from django.utils import translation +from tower import ugettext_lazy as _ + import amo.models from translations.fields import TranslatedField from translations.models import Translation @@ -123,9 +125,22 @@ models.signals.post_save.connect(Review.post_save, sender=Review) models.signals.post_delete.connect(Review.post_delete, sender=Review) +# TODO: translate old flags. class ReviewFlag(amo.models.ModelBase): + FLAGS = ( + ('spam', _('Spam or otherwise non-review content')), + ('language', _('Inappropriate language/dialog')), + ('bug_support', _('Misplaced bug report or support request')), + ('other', _('Other (please specify)')), + ) + review = models.ForeignKey(Review) user = models.ForeignKey('users.UserProfile') - name = models.CharField(max_length=64, default='review_flag_reason_other', - db_column='flag_name') - notes = models.CharField(max_length=100, db_column='flag_notes') + flag = models.CharField(max_length=64, default='other', + choices=FLAGS, db_column='flag_name') + note = models.CharField(max_length=100, db_column='flag_notes', blank=True, + default='') + + class Meta: + db_table = 'reviews_moderation_flags' + unique_together = (('review', 'user'),) diff --git a/apps/reviews/templates/reviews/review.html b/apps/reviews/templates/reviews/review.html index 1189926b9c..7d651ebcc9 100644 --- a/apps/reviews/templates/reviews/review.html +++ b/apps/reviews/templates/reviews/review.html @@ -37,7 +37,8 @@ {% endif %} {% if request.user.is_authenticated() %}