From 2dd334817a42f694a3f9b596a84095baba8e84bf Mon Sep 17 00:00:00 2001 From: melwil Date: Wed, 22 Jan 2014 21:25:31 +0100 Subject: [PATCH 1/2] Fixes #662. --- ...field_attendanceevent_unattend_deadline.py | 152 ++++++++++++++++++ apps/events/models.py | 1 + apps/events/views.py | 9 +- templates/events/details.html | 6 +- 4 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 apps/events/migrations/0003_auto__add_field_attendanceevent_unattend_deadline.py diff --git a/apps/events/migrations/0003_auto__add_field_attendanceevent_unattend_deadline.py b/apps/events/migrations/0003_auto__add_field_attendanceevent_unattend_deadline.py new file mode 100644 index 000000000..cea80a1cf --- /dev/null +++ b/apps/events/migrations/0003_auto__add_field_attendanceevent_unattend_deadline.py @@ -0,0 +1,152 @@ +# -*- coding: 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 field 'AttendanceEvent.unattend_deadline' + db.add_column(u'events_attendanceevent', 'unattend_deadline', + self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime(2014, 1, 22, 0, 0)), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'AttendanceEvent.unattend_deadline' + db.delete_column(u'events_attendanceevent', 'unattend_deadline') + + + 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'authentication.onlineuser': { + 'Meta': {'ordering': "['first_name', 'last_name']", 'object_name': 'OnlineUser'}, + 'address': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}), + 'allergies': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'compiled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'field_of_study': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'gender': ('django.db.models.fields.CharField', [], {'default': "'male'", 'max_length': '10'}), + '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'}), + 'infomail': ('django.db.models.fields.BooleanField', [], {'default': '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'}), + 'mark_rules': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'nickname': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}), + 'ntnu_username': ('django.db.models.fields.CharField', [], {'max_length': '10', 'unique': 'True', 'null': 'True', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'phone_number': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}), + 'rfid': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}), + 'started_date': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2014, 1, 22, 0, 0)'}), + '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'}), + 'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'zip_code': ('django.db.models.fields.CharField', [], {'max_length': '4', 'null': 'True', 'blank': 'True'}) + }, + u'companyprofile.company': { + 'Meta': {'object_name': 'Company'}, + 'email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('filebrowser.fields.FileBrowseField', [], {'max_length': '200'}), + 'long_description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'phone_number': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}), + 'short_description': ('django.db.models.fields.TextField', [], {'max_length': '200'}), + 'site': ('django.db.models.fields.URLField', [], {'max_length': '200'}) + }, + 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'events.attendanceevent': { + 'Meta': {'object_name': 'AttendanceEvent'}, + 'event': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'attendance_event'", 'unique': 'True', 'primary_key': 'True', 'to': u"orm['events.Event']"}), + 'max_capacity': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'registration_end': ('django.db.models.fields.DateTimeField', [], {}), + 'registration_start': ('django.db.models.fields.DateTimeField', [], {}), + 'rule_bundles': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['events.RuleBundle']", 'null': 'True', 'blank': 'True'}), + 'unattend_deadline': ('django.db.models.fields.DateTimeField', [], {}), + 'waitlist': ('django.db.models.fields.BooleanField', [], {'default': 'False'}) + }, + u'events.attendee': { + 'Meta': {'ordering': "['timestamp']", 'unique_together': "(('event', 'user'),)", 'object_name': 'Attendee'}, + 'attended': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'event': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'attendees'", 'to': u"orm['events.AttendanceEvent']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['authentication.OnlineUser']"}) + }, + u'events.companyevent': { + 'Meta': {'object_name': 'CompanyEvent'}, + 'company': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['companyprofile.Company']"}), + 'event': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'companies'", 'to': u"orm['events.Event']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) + }, + u'events.event': { + 'Meta': {'object_name': 'Event'}, + 'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'oppretter'", 'to': u"orm['authentication.OnlineUser']"}), + 'description': ('django.db.models.fields.TextField', [], {}), + 'event_end': ('django.db.models.fields.DateTimeField', [], {}), + 'event_start': ('django.db.models.fields.DateTimeField', [], {}), + 'event_type': ('django.db.models.fields.SmallIntegerField', [], {}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('filebrowser.fields.FileBrowseField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'ingress': ('django.db.models.fields.TextField', [], {}), + 'ingress_short': ('django.db.models.fields.CharField', [], {'max_length': '150'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '45'}) + }, + u'events.fieldofstudyrule': { + 'Meta': {'object_name': 'FieldOfStudyRule', '_ormbases': [u'events.Rule']}, + 'field_of_study': ('django.db.models.fields.SmallIntegerField', [], {}), + u'rule_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['events.Rule']", 'unique': 'True', 'primary_key': 'True'}) + }, + u'events.graderule': { + 'Meta': {'object_name': 'GradeRule', '_ormbases': [u'events.Rule']}, + 'grade': ('django.db.models.fields.SmallIntegerField', [], {}), + u'rule_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['events.Rule']", 'unique': 'True', 'primary_key': 'True'}) + }, + u'events.rule': { + 'Meta': {'object_name': 'Rule'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'offset': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}) + }, + u'events.rulebundle': { + 'Meta': {'object_name': 'RuleBundle'}, + 'description': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'field_of_study_rules': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['events.FieldOfStudyRule']", 'null': 'True', 'blank': 'True'}), + 'grade_rules': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['events.GradeRule']", 'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'user_group_rules': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['events.UserGroupRule']", 'null': 'True', 'blank': 'True'}) + }, + u'events.usergrouprule': { + 'Meta': {'object_name': 'UserGroupRule', '_ormbases': [u'events.Rule']}, + 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.Group']"}), + u'rule_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['events.Rule']", 'unique': 'True', 'primary_key': 'True'}) + } + } + + complete_apps = ['events'] \ No newline at end of file diff --git a/apps/events/models.py b/apps/events/models.py index 390937b50..780cf77ba 100644 --- a/apps/events/models.py +++ b/apps/events/models.py @@ -394,6 +394,7 @@ class AttendanceEvent(models.Model): max_capacity = models.PositiveIntegerField(_(u'maks-kapasitet'), null=False, blank=False) waitlist = models.BooleanField(_(u'venteliste'), default=False) registration_start = models.DateTimeField(_(u'registrerings-start'), null=False, blank=False) + unattend_deadline = models.DateTimeField(_(u'avmeldings-frist'), null=False, blank=False) registration_end = models.DateTimeField(_(u'registrerings-slutt'), null=False, blank=False) #Access rules diff --git a/apps/events/views.py b/apps/events/views.py index ad1f59ee9..96cc57571 100644 --- a/apps/events/views.py +++ b/apps/events/views.py @@ -60,6 +60,7 @@ def details(request, event_id, event_slug): if is_attendance_event: context = { + 'now': timezone.now(), 'event': event, 'attendance_event': attendance_event, 'user_anonymous': user_anonymous, @@ -121,6 +122,12 @@ def unattendEvent(request, event_id): event = get_object_or_404(Event, pk=event_id) attendance_event = event.attendance_event + + # Check if the deadline for unattending has passed + if attendance_event.unattend_deadline < timezone.now(): + messages.error(request, _(u"Avmeldingsfristen for dette arrangementet har utløpt.")) + return redirect(event) + Attendee.objects.get(event=attendance_event, user=request.user).delete() messages.success(request, _(u"Du ble meldt av arrangementet.")) @@ -162,4 +169,4 @@ def _search_indexed(request, query, filters): @user_passes_test(lambda u: u.groups.filter(name='Komiteer').count() == 1) def generate_pdf(request, event_id): event = get_object_or_404(Event, pk=event_id) - return EventPDF(event).render_pdf() \ No newline at end of file + return EventPDF(event).render_pdf() diff --git a/templates/events/details.html b/templates/events/details.html index 2afe8913f..aa210a734 100644 --- a/templates/events/details.html +++ b/templates/events/details.html @@ -111,7 +111,9 @@

