Repository :
http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
---------------------------------------------------------------
commit 44c48824cebdb4e0db2fa0bd19755c1d35486370
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Sun Nov 25 15:20:18 2012 +0100
Add code to delete a Calendar if you are an admin
You can only delete a Calendar if you are an admin and you delete the calendar which
is
in the current view. So change your calendar in the main menu then go to:
admin > delete calendar.
Adjust the unit-tests accordingly so that the deletion is also tested.
---------------------------------------------------------------
fedocal/__init__.py | 27 ++++++++++++++++++++++++++
fedocal/forms.py | 5 ++++
fedocal/templates/delete_calendar.html | 33 ++++++++++++++++++++++++++++++++
fedocal/templates/master.html | 8 ++++++-
fedocal/tests/test_calendar.py | 19 ++++++++++++++++++
5 files changed, 91 insertions(+), 1 deletions(-)
diff --git a/fedocal/__init__.py b/fedocal/__init__.py
index 470b338..c3406f6 100644
--- a/fedocal/__init__.py
+++ b/fedocal/__init__.py
@@ -461,6 +461,33 @@ def delete_meeting(meeting_id):
title=meeting.meeting_name)
+(a)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.
+
+ :arg meeting_id: the identifier of the meeting to delete.
+ """
+ if not flask.g.fas_user or not is_admin():
+ return flask.redirect(flask.url_for('index'))
+ calendarobj = Calendar.by_id(SESSION, calendar_name)
+ deleteform = forms.DeleteCalendarForm()
+ # pylint: disable=E1101
+ if deleteform.validate_on_submit():
+ if deleteform.confirm_delete.data:
+ calendarobj.delete(SESSION)
+ try:
+ SESSION.commit()
+ # pylint: disable=W0703
+ except Exception, err:
+ print 'delete_calendar:', err
+ flask.flash('Could not delete this calendar.')
+ flask.flash('Calendar deleted')
+ return flask.redirect(flask.url_for('index'))
+ return flask.render_template('delete_calendar.html',
+ form=deleteform, calendarobj=calendarobj)
+
+
if __name__ == '__main__': # pragma: no cover
APP.debug = True
APP.run()
diff --git a/fedocal/forms.py b/fedocal/forms.py
index 3b7f13f..e79cc65 100644
--- a/fedocal/forms.py
+++ b/fedocal/forms.py
@@ -150,6 +150,11 @@ class DeleteMeetingForm(wtf.Form):
'Yes, I want to delete all futher meetings.')
+class DeleteCalendarForm(wtf.Form):
+ """ Form used to delete a calendar. """
+ confirm_delete = wtf.BooleanField('Yes I want to delete this calendar')
+
+
class LoginForm(wtf.Form):
""" Form to log in the application. """
username = wtf.TextField('Username', [wtf.validators.Required()])
diff --git a/fedocal/templates/delete_calendar.html
b/fedocal/templates/delete_calendar.html
new file mode 100644
index 0000000..dad6825
--- /dev/null
+++ b/fedocal/templates/delete_calendar.html
@@ -0,0 +1,33 @@
+{% extends "master.html" %}
+
+{% block title %} {{ calendarobj.calendar_name }} {% endblock %}
+
+{% set title_extent = 'delete calendar' %}
+
+{% block content %}
+
+<h4> Calendar: {{ calendarobj.calendar_name}}</h4>
+
+<ul>
+ <li>Contact: {{ calendarobj.calendar_contact }} </li>
+ <li>Description: {{ calendarobj.calendar_description }} </li>
+ <li>Manager group: {{ calendarobj.calendar_manager_group }} </li>
+ <li>Multiple meetings: {{ calendarobj.calendar_multiple_meetings }}
</li>
+ <li>Regional meeting: {{ calendarobj.calendar_regional_meetings }} </li>
+</ul>
+
+
+<p>
+ Are you positively sure that's what you want to do?
+</p>
+
+<form action="" method="post">
+{{ render_field_invert(form.confirm_delete) }}
+<p class="buttons indent">
+ <input type="submit" class="submit positive button"
value="Delete">
+ <input type="button" value="Cancel" class="button"
onclick="history.back();">
+</p>
+{{ form.csrf_token }}
+</form>
+
+{% endblock %}
diff --git a/fedocal/templates/master.html b/fedocal/templates/master.html
index b4a5e12..fb21e36 100644
--- a/fedocal/templates/master.html
+++ b/fedocal/templates/master.html
@@ -98,8 +98,14 @@
<h4> Admin </h4>
<ul>
<li>
- <a href="{{ url_for('add_calendar') }}"> Add
a calendar </a>
+ <a href="{{ url_for('add_calendar') }}">
Add a calendar </a>
</li>
+ {% if calendar %}
+ <li>
+ <a href="{{ url_for('delete_calendar',
+ calendar_name=calendar.calendar_name) }}"> Delete
calendar </a>
+ </li>
+ {% endif %}
</ul>
{% endif %}
</div>
diff --git a/fedocal/tests/test_calendar.py b/fedocal/tests/test_calendar.py
index eee73ed..f3ea640 100644
--- a/fedocal/tests/test_calendar.py
+++ b/fedocal/tests/test_calendar.py
@@ -144,6 +144,25 @@ class Calendartests(Modeltests):
self.assertEqual(len(obj), 0)
self.assertEqual(obj, [])
+ def test_delete(self):
+ """ Test the Calendar.delete method. """
+ self.test_init_calendar()
+ obj = model.Calendar.get_all(self.session)
+ self.assertNotEqual(obj, None)
+ self.assertEqual(len(obj), 4)
+ obj = model.Calendar.by_id(self.session, 'test_calendar')
+ self.assertNotEqual(obj, None)
+
+ obj.delete(self.session)
+ self.session.commit()
+
+ obj = model.Calendar.get_all(self.session)
+ self.assertNotEqual(obj, None)
+ self.assertEqual(len(obj), 3)
+ obj = model.Calendar.by_id(self.session, 'test_calendar')
+ self.assertEqual(obj, None)
+
+
if __name__ == '__main__':
SUITE = unittest.TestLoader().loadTestsFromTestCase(Calendartests)
unittest.TextTestRunner(verbosity=2).run(SUITE)