Allow adding recurrence data to an existing event to create a new event series. Fixes #68
This commit is contained in:
parent
c7ebe12875
commit
e4046f3e65
3 changed files with 23 additions and 2 deletions
|
@ -184,9 +184,10 @@ class DeleteTeamForm(forms.Form):
|
|||
confirm = forms.BooleanField(label="Yes, delete team", required=True)
|
||||
|
||||
class TeamEventForm(forms.ModelForm):
|
||||
recurrences = recurrence.forms.RecurrenceField(label="Repeat", required=False)
|
||||
class Meta:
|
||||
model = Event
|
||||
fields = ['name', 'start_time', 'end_time', 'summary', 'web_url', 'announce_url', 'tags']
|
||||
fields = ['name', 'start_time', 'end_time', 'recurrences', 'summary', 'web_url', 'announce_url', 'tags']
|
||||
widgets = {
|
||||
'place': Lookup(source=Place),
|
||||
'start_time': DateTimeWidget,
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
{% extends "get_together/base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block meta %}
|
||||
<script type="text/javascript" src="{% static 'recurrence/js/recurrence.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'recurrence/js/recurrence-widget.js' %}"></script>
|
||||
<link href="{% static 'recurrence/css/recurrence.css' %}" rel="stylesheet">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Updating {{event.name}}</h2>
|
||||
<form action="{% url "edit-event" event.id%}" method="post">
|
||||
|
|
|
@ -123,7 +123,8 @@ def create_event(request, team_id):
|
|||
new_series.save()
|
||||
new_event.series = new_series
|
||||
new_event.save()
|
||||
messages.add_message(request, messages.SUCCESS, message=_('Your event has been scheduled! Next, find a place for your event.'))
|
||||
|
||||
messages.add_message(request, messages.SUCCESS, message=_('Your event has been scheduled! Next, find a place for your event.'))
|
||||
return redirect('add-place', new_event.id)
|
||||
else:
|
||||
context = {
|
||||
|
@ -240,6 +241,8 @@ def edit_event(request, event_id):
|
|||
|
||||
if request.method == 'GET':
|
||||
form = TeamEventForm(instance=event)
|
||||
if event.series is not None:
|
||||
form.initial['recurrences'] = event.series.recurrences
|
||||
|
||||
context = {
|
||||
'team': event.team,
|
||||
|
@ -251,6 +254,17 @@ def edit_event(request, event_id):
|
|||
form = TeamEventForm(request.POST,instance=event)
|
||||
if form.is_valid:
|
||||
new_event = form.save()
|
||||
|
||||
if form.cleaned_data.get('recurrences', None):
|
||||
if event.series is not None:
|
||||
event.series.recurrences = form.cleaned_data['recurrences']
|
||||
event.series.save()
|
||||
else:
|
||||
new_series = EventSeries.from_event(new_event, recurrences=form.cleaned_data['recurrences'])
|
||||
new_series.save()
|
||||
new_event.series = new_series
|
||||
new_event.save()
|
||||
|
||||
return redirect(new_event.get_absolute_url())
|
||||
else:
|
||||
context = {
|
||||
|
|
Loading…
Reference in a new issue