From f689c911be1ba63d0f404ddaed570df3c3ffbee9 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Thu, 29 Dec 2016 15:21:47 +0100 Subject: [PATCH] add stage2 app (with participant view mostly ready) --- edumed/settings/apps.py | 1 + edumed/templates/base.html | 2 +- edumed/templates/base_super.html | 4 +- edumed/urls.py | 7 +- stage2/__init__.py | 0 stage2/admin.py | 7 + stage2/forms.py | 15 ++ stage2/migrations/0001_initial.py | 160 ++++++++++++++++++ .../migrations/0002_auto__add_attachment.py | 114 +++++++++++++ ...3_auto__del_field_answer_uploaded_files.py | 109 ++++++++++++ stage2/migrations/__init__.py | 0 stage2/models.py | 96 +++++++++++ stage2/templates/stage2/participant.html | 30 ++++ stage2/urls.py | 12 ++ stage2/views.py | 64 +++++++ 15 files changed, 615 insertions(+), 6 deletions(-) create mode 100644 stage2/__init__.py create mode 100644 stage2/admin.py create mode 100644 stage2/forms.py create mode 100644 stage2/migrations/0001_initial.py create mode 100644 stage2/migrations/0002_auto__add_attachment.py create mode 100644 stage2/migrations/0003_auto__del_field_answer_uploaded_files.py create mode 100644 stage2/migrations/__init__.py create mode 100644 stage2/models.py create mode 100644 stage2/templates/stage2/participant.html create mode 100644 stage2/urls.py create mode 100644 stage2/views.py diff --git a/edumed/settings/apps.py b/edumed/settings/apps.py index ec2bb64..9e4d35c 100644 --- a/edumed/settings/apps.py +++ b/edumed/settings/apps.py @@ -6,6 +6,7 @@ INSTALLED_APPS = ( 'catalogue', 'comment', 'wtem', + 'stage2', 'publishers', 'api', diff --git a/edumed/templates/base.html b/edumed/templates/base.html index dd798dd..eb941a6 100644 --- a/edumed/templates/base.html +++ b/edumed/templates/base.html @@ -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 %}Olimpiada cyfrowa{% endblock %} diff --git a/edumed/templates/base_super.html b/edumed/templates/base_super.html index 1c87212..8dbce4a 100644 --- a/edumed/templates/base_super.html +++ b/edumed/templates/base_super.html @@ -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 %} @@ -44,7 +44,7 @@ Wyloguj {% endif %}
- +
{% block organizer %} Projekt prowadzi:
diff --git a/edumed/urls.py b/edumed/urls.py index 26646bb..8b24a1c 100644 --- a/edumed/urls.py +++ b/edumed/urls.py @@ -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.*)$', 'django.views.static.serve', { - 'document_root': settings.MEDIA_ROOT, - }), + # url(r'^media/(?P.*)$', 'django.views.static.serve', { + # 'document_root': settings.MEDIA_ROOT, + # }), ) diff --git a/stage2/__init__.py b/stage2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/stage2/admin.py b/stage2/admin.py new file mode 100644 index 0000000..66fb2f9 --- /dev/null +++ b/stage2/admin.py @@ -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 index 0000000..9ff44f7 --- /dev/null +++ b/stage2/forms.py @@ -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 index 0000000..05fa181 --- /dev/null +++ b/stage2/migrations/0001_initial.py @@ -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 index 0000000..0e4faac --- /dev/null +++ b/stage2/migrations/0002_auto__add_attachment.py @@ -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 index 0000000..79c9dd9 --- /dev/null +++ b/stage2/migrations/0003_auto__del_field_answer_uploaded_files.py @@ -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 index 0000000..e69de29 diff --git a/stage2/models.py b/stage2/models.py new file mode 100644 index 0000000..8ffa255 --- /dev/null +++ b/stage2/models.py @@ -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 index 0000000..f8ca87d --- /dev/null +++ b/stage2/templates/stage2/participant.html @@ -0,0 +1,30 @@ +{% extends 'base_super.html' %} + +{% block title %}Drugi etap{% endblock %} + +{% block body %} +

Drugi etap Olimpiady Cyfrowej

+ + {% for assignment in assignments %} +

{{ assignment.title }} (do {{ assignment.deadline }})

+

{{ assignment.content }}

+
+ {% csrf_token %} + {% for form, attachment in assignment.forms %} +

{{ form.file.label }}:

+

+ {% if assignment.active %}{{ form.file }}{% endif %} + {% if attachment.file %} + {{ attachment.filename }} + {% else %} + (nie wysłano pliku) + {% endif %} +

+ {% endfor %} + +
+ {% endfor %} + + +{% endblock %} \ No newline at end of file diff --git a/stage2/urls.py b/stage2/urls.py new file mode 100644 index 0000000..5587fca --- /dev/null +++ b/stage2/urls.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +from django.conf.urls import patterns, url + +from stage2 import views + +urlpatterns = ( + url(r'^uczestnik/(?P[0-9]*)/(?P.*)/$', views.participant_view, name='stage2_participant'), + url(r'^upload/(?P[0-9]*)/(?P[0-9]*)/(?P.*)/$', views.upload, + name='stage2_upload'), + url(r'^plik/(?P[0-9]*)/(?P[0-9]*)/(?P[0-9]*)/(?P.*)/$', + views.get_file, name='stage2_participant_file') +) diff --git a/stage2/views.py b/stage2/views.py new file mode 100644 index 0000000..2b2e875 --- /dev/null +++ b/stage2/views.py @@ -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 -- 2.20.1