[extensions-web: 69/75] Add a new mechanism for status changes and keeping track of them.



commit a47cc267982994379fd4bbac6b60a9ee8191bad1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Sep 22 16:41:16 2011 -0400

    Add a new mechanism for status changes and keeping track of them.
    
    If reviews don't manage statuses, we need something else that does.

 sweettooth/extensions/models.py                    |    1 +
 .../migrations/0003_auto__add_changestatuslog.py   |  113 ++++++++++++++++++++
 sweettooth/review/models.py                        |    8 ++-
 sweettooth/review/views.py                         |   29 +++++-
 4 files changed, 149 insertions(+), 2 deletions(-)
---
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index 2164f54..c96ba86 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -248,3 +248,4 @@ class ExtensionVersion(models.Model):
 
 submitted_for_review = Signal(providing_args=["version"])
 reviewed = Signal(providing_args=["version", "review"])
+status_changed = Signal(providing_args=["version", "log"])
diff --git a/sweettooth/review/migrations/0003_auto__add_changestatuslog.py b/sweettooth/review/migrations/0003_auto__add_changestatuslog.py
new file mode 100644
index 0000000..9e70850
--- /dev/null
+++ b/sweettooth/review/migrations/0003_auto__add_changestatuslog.py
@@ -0,0 +1,113 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding model 'ChangeStatusLog'
+        db.create_table('review_changestatuslog', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
+            ('date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
+            ('newstatus', self.gf('django.db.models.fields.PositiveIntegerField')()),
+            ('version', self.gf('django.db.models.fields.related.ForeignKey')(related_name='status_log', to=orm['extensions.ExtensionVersion'])),
+        ))
+        db.send_create_signal('review', ['ChangeStatusLog'])
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'ChangeStatusLog'
+        db.delete_table('review_changestatuslog')
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'extensions.extension': {
+            'Meta': {'object_name': 'Extension'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'icon': ('django.db.models.fields.files.ImageField', [], {'default': "''", 'max_length': '100', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'screenshot': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '100', 'blank': 'True'}),
+            'slug': ('autoslug.fields.AutoSlugField', [], {'unique_with': '()', 'max_length': '50', 'populate_from': 'None', 'db_index': 'True'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'uuid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200', 'db_index': 'True'})
+        },
+        'extensions.extensionversion': {
+            'Meta': {'unique_together': "(('extension', 'version'),)", 'object_name': 'ExtensionVersion'},
+            'extension': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'versions'", 'to': "orm['extensions.Extension']"}),
+            'extra_json_fields': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'shell_versions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['extensions.ShellVersion']", 'symmetrical': 'False'}),
+            'source': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+            'status': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'version': ('django.db.models.fields.IntegerField', [], {'default': '0', 'max_length': '223'})
+        },
+        'extensions.shellversion': {
+            'Meta': {'object_name': 'ShellVersion'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'major': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'minor': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'point': ('django.db.models.fields.IntegerField', [], {})
+        },
+        'review.changestatuslog': {
+            'Meta': {'object_name': 'ChangeStatusLog'},
+            'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'newstatus': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+            'version': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'status_log'", 'to': "orm['extensions.ExtensionVersion']"})
+        },
+        'review.codereview': {
+            'Meta': {'object_name': 'CodeReview'},
+            'comments': ('django.db.models.fields.TextField', [], {}),
+            'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'reviewer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+            'version': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'reviews'", 'to': "orm['extensions.ExtensionVersion']"})
+        }
+    }
+
+    complete_apps = ['review']
diff --git a/sweettooth/review/models.py b/sweettooth/review/models.py
index 37b2aaa..5e89c34 100644
--- a/sweettooth/review/models.py
+++ b/sweettooth/review/models.py
@@ -3,7 +3,7 @@ from django.contrib.auth.models import User, Permission, Group
 from django.db import models
 from django.db.models import Q
 
-from extensions.models import ExtensionVersion
+from extensions.models import ExtensionVersion, STATUSES
 
 def get_all_reviewers():
     perm = Permission.objects.get(codename="can-review-extensions")
@@ -23,3 +23,9 @@ class CodeReview(models.Model):
         permissions = (
             ("can-review-extensions", "Can review extensions"),
         )
+
+class ChangeStatusLog(models.Model):
+    user = models.ForeignKey(User)
+    date = models.DateTimeField(auto_now_add=True)
+    newstatus = models.PositiveIntegerField(choices=STATUSES.items())
+    version = models.ForeignKey(ExtensionVersion, related_name="status_log")
diff --git a/sweettooth/review/views.py b/sweettooth/review/views.py
index 31eddfe..1e51aec 100644
--- a/sweettooth/review/views.py
+++ b/sweettooth/review/views.py
@@ -20,7 +20,7 @@ from django.utils.safestring import mark_safe
 from django.views.generic import View, DetailView, ListView
 from django.views.generic.detail import SingleObjectMixin
 
-from review.models import CodeReview, get_all_reviewers
+from review.models import CodeReview, ChangeStatusLog, get_all_reviewers
 from extensions import models
 
 def can_review_extension(user, extension):
@@ -67,6 +67,33 @@ class AjaxGetFilesView(SingleObjectMixin, View):
         return HttpResponse(mark_safe(json.dumps(files)),
                             content_type="application/json")
 
+class AjaxChangeStatusView(SingleObjectMixin, View):
+    model = models.ExtensionVersion
+
+    def get(self, request, *args, **kwargs):
+        return HttpResponseForbidden()
+
+    def post(self, request, *args, **kwargs):
+        self.object = self.get_object()
+
+        if not can_review_extension(request.user, self.object.extension):
+            return HttpResponseForbidden()
+
+        # Do not let reviewers change the status of their own extension
+        if request.user == self.object.extension:
+            return HttpResponseForbidden()
+
+        newstatus = request.POST.get('newstatus')
+
+        log = ChangeStatusLog(user=request.user,
+                              version=self.object,
+                              newstatus=newstatus)
+        log.save()
+
+        models.status_changed.send(sender=self, version=self.object, log=log)
+
+        self.object.status = newstatus
+
 class SubmitReviewView(SingleObjectMixin, View):
     model = models.ExtensionVersion
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]