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 @@
{% if not request.is_ajax %}

{{ object.name }}

-
Edit @@ -38,9 +37,16 @@ {% if request.is_ajax %} {% block footer %} -
- Edit +
+
+ Lasted edited at {{ object.last_edited_at|date:"SHORT_DATE_FORMAT" }} by {{ user }} +
+
+
+ Edit +
+
{% endblock %} {% endif %} \ No newline at end of file diff --git a/RIGS/templatetags/filters.py b/RIGS/templatetags/filters.py index f679d35f..fe1f80cc 100644 --- a/RIGS/templatetags/filters.py +++ b/RIGS/templatetags/filters.py @@ -59,5 +59,4 @@ def paginator(context, adjacent_pages=3): dict['previous'] = page.previous_page_number() return dict - register.inclusion_tag('pagination.html', takes_context=True)(paginator) \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index 1d8517ae..d228b02b 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