add stage2 app (with participant view mostly ready)
authorJan Szejko <janek37@gmail.com>
Thu, 29 Dec 2016 14:21:47 +0000 (15:21 +0100)
committerJan Szejko <janek37@gmail.com>
Thu, 29 Dec 2016 14:21:47 +0000 (15:21 +0100)
15 files changed:
edumed/settings/apps.py
edumed/templates/base.html
edumed/templates/base_super.html
edumed/urls.py
stage2/__init__.py [new file with mode: 0644]
stage2/admin.py [new file with mode: 0644]
stage2/forms.py [new file with mode: 0644]
stage2/migrations/0001_initial.py [new file with mode: 0644]
stage2/migrations/0002_auto__add_attachment.py [new file with mode: 0644]
stage2/migrations/0003_auto__del_field_answer_uploaded_files.py [new file with mode: 0644]
stage2/migrations/__init__.py [new file with mode: 0644]
stage2/models.py [new file with mode: 0644]
stage2/templates/stage2/participant.html [new file with mode: 0644]
stage2/urls.py [new file with mode: 0644]
stage2/views.py [new file with mode: 0644]

index ec2bb64..9e4d35c 100644 (file)
@@ -6,6 +6,7 @@ INSTALLED_APPS = (
     'catalogue',
     'comment',
     'wtem',
+    'stage2',
     'publishers',
     'api',
 
index dd798dd..eb941a6 100644 (file)
@@ -10,7 +10,7 @@
 
 {% block ogurl %}https://olimpiadacyfrowa.pl{% endblock %}
 
-{% block og_image %}http://olimpiadacyfrowa.pl/media/chunks/attachment/olimpiada_cyfrowa_logo.png{% endblock %}
+{% block og_image %}{% static "img/logo-oc.png" %}{% endblock %}
 
 {% block logo %}<img src="{% static "img/logo-oc.png" %}" height="73" alt="Olimpiada cyfrowa"/>{% endblock %}
 
index 1c87212..8dbce4a 100644 (file)
@@ -6,7 +6,7 @@
 {% load piwik_tags %}
 
 {% macro title %}{% block title %}{% endblock %}{% endmacro %}
-{% macro site_name %}Edukacja medialna{% endmacro %}
+{% macro site_name %}Olimpiada Cyfrowa{% endmacro %}
 
 <html prefix="og: http://ogp.me/ns#">
     <head>
@@ -44,7 +44,7 @@
                 <a href="{% url 'logout' subdomain=None %}" style="position: absolute; top:5px; right: 10px; font-size: 12px;">Wyloguj</a>
             {% endif %}
             <div id="header-top">
-            <a id="logo" href="/">{% block logo %}<img src="{% static "img/logo-oc.png" %}" alt="Edukacja medialna" height="73"/>{% endblock %}</a>
+            <a id="logo" href="/">{% block logo %}<img src="{% static "img/logo-oc.png" %}" alt="Olimpiada Cyfrowa" height="73"/>{% endblock %}</a>
             <div id="organizer">
                 {% block organizer %}
                 Projekt prowadzi:<br/>
index 26646bb..8b24a1c 100644 (file)
@@ -26,6 +26,7 @@ urlpatterns = patterns(
     # url(r'^forum/', include('pybb.urls', namespace='pybb')),
     # url(r'^kompetencje/', include('curriculum.urls')),
     url(r'^zadania/', include('wtem.urls')),
+    url(r'^2etap/', include('stage2.urls')),
 )
 
 
@@ -61,7 +62,7 @@ urlpatterns += (
 if settings.DEBUG:
     urlpatterns += patterns(
         '',
-        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
-            'document_root': settings.MEDIA_ROOT,
-        }),
+        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
+            'document_root': settings.MEDIA_ROOT,
+        }),
     )
