Add ability for org owners to edit common events
This commit is contained in:
parent
b74c95e923
commit
9f09405ecd
7 changed files with 143 additions and 11 deletions
|
@ -469,7 +469,7 @@ class InviteToJoinOrgForm(forms.ModelForm):
|
||||||
class AcceptInviteToJoinOrgForm(forms.Form):
|
class AcceptInviteToJoinOrgForm(forms.Form):
|
||||||
confirm = forms.BooleanField(label="Yes, add my team to this organization", required=True)
|
confirm = forms.BooleanField(label="Yes, add my team to this organization", required=True)
|
||||||
|
|
||||||
class NewCommonEventForm(forms.ModelForm):
|
class CommonEventForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CommonEvent
|
model = CommonEvent
|
||||||
fields = [
|
fields = [
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{% extends "get_together/base.html" %}
|
{% extends "get_together/base.html" %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
{% block extra_google_analytics %}
|
|
||||||
gtag('config', '{{settings.GOOGLE_ANALYTICS_ID}}', {'page_path': '/org/+create-event/'});
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Plan a <strong>{{org.name}}</strong> event</h2>
|
<h2>Plan a <strong>{{org.name}}</strong> event</h2>
|
||||||
<form action="{% url "create-common-event" org.slug%}" method="post">
|
<form action="{% url "create-common-event" org.slug%}" method="post">
|
||||||
|
|
100
get_together/templates/get_together/orgs/edit_common_event.html
Normal file
100
get_together/templates/get_together/orgs/edit_common_event.html
Normal 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 %}
|
|
@ -90,7 +90,9 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
{% if can_edit_event %}
|
{% 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 %}
|
{% endif %}
|
||||||
{% if common_event.organization.banner_img %}
|
{% if common_event.organization.banner_img %}
|
||||||
<div class="team-banner mb-3">
|
<div class="team-banner mb-3">
|
||||||
|
|
|
@ -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/+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('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>/+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('common/<int:event_id>/<str:event_slug>/', views.show_common_event, name='show-common-event'),
|
||||||
|
|
||||||
path('places/', views.places_list, name='places'),
|
path('places/', views.places_list, name='places'),
|
||||||
|
|
|
@ -36,7 +36,6 @@ from events.forms import (
|
||||||
EventCommentForm,
|
EventCommentForm,
|
||||||
NewPlaceForm,
|
NewPlaceForm,
|
||||||
UploadEventPhotoForm,
|
UploadEventPhotoForm,
|
||||||
NewCommonEventForm,
|
|
||||||
EventInviteEmailForm,
|
EventInviteEmailForm,
|
||||||
EventInviteMemberForm,
|
EventInviteMemberForm,
|
||||||
EventContactForm,
|
EventContactForm,
|
||||||
|
|
|
@ -13,7 +13,7 @@ from django.conf import settings
|
||||||
|
|
||||||
from events.models.profiles import Organization, Team, UserProfile, Member, OrgTeamRequest
|
from events.models.profiles import Organization, Team, UserProfile, Member, OrgTeamRequest
|
||||||
from events.models.events import Event, CommonEvent, Place, Attendee
|
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 import location
|
||||||
from events.utils import slugify
|
from events.utils import slugify
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ def show_common_event(request, event_id, event_slug):
|
||||||
'org': event.organization,
|
'org': event.organization,
|
||||||
'common_event': event,
|
'common_event': event,
|
||||||
'participating_events': event.participating_events.all().order_by('start_time'),
|
'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)
|
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)
|
new_event = CommonEvent(organization=org, created_by=request.user.profile)
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
form = NewCommonEventForm(instance=new_event)
|
form = CommonEventForm(instance=new_event)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'org': org,
|
'org': org,
|
||||||
|
@ -318,7 +318,7 @@ def create_common_event(request, org_slug):
|
||||||
}
|
}
|
||||||
return render(request, 'get_together/orgs/create_common_event.html', context)
|
return render(request, 'get_together/orgs/create_common_event.html', context)
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
form = NewCommonEventForm(request.POST, instance=new_event)
|
form = CommonEventForm(request.POST, instance=new_event)
|
||||||
if form.is_valid:
|
if form.is_valid:
|
||||||
new_event = form.save()
|
new_event = form.save()
|
||||||
send_common_event_invite(new_event)
|
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)
|
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')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue