Courses have a manytoone relation to schools.
"""
import datetime
+import reversion
from django.db import models
from django.utils.text import slugify
""" 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
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. """
""" Views for the KarmaNotes Courses app """
import json
+import reversion
from django.core import serializers
from django.core.exceptions import MultipleObjectsReturned
"""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
}
},
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