{% else %}

Du er meldt på dette arrangementet.

{% endif %} - + {% if attendance_event.unattend_deadline > now %} + + {% endif %} {% else %} {% if user_status.status %} {% if will_be_on_wait_list %} @@ -140,7 +142,7 @@

{% if attendance_event %} {% if user_attending %} -

Avmeldingsfristen er {{ attendance_event.registration_end|date:"H.i d. M Y" }}

+

Avmeldingsfristen er {{ attendance_event.unattend_deadline|date:"H.i d. M Y" }}

{% endif %} {% endif %} From 70b783acc06a7b63d22d96b143ae95423a1bd22b Mon Sep 17 00:00:00 2001 From: melwil Date: Wed, 22 Jan 2014 22:11:03 +0100 Subject: [PATCH 2/2] Fixed a broken test. --- apps/feedback/tests.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/feedback/tests.py b/apps/feedback/tests.py index 66af26192..fec5807d8 100644 --- a/apps/feedback/tests.py +++ b/apps/feedback/tests.py @@ -32,7 +32,13 @@ def setUp(self): user2 = User.objects.create(username="user2") Email.objects.create(user = user2, email="user2@gmail.com", primary=True) event = Event.objects.create(title="Bedpress", event_start = timezone.now(), event_end = timezone.now(), event_type = 2, author = user1) - attendance_event = AttendanceEvent.objects.create(registration_start = timezone.now(), registration_end = timezone.now(), event = event, max_capacity=30) + attendance_event = AttendanceEvent.objects.create( + registration_start = timezone.now(), + unattend_deadline = timezone.now(), + registration_end = timezone.now(), + event = event, + max_capacity=30 + ) feedback = Feedback.objects.create(author = user1) TextQuestion.objects.create(feedback = feedback) RatingQuestion.objects.create(feedback = feedback)