summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2008-04-07 01:07:12 +0200
committerGuillaume Seguin <guillaume@segu.in>2008-04-07 01:07:12 +0200
commita777e1bfa975125c9bac8f8c1940a03c29bf18c1 (patch)
treec97a2830814658e3855b46013be329b209486989
parent3fbd8f05e0c633ff6167b8d1952cd10b0f41d68e (diff)
downloadmarks-a777e1bfa975125c9bac8f8c1940a03c29bf18c1.tar.gz
marks-a777e1bfa975125c9bac8f8c1940a03c29bf18c1.tar.bz2
* Add views to delete exams/ratings sets/marks sets
-rw-r--r--main/views.py32
-rw-r--r--urls.py3
2 files changed, 35 insertions, 0 deletions
diff --git a/main/views.py b/main/views.py
index 97d1ddc..0b4c727 100644
--- a/main/views.py
+++ b/main/views.py
@@ -93,3 +93,35 @@ def export_view (request):
response["Content-Disposition"] = "attachment; filename=%s" % filename
response.write (data)
return response
+
+def delete_exam_view (request, exam):
+ '''Removes an exam'''
+ user_data = get_user_data (request)
+ if not exam in user_data["exams"]:
+ return home_view (request)
+ else:
+ user_data["exams"].remove (exam)
+ for name in user_data["ratings"]:
+ del user_data["ratings"][name][exam]
+ for name in user_data["marks"]:
+ del user_data["marks"][name][exam]
+ set_user_data (request, user_data)
+ return home_view (request)
+
+def delete_user_data_item (request, key, name):
+ '''Removes an user data item'''
+ user_data = get_user_data (request)
+ if not name in user_data[key]:
+ return home_view (request)
+ else:
+ del user_data[key][name]
+ set_user_data (request, user_data)
+ return home_view (request)
+
+def delete_ratings_view (request, name):
+ '''Removes a ratings set'''
+ return delete_user_data_item (request, "ratings", name)
+
+def delete_marks_view (request, name):
+ '''Removes a marks set'''
+ return delete_user_data_item (request, "marks", name)
diff --git a/urls.py b/urls.py
index 2c29926..61ac87c 100644
--- a/urls.py
+++ b/urls.py
@@ -23,4 +23,7 @@ urlpatterns = patterns('',
(r'^$', 'marks.main.views.home_view'),
(r'^reset$', 'marks.main.views.reset_view'),
(r'^export$', 'marks.main.views.export_view'),
+ (r'^delete/exam/(.+)$', 'marks.main.views.delete_exam_view'),
+ (r'^delete/ratings/(.+)$', 'marks.main.views.delete_ratings_view'),
+ (r'^delete/marks/(.+)$', 'marks.main.views.delete_marks_view'),
)