Repository :
http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
---------------------------------------------------------------
commit 0eac762606a6a4ab53efd9ff2c769bbf4b88b062
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Tue Nov 27 15:32:55 2012 +0100
Add support to edit calendar information
There is now an entry in the admin menu which allows to edit a calendar and thus
change its specifications.
Fixes #15
---------------------------------------------------------------
fedocal/__init__.py | 45 +++++++++++++++++++-
fedocal/forms.py | 19 ++++++++
.../{add_calendar.html => edit_calendar.html} | 6 +-
fedocal/templates/master.html | 4 ++
4 files changed, 69 insertions(+), 5 deletions(-)
diff --git a/fedocal/__init__.py b/fedocal/__init__.py
index c3406f6..f0f151a 100644
--- a/fedocal/__init__.py
+++ b/fedocal/__init__.py
@@ -464,9 +464,9 @@ def delete_meeting(meeting_id):
@APP.route('/calendar/delete/<calendar_name>/', methods=('GET',
'POST'))
@cla_plus_one_required
def delete_calendar(calendar_name):
- """ Delete a specific meeting given its identifier.
+ """ Delete a specific calendar given its identifier.
- :arg meeting_id: the identifier of the meeting to delete.
+ :arg calendar_name: the identifier of the calendar to delete.
"""
if not flask.g.fas_user or not is_admin():
return flask.redirect(flask.url_for('index'))
@@ -488,6 +488,47 @@ def delete_calendar(calendar_name):
form=deleteform, calendarobj=calendarobj)
+# pylint: disable=R0915,R0912,R0911
+# CLA + 1
+(a)APP.route('/calendar/edit/<calendar_name>/', methods=('GET',
'POST'))
+@cla_plus_one_required
+def edit_calendar(calendar_name):
+ """ Edit a specific calendar based on the calendar identifier.
+
+ :arg calendar_name: the identifier of the calendar to edit.
+ """
+ if not flask.g.fas_user or not is_admin():
+ return flask.redirect(flask.url_for('index'))
+ calendarobj = Calendar.by_id(SESSION, calendar_name)
+ form = forms.AddCalendarForm()
+ # pylint: disable=E1101
+ if form.validate_on_submit():
+ try:
+ calendarobj.calendar_name = form.calendar_name.data
+ calendarobj.calendar_contact = form.calendar_contact.data
+ calendarobj.calendar_description = form.calendar_description.data
+ calendarobj.calendar_manager_group = \
+ form.calendar_manager_groups.data
+ calendarobj.calendar_multiple_meetings = bool(
+ form.calendar_multiple_meetings.data)
+ calendarobj.calendar_regional_meetings = bool(
+ form.calendar_regional_meetings.data)
+ calendarobj.save(SESSION)
+ SESSION.commit()
+ except SQLAlchemyError, err:
+ print 'edit_calendar:', err
+ flask.flash('Could not update this calendar.')
+ return flask.render_template('edit_calendar.html', form=form,
+ calendar=calendarobj)
+
+ flask.flash('Calendar updated')
+ return flask.redirect(flask.url_for('calendar',
+ calendar_name=calendarobj.calendar_name))
+ else:
+ form = forms.AddCalendarForm(calendar=calendarobj)
+ return flask.render_template('edit_calendar.html', form=form,
+ calendar=calendarobj)
+
if __name__ == '__main__': # pragma: no cover
APP.debug = True
APP.run()
diff --git a/fedocal/forms.py b/fedocal/forms.py
index a17602f..913c6cd 100644
--- a/fedocal/forms.py
+++ b/fedocal/forms.py
@@ -58,6 +58,25 @@ class AddCalendarForm(wtf.Form):
calendar_regional_meetings = wtf.BooleanField(
'Meetings can regional?')
+ def __init__(self, *args, **kwargs):
+ """ Calls the default constructor with the normal argument but
+ if a calendar is set using the calendar keyword, then fill the
+ value of the form with the value from the Calendar object.
+ """
+ super(AddCalendarForm, self).__init__(*args, **kwargs)
+ if 'calendar' in kwargs:
+ calendar = kwargs['calendar']
+
+ self.calendar_name.data = calendar.calendar_name
+ self.calendar_contact.data = calendar.calendar_contact
+ self.calendar_description.data = calendar.calendar_description
+ self.calendar_manager_groups.data = \
+ calendar.calendar_manager_group
+ self.calendar_multiple_meetings.data = bool(
+ calendar.calendar_multiple_meetings)
+ self.calendar_regional_meetings.data = bool(
+ calendar.calendar_regional_meetings)
+
class AddMeetingForm(wtf.Form):
""" Form used to create a new meeting. """
diff --git a/fedocal/templates/add_calendar.html b/fedocal/templates/edit_calendar.html
similarity index 88%
copy from fedocal/templates/add_calendar.html
copy to fedocal/templates/edit_calendar.html
index 772518d..cc9f0d9 100644
--- a/fedocal/templates/add_calendar.html
+++ b/fedocal/templates/edit_calendar.html
@@ -8,8 +8,8 @@
{% block content %}
<section>
<header>
- <h2>New calendar</h2>
- <p>Please enter your calendar details in the form below.</p>
+ <h2>Edit calendar</h2>
+ <p>Edit the calendar details in the form below.</p>
</header>
<form action="" method="post">
@@ -20,7 +20,7 @@
{{ render_field(form.calendar_multiple_meetings) }}
{{ render_field(form.calendar_regional_meetings) }}
<p class="buttons indent">
- <input type="submit" class="submit positive button"
value="Create">
+ <input type="submit" class="submit positive button"
value="Edit">
<input type="button" value="Cancel"
class="button" onclick="history.back();">
{{ form.csrf_token }}
</p>
diff --git a/fedocal/templates/master.html b/fedocal/templates/master.html
index fb21e36..21aca49 100644
--- a/fedocal/templates/master.html
+++ b/fedocal/templates/master.html
@@ -102,6 +102,10 @@
</li>
{% if calendar %}
<li>
+ <a href="{{ url_for('edit_calendar',
+ calendar_name=calendar.calendar_name) }}"> Edit
calendar </a>
+ </li>
+ <li>
<a href="{{ url_for('delete_calendar',
calendar_name=calendar.calendar_name) }}"> Delete
calendar </a>
</li>