diff --git a/RIGS/importer.py b/RIGS/importer.py index 05dbbb14..34af1c57 100644 --- a/RIGS/importer.py +++ b/RIGS/importer.py @@ -7,7 +7,9 @@ django.setup() from django.db import connections from django.core.exceptions import ObjectDoesNotExist from django.db.utils import ConnectionDoesNotExist +from django.db import transaction from RIGS import models +import reversion def setup_cursor(): try: @@ -40,6 +42,8 @@ def import_people(): person, created = models.Person.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], email=email, address=row[4], notes=notes) if created: print("Created: " + person.__unicode__()) + with transaction.atomic(), reversion.create_revision(): + person.save() else: print("Found: " + person.__unicode__()) diff --git a/RIGS/models.py b/RIGS/models.py index 3a08fcf1..35380888 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -16,8 +16,20 @@ class Profile(AbstractUser): url = "https://www.gravatar.com/avatar/" + hashlib.md5(self.email).hexdigest() + "?d=identicon&s=500" return url +class RevisionMixin(object): + @property + def last_edited_at(self): + version = reversion.get_for_object(self)[0] + return version.revision.date_created + + @property + def last_edited_by(self): + version = reversion.get_for_object(self)[0] + return version.revision.user + + @reversion.register -class Person(models.Model): +class Person(models.Model, RevisionMixin): name = models.CharField(max_length=50) phone = models.CharField(max_length=15, blank=True, null=True) email = models.EmailField(blank=True, null=True) @@ -30,4 +42,5 @@ class Person(models.Model): string = self.name if len(self.notes) > 0: string += "*" - return string \ No newline at end of file + return string + diff --git a/RIGS/templates/RIGS/person_detail.html b/RIGS/templates/RIGS/person_detail.html index 5e80cd98..0b2007ef 100644 --- a/RIGS/templates/RIGS/person_detail.html +++ b/RIGS/templates/RIGS/person_detail.html @@ -7,7 +7,6 @@