summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2008-04-07 13:43:51 +0200
committerGuillaume Seguin <guillaume@segu.in>2008-04-07 13:43:51 +0200
commitb70cd62ffaa3b5f89cc9e381454f380113765c2c (patch)
tree76c42cf4ce783a6b2dfbf4fb375ba2979a52459e
parentb03a49aff14de130a2c0d3fcd60b355d9f6c6289 (diff)
downloadmarks-b70cd62ffaa3b5f89cc9e381454f380113765c2c.tar.gz
marks-b70cd62ffaa3b5f89cc9e381454f380113765c2c.tar.bz2
* Add marks view to compare the totals of a given marks set
-rw-r--r--main/views.py41
-rw-r--r--templates/main/marks.html21
-rw-r--r--urls.py1
3 files changed, 63 insertions, 0 deletions
diff --git a/main/views.py b/main/views.py
index 0b4c727..a0aa713 100644
--- a/main/views.py
+++ b/main/views.py
@@ -94,6 +94,47 @@ def export_view (request):
response.write (data)
return response
+def get_rating (user_data, exam, name):
+ '''Helper function returning the stored rating if it exists, 0 otherwise'''
+ if exam in user_data["ratings"][name]:
+ return user_data["ratings"][name][exam]
+ else:
+ return 0
+
+def get_mark (user_data, exam, name):
+ '''Helper function returning the stored mark if it exists, 0 otherwise'''
+ if exam in user_data["marks"][name]:
+ return user_data["marks"][name][exam]
+ else:
+ return 0
+
+def marks_view (request, name):
+ '''View the totals of a given marks set'''
+ user_data = get_user_data (request)
+ if not name in user_data["marks"]:
+ return home_view (request)
+ marks = {}
+ for exam in user_data["exams"]:
+ marks[exam] = get_mark (user_data, exam, name)
+ totals = {}
+ for set in user_data["ratings"]:
+ total_ratings = 0
+ total = 0
+ for exam in user_data["exams"]:
+ rating = get_rating (user_data, exam, set)
+ total += rating * get_mark (user_data, exam, name)
+ total_ratings += rating
+ if total_ratings:
+ totals[set] = round (float (total) / total_ratings, 2)
+ else:
+ totals[set] = 0
+ data = {
+ "name": name,
+ "marks": marks,
+ "totals": totals,
+ }
+ return render_page (request, data, "main/marks.html")
+
def delete_exam_view (request, exam):
'''Removes an exam'''
user_data = get_user_data (request)
diff --git a/templates/main/marks.html b/templates/main/marks.html
new file mode 100644
index 0000000..ec7b508
--- /dev/null
+++ b/templates/main/marks.html
@@ -0,0 +1,21 @@
+{% extends "main/base.html" %}
+{% load marks_tags %}
+
+{% block title %}{{ block.super }}{% endblock %}
+
+{% block content %}
+{% rounded_block_start 'fullblock' 'halfblock' %}Jeu de notes {{ name }}{% end_rounded_block_start %}
+<h4>Notes</h4>
+<ul>
+ {% for exam,mark in marks.items %}
+ <li>{{ exam }}: {{ mark }}</li>
+ {% endfor %}
+</ul>
+<h4>Totaux</h4>
+<ul>
+ {% for set_name,total in totals.items %}
+ <li>{{ set_name }}: {{ total }}</li>
+ {% endfor %}
+</ul>
+{% rounded_block_end %}
+{% endblock %}
diff --git a/urls.py b/urls.py
index 61ac87c..84a8453 100644
--- a/urls.py
+++ b/urls.py
@@ -23,6 +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'^view/marks/(.+)$', 'marks.main.views.marks_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'),