From 9f09405ecdcea534eee48094eb070c337d2e233c Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Fri, 7 Sep 2018 14:20:06 -0400 Subject: [PATCH] Add ability for org owners to edit common events --- events/forms.py | 2 +- .../orgs/create_common_event.html | 4 - .../get_together/orgs/edit_common_event.html | 100 ++++++++++++++++++ .../get_together/orgs/show_common_event.html | 4 +- get_together/urls.py | 1 + get_together/views/events.py | 1 - get_together/views/orgs.py | 42 +++++++- 7 files changed, 143 insertions(+), 11 deletions(-) create mode 100644 get_together/templates/get_together/orgs/edit_common_event.html diff --git a/events/forms.py b/events/forms.py index fd3b418..62a3e93 100644 --- a/events/forms.py +++ b/events/forms.py @@ -469,7 +469,7 @@ class InviteToJoinOrgForm(forms.ModelForm): class AcceptInviteToJoinOrgForm(forms.Form): confirm = forms.BooleanField(label="Yes, add my team to this organization", required=True) -class NewCommonEventForm(forms.ModelForm): +class CommonEventForm(forms.ModelForm): class Meta: model = CommonEvent fields = [ diff --git a/get_together/templates/get_together/orgs/create_common_event.html b/get_together/templates/get_together/orgs/create_common_event.html index b583db1..f67a05a 100644 --- a/get_together/templates/get_together/orgs/create_common_event.html +++ b/get_together/templates/get_together/orgs/create_common_event.html @@ -1,10 +1,6 @@ {% extends "get_together/base.html" %} {% load static %} -{% block extra_google_analytics %} - gtag('config', '{{settings.GOOGLE_ANALYTICS_ID}}', {'page_path': '/org/+create-event/'}); -{% endblock %} - {% block content %}

Plan a {{org.name}} event

diff --git a/get_together/templates/get_together/orgs/edit_common_event.html b/get_together/templates/get_together/orgs/edit_common_event.html new file mode 100644 index 0000000..e2fe3d8 --- /dev/null +++ b/get_together/templates/get_together/orgs/edit_common_event.html @@ -0,0 +1,100 @@ +{% extends "get_together/base.html" %} +{% load static %} + +{% block content %} +

Plan a {{org.name}} event

+ +{% csrf_token %} +
+{% include "events/event_form.html" %} +
+ +
+
+{% endblock %} + +{% block javascript %} + + +{% endblock %} diff --git a/get_together/templates/get_together/orgs/show_common_event.html b/get_together/templates/get_together/orgs/show_common_event.html index c49f990..f662807 100644 --- a/get_together/templates/get_together/orgs/show_common_event.html +++ b/get_together/templates/get_together/orgs/show_common_event.html @@ -90,7 +90,9 @@
{% if can_edit_event %} - Edit + {% endif %} {% if common_event.organization.banner_img %}
diff --git a/get_together/urls.py b/get_together/urls.py index 9f40adb..17358ee 100644 --- a/get_together/urls.py +++ b/get_together/urls.py @@ -112,6 +112,7 @@ urlpatterns = [ path('org/+confirm_request//', views.confirm_request_to_join_org, name='confirm-request-to-join-org'), path('org//+create-event/', views.create_common_event, name='create-common-event'), path('common//+create-event/', views.create_common_event_team_select, name='create-common-event-team-select'), + path('common//+edit/', views.edit_common_event, name='edit-common-event'), path('common///', views.show_common_event, name='show-common-event'), path('places/', views.places_list, name='places'), diff --git a/get_together/views/events.py b/get_together/views/events.py index c4a56af..79b9632 100644 --- a/get_together/views/events.py +++ b/get_together/views/events.py @@ -36,7 +36,6 @@ from events.forms import ( EventCommentForm, NewPlaceForm, UploadEventPhotoForm, - NewCommonEventForm, EventInviteEmailForm, EventInviteMemberForm, EventContactForm, diff --git a/get_together/views/orgs.py b/get_together/views/orgs.py index fca92d2..6b025cb 100644 --- a/get_together/views/orgs.py +++ b/get_together/views/orgs.py @@ -13,7 +13,7 @@ from django.conf import settings from events.models.profiles import Organization, Team, UserProfile, Member, OrgTeamRequest from events.models.events import Event, CommonEvent, Place, Attendee -from events.forms import OrganizationForm, NewCommonEventForm, RequestToJoinOrgForm, InviteToJoinOrgForm, AcceptRequestToJoinOrgForm, AcceptInviteToJoinOrgForm +from events.forms import OrganizationForm, CommonEventForm, RequestToJoinOrgForm, InviteToJoinOrgForm, AcceptRequestToJoinOrgForm, AcceptInviteToJoinOrgForm from events import location from events.utils import slugify @@ -296,7 +296,7 @@ def show_common_event(request, event_id, event_slug): 'org': event.organization, 'common_event': event, 'participating_events': event.participating_events.all().order_by('start_time'), - 'can_edit_event': False, + 'can_edit_event': request.user.profile.can_create_common_event(event.organization), } return render(request, 'get_together/orgs/show_common_event.html', context) @@ -310,7 +310,7 @@ def create_common_event(request, org_slug): new_event = CommonEvent(organization=org, created_by=request.user.profile) if request.method == 'GET': - form = NewCommonEventForm(instance=new_event) + form = CommonEventForm(instance=new_event) context = { 'org': org, @@ -318,7 +318,7 @@ def create_common_event(request, org_slug): } return render(request, 'get_together/orgs/create_common_event.html', context) elif request.method == 'POST': - form = NewCommonEventForm(request.POST, instance=new_event) + form = CommonEventForm(request.POST, instance=new_event) if form.is_valid: new_event = form.save() send_common_event_invite(new_event) @@ -384,3 +384,37 @@ def create_common_event_team_select(request, event_id): } return render(request, 'get_together/orgs/create_common_event_team_select.html', context) + +@login_required +def edit_common_event(request, event_id): + event = get_object_or_404(CommonEvent, id=event_id) + org = event.organization + if not request.user.profile.can_create_common_event(org): + messages.add_message(request, messages.WARNING, message=_('You can not edit events for this org.')) + return redirect('show-org', org_id=org.pk) + + if request.method == 'GET': + form = CommonEventForm(instance=event) + + context = { + 'org': org, + 'event': event, + 'event_form': form, + } + return render(request, 'get_together/orgs/edit_common_event.html', context) + elif request.method == 'POST': + form = CommonEventForm(request.POST, instance=event) + if form.is_valid(): + new_event = form.save() + return redirect('show-common-event', new_event.id, new_event.slug) + else: + context = { + 'org': org, + 'event': event, + 'event_form': form, + } + return render(request, 'get_together/orgs/edit_common_event.html', context) + else: + return redirect('home') + +