filter answers by complete sets
authorJan Szejko <janek37@gmail.com>
Tue, 31 Jan 2017 15:03:40 +0000 (16:03 +0100)
committerJan Szejko <janek37@gmail.com>
Tue, 31 Jan 2017 15:03:40 +0000 (16:03 +0100)
stage2/management/commands/stage2_mark_complete.py [new file with mode: 0644]
stage2/migrations/0009_auto__add_field_participant_complete_set.py [new file with mode: 0644]
stage2/models.py

diff --git a/stage2/management/commands/stage2_mark_complete.py b/stage2/management/commands/stage2_mark_complete.py
new file mode 100644 (file)
index 0000000..0f239b7
--- /dev/null
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+from django.core.management.base import BaseCommand
+
+from stage2.models import Participant, Assignment
+
+
+class Command(BaseCommand):
+
+    def handle(self, **options):
+        assignment_count = Assignment.objects.count()
+        for participant in Participant.objects.all():
+            if participant.answer_set.count() == assignment_count:
+                participant.complete_set = True
+                participant.save()
diff --git a/stage2/migrations/0009_auto__add_field_participant_complete_set.py b/stage2/migrations/0009_auto__add_field_participant_complete_set.py
new file mode 100644 (file)
index 0000000..1875cf6
--- /dev/null
@@ -0,0 +1,115 @@
+# -*- coding: utf-8 -*-
+from south.utils import datetime_utils as datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'Participant.complete_set'
+        db.add_column(u'stage2_participant', 'complete_set',
+                      self.gf('django.db.models.fields.BooleanField')(default=False),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'Participant.complete_set'
+        db.delete_column(u'stage2_participant', 'complete_set')
+
+
+    models = {
+        u'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            u'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': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        u'auth.permission': {
+            'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        u'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', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
+            u'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', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        u'contact.contact': {
+            'Meta': {'ordering': "('-created_at',)", 'object_name': 'Contact'},
+            'body': ('jsonfield.fields.JSONField', [], {}),
+            'contact': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'form_tag': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_index': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'})
+        },
+        u'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'}),
+            u'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'})
+        },
+        u'stage2.answer': {
+            'Meta': {'unique_together': "(['participant', 'assignment'],)", 'object_name': 'Answer'},
+            'assignment': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stage2.Assignment']"}),
+            'complete': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'need_arbiter': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'participant': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stage2.Participant']"})
+        },
+        u'stage2.assignment': {
+            'Meta': {'ordering': "['deadline', 'title']", 'object_name': 'Assignment'},
+            'arbiters': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'stage2_arbitrated'", 'blank': 'True', 'to': u"orm['auth.User']"}),
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'content_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'deadline': ('django.db.models.fields.DateTimeField', [], {}),
+            'experts': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'stage2_assignments'", 'symmetrical': 'False', 'to': u"orm['auth.User']"}),
+            'file_descriptions': ('jsonfield.fields.JSONField', [], {}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'max_points': ('django.db.models.fields.IntegerField', [], {}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '128'})
+        },
+        u'stage2.attachment': {
+            'Meta': {'ordering': "['file_no']", 'object_name': 'Attachment'},
+            'answer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stage2.Answer']"}),
+            'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+            'file_no': ('django.db.models.fields.IntegerField', [], {}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+        },
+        u'stage2.mark': {
+            'Meta': {'unique_together': "(['expert', 'answer'],)", 'object_name': 'Mark'},
+            'answer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stage2.Answer']"}),
+            'expert': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'points': ('django.db.models.fields.DecimalField', [], {'max_digits': '3', 'decimal_places': '1'})
+        },
+        u'stage2.participant': {
+            'Meta': {'object_name': 'Participant'},
+            'complete_set': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contact.Contact']", 'null': 'True'}),
+            'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '100'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
+            'key_sent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        }
+    }
+
+    complete_apps = ['stage2']
\ No newline at end of file
index dc7ac63..18f5ce9 100644 (file)
@@ -22,6 +22,7 @@ class Participant(models.Model):
     last_name = models.CharField(_('last_name'), max_length=100)
     email = models.EmailField(_('email'), max_length=100, unique=True)
     key_sent = models.BooleanField(_('key sent'), default=False)
+    complete_set = models.BooleanField(default=False)
 
     class Meta:
         verbose_name = _('participant')
@@ -76,7 +77,8 @@ class Assignment(models.Model):
         return self.title
 
     def available_answers(self, expert):
-        answers = self.answer_set.exclude(mark__expert=expert).exclude(complete=True)
+        answers = self.answer_set.exclude(mark__expert=expert).exclude(complete=True)\
+            .filter(participant__complete_set=True)
         if expert in self.arbiters.all():
             answers = answers.filter(need_arbiter=True)
         return answers