summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2008-04-07 01:06:40 +0200
committerGuillaume Seguin <guillaume@segu.in>2008-04-07 01:06:40 +0200
commit3fbd8f05e0c633ff6167b8d1952cd10b0f41d68e (patch)
tree6fd1dfecb25d8fed89dd4a303864e4072ea3b074
parent61a098542d3865904ef4c667665dd3f557e1e8ab (diff)
downloadmarks-3fbd8f05e0c633ff6167b8d1952cd10b0f41d68e.tar.gz
marks-3fbd8f05e0c633ff6167b8d1952cd10b0f41d68e.tar.bz2
* Add export view to export current user data as a pickled data file
-rw-r--r--main/views.py18
-rw-r--r--urls.py1
2 files changed, 19 insertions, 0 deletions
diff --git a/main/views.py b/main/views.py
index c30906d..97d1ddc 100644
--- a/main/views.py
+++ b/main/views.py
@@ -17,6 +17,14 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
+from django.http import HttpResponse
+
+try:
+ import cPickle as pickle
+except ImportError:
+ import pickle
+from datetime import datetime
+
from marks.main.shared import redirect, render_page, render_template, \
get_user_data, set_user_data, reset_user_data
from marks.main.forms import AddExaminationForm, AddRatingsForm, AddMarksForm
@@ -75,3 +83,13 @@ def reset_view (request):
'''Free user data'''
reset_user_data (request)
return redirect (request, "/", "Session was successfully reset.")
+
+def export_view (request):
+ '''Export user data'''
+ user_data = get_user_data (request)
+ data = pickle.dumps (user_data)
+ response = HttpResponse (mimetype = "application/octet-stream")
+ filename = "marks-%s.dat" % datetime.now ().strftime ("%d_%m_%Y-%H_%M_%S")
+ response["Content-Disposition"] = "attachment; filename=%s" % filename
+ response.write (data)
+ return response
diff --git a/urls.py b/urls.py
index 72b3857..2c29926 100644
--- a/urls.py
+++ b/urls.py
@@ -22,4 +22,5 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^$', 'marks.main.views.home_view'),
(r'^reset$', 'marks.main.views.reset_view'),
+ (r'^export$', 'marks.main.views.export_view'),
)