From b8f67d32d86f28a71a580da09ce5d639a9ff51a5 Mon Sep 17 00:00:00 2001 From: Jacob Hilker Date: Sat, 1 Feb 2014 19:03:13 -0500 Subject: [PATCH] add reversion --- karmaworld/apps/courses/models.py | 4 ++++ karmaworld/apps/courses/views.py | 2 ++ karmaworld/assets/js/course-detail.js | 8 +++++++- karmaworld/settings/common.py | 3 +++ reqs/common.txt | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index 7f12342..78761a8 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -9,6 +9,7 @@ Courses have a manytoone relation to schools. """ import datetime +import reversion from django.db import models from django.utils.text import slugify @@ -248,6 +249,7 @@ class Course(models.Model): """ return url based on school slug and self slug """ return u"/{0}/{1}".format(self.school.slug, self.slug) + @reversion.create_revision() def save(self, *args, **kwargs): """ Save school and generate a slug if one doesn't exist """ super(Course, self).save(*args, **kwargs) # generate a self.id @@ -263,11 +265,13 @@ class Course(models.Model): def autocomplete_search_fields(): return ("name__icontains",) + @reversion.create_revision() def update_note_count(self): """ Update self.file_count by summing the note_set """ self.file_count = self.note_set.count() self.save() +reversion.register(Course) class ProfessorTaughtManager(models.Manager): """ Handle restoring data. """ diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index 714047c..0e91be5 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -4,6 +4,7 @@ """ Views for the KarmaNotes Courses app """ import json +import reversion from django.core import serializers from django.core.exceptions import MultipleObjectsReturned @@ -201,6 +202,7 @@ def flag_course(request, pk): """Record that somebody has flagged a note.""" return ajax_increment(Course, request, pk, FLAG_FIELD, process_course_flag_events) +@reversion.create_revision() def edit_course(request, pk): """ Saves the edited course content diff --git a/karmaworld/assets/js/course-detail.js b/karmaworld/assets/js/course-detail.js index 9c1d089..342338c 100644 --- a/karmaworld/assets/js/course-detail.js +++ b/karmaworld/assets/js/course-detail.js @@ -49,7 +49,13 @@ $(function() { } }, error: function(resp) { - var json = JSON.parse(resp.responseText); + var json; + try { + json = JSON.parse(resp.responseText); + } catch(e) { + json = { message: 'Unknown Error' }; + } + var errors = json.errors; // Delete all errors that currently exist diff --git a/karmaworld/settings/common.py b/karmaworld/settings/common.py index ba16684..af0271e 100644 --- a/karmaworld/settings/common.py +++ b/karmaworld/settings/common.py @@ -227,6 +227,9 @@ THIRD_PARTY_APPS = ( # Tagging https://github.com/yedpodtrzitko/django-taggit 'taggit', + # Version control + 'reversion', + 'allauth', 'allauth.account', 'allauth.socialaccount', diff --git a/reqs/common.txt b/reqs/common.txt index f2715e7..24cc7b2 100644 --- a/reqs/common.txt +++ b/reqs/common.txt @@ -21,3 +21,4 @@ html2text django-allauth boto==2.6.0 django-storages==1.1.4 +reversion -- 2.25.1