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)
|
confirm = forms.BooleanField(label="Yes, delete team", required=True)
|
||||||
|
|
||||||
class TeamEventForm(forms.ModelForm):
|
class TeamEventForm(forms.ModelForm):
|
||||||
|
recurrences = recurrence.forms.RecurrenceField(label="Repeat", required=False)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Event
|
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 = {
|
widgets = {
|
||||||
'place': Lookup(source=Place),
|
'place': Lookup(source=Place),
|
||||||
'start_time': DateTimeWidget,
|
'start_time': DateTimeWidget,
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
{% extends "get_together/base.html" %}
|
{% extends "get_together/base.html" %}
|
||||||
{% load static %}
|
{% 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 %}
|
{% block content %}
|
||||||
<h2>Updating {{event.name}}</h2>
|
<h2>Updating {{event.name}}</h2>
|
||||||
<form action="{% url "edit-event" event.id%}" method="post">
|
<form action="{% url "edit-event" event.id%}" method="post">
|
||||||
|
|
|
@ -123,7 +123,8 @@ def create_event(request, team_id):
|
||||||
new_series.save()
|
new_series.save()
|
||||||
new_event.series = new_series
|
new_event.series = new_series
|
||||||
new_event.save()
|
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)
|
return redirect('add-place', new_event.id)
|
||||||
else:
|
else:
|
||||||
context = {
|
context = {
|
||||||
|
@ -240,6 +241,8 @@ def edit_event(request, event_id):
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
form = TeamEventForm(instance=event)
|
form = TeamEventForm(instance=event)
|
||||||
|
if event.series is not None:
|
||||||
|
form.initial['recurrences'] = event.series.recurrences
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'team': event.team,
|
'team': event.team,
|
||||||
|
@ -251,6 +254,17 @@ def edit_event(request, event_id):
|
||||||
form = TeamEventForm(request.POST,instance=event)
|
form = TeamEventForm(request.POST,instance=event)
|
||||||
if form.is_valid:
|
if form.is_valid:
|
||||||
new_event = form.save()
|
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())
|
return redirect(new_event.get_absolute_url())
|
||||||
else:
|
else:
|
||||||
context = {
|
context = {
|
||||||
|
|
Loading…
Reference in a new issue