From a1c387f5205cd29aadcaf8a9bb5737bac5af8664 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sat, 25 Aug 2018 10:34:23 -0400 Subject: [PATCH] Add event toggles to enable/disable presentations, comments and photos. Fixes #109 --- events/forms.py | 10 +++++-- events/migrations/0044_add_event_settings.py | 28 +++++++++++++++++++ events/models/events.py | 5 ++++ .../get_together/events/show_event.html | 6 ++++ get_together/views/events.py | 8 ++++++ get_together/views/speakers.py | 5 ++++ 6 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 events/migrations/0044_add_event_settings.py diff --git a/events/forms.py b/events/forms.py index 0ce9d33..6697b35 100644 --- a/events/forms.py +++ b/events/forms.py @@ -225,7 +225,7 @@ class TeamEventForm(forms.ModelForm): recurrences = recurrence.forms.RecurrenceField(label="Repeat", required=False) class Meta: model = Event - fields = ['name', 'start_time', 'end_time', 'recurrences', 'summary', 'web_url', 'announce_url', 'tags'] + fields = ['name', 'start_time', 'end_time', 'recurrences', 'summary', 'web_url', 'announce_url', 'enable_comments', 'enable_photos', 'enable_presentations'] widgets = { 'place': Lookup(source=Place), 'start_time': DateTimeWidget, @@ -302,7 +302,13 @@ class NewEventDetailsForm(forms.ModelForm): class Meta: model = Event - fields = ['summary', 'recurrences', 'web_url', 'announce_url'] + fields = ['summary', 'recurrences', 'web_url', 'announce_url', 'enable_comments', 'enable_photos', 'enable_presentations'] + + +class EventSettingsForm(forms.ModelForm): + class Meta: + model = Event + fields = ['enable_comments', 'enable_photos', 'enable_presentations'] class DeleteEventForm(forms.Form): diff --git a/events/migrations/0044_add_event_settings.py b/events/migrations/0044_add_event_settings.py new file mode 100644 index 0000000..3c29931 --- /dev/null +++ b/events/migrations/0044_add_event_settings.py @@ -0,0 +1,28 @@ +# Generated by Django 2.0 on 2018-08-25 14:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0043_remove_premium_restrictions'), + ] + + operations = [ + migrations.AddField( + model_name='event', + name='enable_comments', + field=models.BooleanField(default=True, verbose_name='Comments'), + ), + migrations.AddField( + model_name='event', + name='enable_photos', + field=models.BooleanField(default=True, verbose_name='Photos'), + ), + migrations.AddField( + model_name='event', + name='enable_presentations', + field=models.BooleanField(default=False, verbose_name='Presentations'), + ), + ] diff --git a/events/models/events.py b/events/models/events.py index c37c395..234ffa0 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -93,6 +93,11 @@ class Event(models.Model): sponsors = models.ManyToManyField('Sponsor', related_name='events', blank=True) + enable_comments = models.BooleanField(verbose_name=_('Comments'), default=True) + enable_photos = models.BooleanField(verbose_name=_('Photos'), default=True) + enable_presentations = models.BooleanField(verbose_name=_('Presentations'), default=False) + + @property def is_over(self): return self.end_time <= timezone.now() diff --git a/get_together/templates/get_together/events/show_event.html b/get_together/templates/get_together/events/show_event.html index 7eb3924..616832f 100644 --- a/get_together/templates/get_together/events/show_event.html +++ b/get_together/templates/get_together/events/show_event.html @@ -210,6 +210,7 @@ {% endif %} + {% if event.enable_presentations %}
Presentations:
@@ -224,9 +225,11 @@ {% endif %}
+ {% endif %} + {% if event.enable_comments %}

Comments

@@ -270,6 +273,7 @@
+ {% endif %}
@@ -335,6 +339,7 @@
{% endfor %} + {% if event.enable_photos %}

Photos

@@ -362,6 +367,7 @@
{% endif %}
+ {% endif %} diff --git a/get_together/views/events.py b/get_together/views/events.py index 6999985..c4a56af 100644 --- a/get_together/views/events.py +++ b/get_together/views/events.py @@ -476,6 +476,10 @@ def attended_event(request, event_id): def comment_event(request, event_id): event = Event.objects.get(id=event_id) + if not event.enable_comments: + messages.add_message(request, messages.WARNING, message=_('This event does not allow comments.')) + return redirect(event.get_absolute_url()) + if request.user.is_anonymous: messages.add_message(request, messages.WARNING, message=_("You must be logged in to comment.")) return redirect(event.get_absolute_url()) @@ -526,6 +530,10 @@ def add_event_photo(request, event_id): messages.add_message(request, messages.WARNING, message=_('You can not make changes to this event.')) return redirect(event.get_absolute_url()) + if not event.enable_photos: + messages.add_message(request, messages.WARNING, message=_('This event does not allow uploading photos.')) + return redirect(event.get_absolute_url()) + if request.method == 'GET': form = UploadEventPhotoForm() diff --git a/get_together/views/speakers.py b/get_together/views/speakers.py index 2d31348..c903794 100644 --- a/get_together/views/speakers.py +++ b/get_together/views/speakers.py @@ -240,6 +240,11 @@ def delete_talk(request, talk_id): def propose_event_talk(request, event_id): event = get_object_or_404(Event, id=event_id) + if not event.enable_presentations: + messages.add_message(request, messages.WARNING, message=_('This event does not allow presentations.')) + return redirect(event.get_absolute_url()) + + if request.method == 'GET': profile = request.user.profile talks = list(Talk.objects.filter(speaker__user=profile))