Add ability for org owners to edit common events

This commit is contained in:
Michael Hall 2018-09-07 14:20:06 -04:00
parent b74c95e923
commit 9f09405ecd
7 changed files with 143 additions and 11 deletions

View file

@ -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 = [

View file

@ -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 %}
<h2>Plan a <strong>{{org.name}}</strong> event</h2>
<form action="{% url "create-common-event" org.slug%}" method="post">

View file

@ -0,0 +1,100 @@
{% extends "get_together/base.html" %}
{% load static %}
{% block content %}
<h2>Plan a <strong>{{org.name}}</strong> event</h2>
<form action="{% url 'edit-common-event' event.id %}" method="post">
{% csrf_token %}
<div class="form-group">
{% include "events/event_form.html" %}
<br />
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
{% endblock %}
{% block javascript %}
<script src="{% static 'js/jquery-ui-lookup.js' %}"></script>
<script type="text/javascript">
$(document).ready(function(){
$.datepicker.setDefaults({
showOn: 'focus',
dateFormat: 'yy-mm-dd',
});
$("#id_start_time_0").datepicker({altField: "#id_end_time_0", altFormat: "yy-mm-dd"});
$("#id_end_time_0").datepicker();
$("#id_continent").selectmenu();
$("#country_select").lookup({
search: function(searchText, callback) {
if (searchText.length < 3) return callback(searchText, []);
$.getJSON("/api/countries/?q="+searchText, function(data) {
var m = this.url.match(/q=([^&]+)/);
var q = "";
if (m && m.length > 0) {
q = this.url.match(/q=([^&]+)/)[1]
}
return callback(q, data);
});
}
})
$("#spr_select").lookup({
search: function(searchText, callback) {
if (searchText.length < 3) return callback(searchText, []);
$.getJSON("/api/spr/?q="+searchText, function(data) {
var m = this.url.match(/q=([^&]+)/);
var q = "";
if (m && m.length > 0) {
q = this.url.match(/q=([^&]+)/)[1]
}
return callback(q, data);
});
}
})
$("#city_select").lookup({
search: function(searchText, callback) {
if (searchText.length < 3) return callback(searchText, []);
$.getJSON("/api/cities/?q="+searchText, function(data) {
var m = this.url.match(/q=([^&]+)/);
var q = "";
if (m && m.length > 0) {
q = this.url.match(/q=([^&]+)/)[1]
}
return callback(q, data);
});
}
})
$("#place_select").lookup({
search: function(searchText, callback) {
if (searchText.length < 3) return callback(searchText, []);
$.getJSON("/api/places/?q="+searchText, function(data) {
var m = this.url.match(/q=([^&]+)/);
var q = "";
if (m && m.length > 0) {
q = this.url.match(/q=([^&]+)/)[1]
}
return callback(q, data);
});
}
})
$("#id_category").selectmenu();
$("#id_tz").selectmenu();
$("#id_start_time_1").selectmenu({width: 150});
$("#id_end_time_1").selectmenu({width: 150});
});
</script>
{% endblock %}

View file

@ -90,7 +90,9 @@
<div class="row">
<div class="col-md-9">
{% if can_edit_event %}
<a href="{% url 'edit-common-event' common_event.id %}" class="btn btn-secondary btn-sm">Edit</a>
<div id="admin_buttons" class="mb-2">
<a href="{% url 'edit-common-event' common_event.id %}" class="btn btn-secondary btn-sm"><i class="fa fa-pencil"></i> Edit Event</a>
</div>
{% endif %}
{% if common_event.organization.banner_img %}
<div class="team-banner mb-3">

View file

@ -112,6 +112,7 @@ urlpatterns = [
path('org/+confirm_request/<str:request_key>/', views.confirm_request_to_join_org, name='confirm-request-to-join-org'),
path('org/<str:org_slug>/+create-event/', views.create_common_event, name='create-common-event'),
path('common/<int:event_id>/+create-event/', views.create_common_event_team_select, name='create-common-event-team-select'),
path('common/<int:event_id>/+edit/', views.edit_common_event, name='edit-common-event'),
path('common/<int:event_id>/<str:event_slug>/', views.show_common_event, name='show-common-event'),
path('places/', views.places_list, name='places'),

View file

@ -36,7 +36,6 @@ from events.forms import (
EventCommentForm,
NewPlaceForm,
UploadEventPhotoForm,
NewCommonEventForm,
EventInviteEmailForm,
EventInviteMemberForm,
EventContactForm,

View file

@ -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')