diff --git a/stage2/__init__.py b/stage2/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/stage2/admin.py b/stage2/admin.py
new file mode 100644 (file)
index 0000000..66fb2f9
--- /dev/null
@@ -0,0 +1,7 @@
+# -*- coding: utf-8 -*-
+from django.contrib import admin
+from .models import Participant, Assignment
+
+
+admin.site.register(Assignment)
+admin.site.register(Participant)
diff --git a/stage2/forms.py b/stage2/forms.py
new file mode 100644 (file)
index 0000000..9ff44f7
--- /dev/null
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+from django import forms
+
+from stage2.models import Attachment
+
+
+class AttachmentForm(forms.ModelForm):
+    class Meta:
+        model = Attachment
+        fields = ['file']
+
+    def __init__(self, assignment, file_no, label, *args, **kwargs):
+        prefix = 'att%s-%s' % (assignment.id, file_no)
+        super(AttachmentForm, self).__init__(*args, prefix=prefix, **kwargs)
+        self.fields['file'].label = label
diff --git a/stage2/migrations/0001_initial.py b/stage2/migrations/0001_initial.py
new file mode 100644 (file)
index 0000000..05fa181
--- /dev/null
@@ -0,0 +1,160 @@
+# -*- 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 model 'Participant'
+        db.create_table(u'stage2_participant', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('contact', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contact.Contact'], null=True)),
+            ('key', self.gf('django.db.models.fields.CharField')(unique=True, max_length=30)),
+            ('first_name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('last_name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('email', self.gf('django.db.models.fields.EmailField')(unique=True, max_length=100)),
+            ('key_sent', self.gf('django.db.models.fields.BooleanField')(default=False)),
+        ))
+        db.send_create_signal(u'stage2', ['Participant'])
+
+        # Adding model 'Assignment'
+        db.create_table(u'stage2_assignment', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('title', self.gf('django.db.models.fields.CharField')(max_length=128)),
+            ('content', self.gf('django.db.models.fields.TextField')()),
+            ('deadline', self.gf('django.db.models.fields.DateTimeField')()),
+            ('max_points', self.gf('django.db.models.fields.IntegerField')()),
+            ('file_descriptions', self.gf('jsonfield.fields.JSONField')()),
+        ))
+        db.send_create_signal(u'stage2', ['Assignment'])
+
+        # Adding model 'Answer'
+        db.create_table(u'stage2_answer', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('participant', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['stage2.Participant'])),
+            ('assignment', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['stage2.Assignment'])),
+            ('uploaded_files', self.gf('jsonfield.fields.JSONField')()),
+        ))
+        db.send_create_signal(u'stage2', ['Answer'])
+
+        # Adding unique constraint on 'Answer', fields ['participant', 'assignment']
+        db.create_unique(u'stage2_answer', ['participant_id', 'assignment_id'])
+
+        # Adding model 'Mark'
+        db.create_table(u'stage2_mark', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('expert', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
+            ('answer', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['stage2.Answer'])),
+            ('points', self.gf('django.db.models.fields.DecimalField')(max_digits=3, decimal_places=1)),
+        ))
+        db.send_create_signal(u'stage2', ['Mark'])
+
+        # Adding unique constraint on 'Mark', fields ['expert', 'answer']
+        db.create_unique(u'stage2_mark', ['expert_id', 'answer_id'])
+
+
+    def backwards(self, orm):
+        # Removing unique constraint on 'Mark', fields ['expert', 'answer']
+        db.delete_unique(u'stage2_mark', ['expert_id', 'answer_id'])
+
+        # Removing unique constraint on 'Answer', fields ['participant', 'assignment']
+        db.delete_unique(u'stage2_answer', ['participant_id', 'assignment_id'])
+
+        # Deleting model 'Participant'
+        db.delete_table(u'stage2_participant')
+
+        # Deleting model 'Assignment'
+        db.delete_table(u'stage2_assignment')
+
+        # Deleting model 'Answer'
+        db.delete_table(u'stage2_answer')
+
+        # Deleting model 'Mark'
+        db.delete_table(u'stage2_mark')
+
+
+    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']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'participant': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stage2.Participant']"}),
+            'uploaded_files': ('jsonfield.fields.JSONField', [], {})
+        },
+        u'stage2.assignment': {
+            'Meta': {'ordering': "['deadline']", 'object_name': 'Assignment'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'deadline': ('django.db.models.fields.DateTimeField', [], {}),
+            '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.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'},
+            '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
diff --git a/stage2/migrations/0002_auto__add_attachment.py b/stage2/migrations/0002_auto__add_attachment.py
new file mode 100644 (file)
index 0000000..0e4faac
--- /dev/null
@@ -0,0 +1,114 @@
+# -*- 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 model 'Attachment'
+        db.create_table(u'stage2_attachment', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('answer', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['stage2.Answer'])),
+            ('file_no', self.gf('django.db.models.fields.IntegerField')()),
+            ('file', self.gf('django.db.models.fields.files.FileField')(max_length=100)),
+        ))
+        db.send_create_signal(u'stage2', ['Attachment'])
+
+
+    def backwards(self, orm):
+        # Deleting model 'Attachment'
+        db.delete_table(u'stage2_attachment')
+
+
+    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']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'participant': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stage2.Participant']"}),
+            'uploaded_files': ('jsonfield.fields.JSONField', [], {})
+        },
+        u'stage2.assignment': {
+            'Meta': {'ordering': "['deadline']", 'object_name': 'Assignment'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'deadline': ('django.db.models.fields.DateTimeField', [], {}),
+            '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': {'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'},
+            '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
diff --git a/stage2/migrations/0003_auto__del_field_answer_uploaded_files.py b/stage2/migrations/0003_auto__del_field_answer_uploaded_files.py
new file mode 100644 (file)
index 0000000..79c9dd9
--- /dev/null
@@ -0,0 +1,109 @@
+# -*- 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):
+        # Deleting field 'Answer.uploaded_files'
+        db.delete_column(u'stage2_answer', 'uploaded_files')
+
+
+    def backwards(self, orm):
+        # Adding field 'Answer.uploaded_files'
+        db.add_column(u'stage2_answer', 'uploaded_files',
+                      self.gf('jsonfield.fields.JSONField')(default=[]),
+                      keep_default=False)
+
+
+    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']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'participant': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stage2.Participant']"})
+        },
+        u'stage2.assignment': {
+            'Meta': {'ordering': "['deadline']", 'object_name': 'Assignment'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'deadline': ('django.db.models.fields.DateTimeField', [], {}),
+            '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': {'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'},
+            '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
diff --git a/stage2/migrations/__init__.py b/stage2/migrations/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/stage2/models.py b/stage2/models.py
new file mode 100644 (file)
index 0000000..8ffa255
--- /dev/null
@@ -0,0 +1,96 @@
+# -*- coding: utf-8 -*-
+import os
+import random
+import string
+
+from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
+from django.db import models
+from jsonfield import JSONField
+
+from contact.models import Contact
+
+
+class Participant(models.Model):
+    contact = models.ForeignKey(Contact, null=True)
+    key = models.CharField(max_length=30, unique=True)
+    first_name = models.CharField(max_length=100)
+    last_name = models.CharField(max_length=100)
+    email = models.EmailField(max_length=100, unique=True)
+    key_sent = models.BooleanField(default=False)
+
+    def __unicode__(self):
+        return ', '.join((self.last_name, self.first_name, self.email))
+
+    # copy-paste from wtem
+    @classmethod
+    def generate_key(cls):
+        key = ''
+        while not key or key in [record['key'] for record in cls.objects.values('key')]:
+            key = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits)
+                          for i in range(30))
+        return key
+
+    # copy-paste from wtem
+    @classmethod
+    def create(cls, first_name, last_name, email, key=None, contact=None):
+        return cls.objects.create(
+            contact=contact,
+            key=key if key else cls.generate_key(),
+            first_name=first_name,
+            last_name=last_name,
+            email=email)
+
+    def check(self, key):
+        return key == self.key
+
+
+class Assignment(models.Model):
+    title = models.CharField(max_length=128)
+    content = models.TextField()
+    deadline = models.DateTimeField()
+    max_points = models.IntegerField()
+    file_descriptions = JSONField()
+
+    class Meta:
+        ordering = ['deadline']
+
+    def __unicode__(self):
+        return self.title
+
+
+class Answer(models.Model):
+    participant = models.ForeignKey(Participant)
+    assignment = models.ForeignKey(Assignment)
+
+    class Meta:
+        unique_together = ['participant', 'assignment']
+
+
+def attachment_path(instance, filename):
+    answer = instance.answer
+    return 'stage2/attachment/%s/%s/%s' % (answer.participant_id, answer.assignment_id, filename)
+
+
+class Attachment(models.Model):
+    answer = models.ForeignKey(Answer)
+    file_no = models.IntegerField()
+    file = models.FileField(upload_to=attachment_path)
+
+    def filename(self):
+        return os.path.basename(self.file.name)
+
+    def download_url(self):
+        return reverse(
+            'stage2_participant_file',
+            args=(self.answer.assignment_id, self.file_no,
+                  self.answer.participant_id, self.answer.participant.key))
+
+
+class Mark(models.Model):
+    expert = models.ForeignKey(User)
+    answer = models.ForeignKey(Answer)
+    points = models.DecimalField(max_digits=3, decimal_places=1)
+
+    class Meta:
+        unique_together = ['expert', 'answer']
diff --git a/stage2/templates/stage2/participant.html b/stage2/templates/stage2/participant.html
new file mode 100644 (file)
index 0000000..f8ca87d
--- /dev/null
@@ -0,0 +1,30 @@
+{% extends 'base_super.html' %}
+
+{% block title %}Drugi etap{% endblock %}
+
+{% block body %}
+  <h1>Drugi etap Olimpiady Cyfrowej</h1>
+
+  {% for assignment in assignments %}
+    <h2>{{ assignment.title }} (do {{ assignment.deadline }})</h2>
+    <p>{{ assignment.content }}</p>
+    <form method="POST" action="{% url 'stage2_upload' assignment.id participant.id participant.key %}"
+          enctype="multipart/form-data">
+      {% csrf_token %}
+      {% for form, attachment in assignment.forms %}
+        <p><strong>{{ form.file.label }}:</strong></p>
+        <p>
+          {% if assignment.active %}{{ form.file }}{% endif %}
+          {% if attachment.file %}
+            <a href="{{ attachment.download_url }}">{{ attachment.filename }}</a>
+          {% else %}
+            (nie wysłano pliku)
+          {% endif %}
+        </p>
+      {% endfor %}
+      <input type="submit" value="Wyślij"/>
+    </form>
+  {% endfor %}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/stage2/urls.py b/stage2/urls.py
new file mode 100644 (file)
index 0000000..5587fca
--- /dev/null
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+from django.conf.urls import patterns, url
+
+from stage2 import views
+
+urlpatterns = (
+    url(r'^uczestnik/(?P<participant_id>[0-9]*)/(?P<key>.*)/$', views.participant_view, name='stage2_participant'),
+    url(r'^upload/(?P<assignment_id>[0-9]*)/(?P<participant_id>[0-9]*)/(?P<key>.*)/$', views.upload,
+        name='stage2_upload'),
+    url(r'^plik/(?P<assignment_id>[0-9]*)/(?P<file_no>[0-9]*)/(?P<participant_id>[0-9]*)/(?P<key>.*)/$',
+        views.get_file, name='stage2_participant_file')
+)
diff --git a/stage2/views.py b/stage2/views.py
new file mode 100644 (file)
index 0000000..2b2e875
--- /dev/null
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+from django.core.urlresolvers import reverse
+from django.http import Http404
+from django.http.response import HttpResponseRedirect, HttpResponse
+from django.shortcuts import get_object_or_404, render
+from django.utils import timezone
+from django.views.decorators.http import require_POST
+
+from stage2.forms import AttachmentForm
+from stage2.models import Participant, Assignment, Answer, Attachment
+
+
+def participant_view(request, participant_id, key):
+    participant = get_object_or_404(Participant, id=participant_id)
+    if not participant.check(key):
+        raise Http404
+    now = timezone.now()
+    assignments = Assignment.objects.all()
+    for assignment in assignments:
+        assignment.active = assignment.deadline >= now
+        assignment.answer = assignment.answer_set.filter(participant=participant).first()
+        assignment.forms = [
+            (AttachmentForm(assignment=assignment, file_no=i, label=label),
+             assignment.answer.attachment_set.filter(file_no=i).first() if assignment.answer else None)
+            for i, label in enumerate(assignment.file_descriptions, 1)]
+    return render(request, 'stage2/participant.html', {
+        'participant': participant,
+        'assignments': assignments})
+
+
+@require_POST
+def upload(request, assignment_id, participant_id, key):
+    participant = get_object_or_404(Participant, id=participant_id)
+    if not participant.check(key):
+        raise Http404
+    assignment = get_object_or_404(Assignment, id=assignment_id)
+    now = timezone.now()
+    if assignment.deadline < now:
+        raise Http404  # TODO za późno
+    for i, label in enumerate(assignment.file_descriptions, 1):
+        answer, created = Answer.objects.get_or_create(participant=participant, assignment=assignment)
+        attachment, created = Attachment.objects.get_or_create(answer=answer, file_no=i)
+        form = AttachmentForm(
+            data=request.POST, files=request.FILES,
+            assignment=assignment, file_no=i, label=label, instance=attachment)
+        if form.is_valid():
+            form.save()
+    return HttpResponseRedirect(reverse('stage2_participant', args=(participant_id, key)))
+
+
+def get_file(request, assignment_id, file_no, participant_id, key):
+    """We want to serve submitted files back to participants, but also validate their keys,
+       so static files are not good"""
+    participant = get_object_or_404(Participant, id=participant_id)
+    if not participant.check(key):
+        raise Http404
+    assignment = get_object_or_404(Assignment, id=assignment_id)
+    answer = get_object_or_404(Answer, participant=participant, assignment=assignment)
+    attachment = get_object_or_404(Attachment, answer=answer, file_no=file_no)
+    response = HttpResponse(content_type='application/force-download')
+    response.write(attachment.file.read())
+    response['Content-Disposition'] = 'attachment; filename="%s"' % attachment.filename()
+    response['Content-Length'] = response.tell()
+    return response