-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #93 - Add 'changes_display_dict' property to 'LogEntry' model to display diff in a more human readable format #94
Changes from all commits
a2f57b1
94ba93e
b80b876
23cadae
8cc8f52
1e8a7b4
fd5069e
26283fc
cf66145
609ec28
a746302
5885953
37b134a
17411f6
1aca807
6c23385
29f1431
23236ce
89e1868
0a8fdf9
61da565
8fc05e4
9893d66
6578780
591f596
26b3665
1930fb7
380e144
5fb6197
55795e1
27ae05e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
coverage==4.3.4 | ||
tox>=1.7.0 | ||
codecov>=2.0.0 | ||
django-multiselectfield==0.1.8 | ||
psycopg2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
django-jsonfield>=1.0.0 | ||
python-dateutil==2.6.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import uuid | ||
|
||
from django.contrib.postgres.fields import ArrayField | ||
from django.db import models | ||
from auditlog.models import AuditlogHistoryField | ||
from auditlog.registry import auditlog | ||
|
||
from multiselectfield import MultiSelectField | ||
|
||
|
||
@auditlog.register() | ||
class SimpleModel(models.Model): | ||
|
@@ -101,6 +104,18 @@ class SimpleExcludeModel(models.Model): | |
history = AuditlogHistoryField() | ||
|
||
|
||
class SimpleMappingModel(models.Model): | ||
""" | ||
A simple model used for register's mapping_fields kwarg | ||
""" | ||
|
||
sku = models.CharField(max_length=100) | ||
vtxt = models.CharField(verbose_name='Version', max_length=100) | ||
not_mapped = models.CharField(max_length=100) | ||
|
||
history = AuditlogHistoryField() | ||
|
||
|
||
class AdditionalDataIncludedModel(models.Model): | ||
""" | ||
A model where get_additional_data is defined which allows for logging extra | ||
|
@@ -133,6 +148,62 @@ class DateTimeFieldModel(models.Model): | |
""" | ||
label = models.CharField(max_length=100) | ||
timestamp = models.DateTimeField() | ||
date = models.DateField() | ||
time = models.TimeField() | ||
|
||
history = AuditlogHistoryField() | ||
|
||
|
||
class ChoicesFieldModel(models.Model): | ||
""" | ||
A model with a CharField restricted to a set of choices. | ||
This model is used to test the changes_display_dict method. | ||
""" | ||
RED = 'r' | ||
YELLOW = 'y' | ||
GREEN = 'g' | ||
|
||
STATUS_CHOICES = ( | ||
(RED, 'Red'), | ||
(YELLOW, 'Yellow'), | ||
(GREEN, 'Green'), | ||
) | ||
|
||
status = models.CharField(max_length=1, choices=STATUS_CHOICES) | ||
multiselect = MultiSelectField(max_length=3, choices=STATUS_CHOICES, max_choices=3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you explicitly testing with this third party library? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use this library and wanted auditlog to be compatible with it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. If this is added to the tests I would also want the built-in PostgreSQL equivalent/replacement of it (https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/fields/#arrayfield) since it is likely that people store lists that way as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I am stuck on 1.8 so using it, I will add arrayfield support though, good idea! |
||
multiplechoice = models.CharField(max_length=3, choices=STATUS_CHOICES) | ||
|
||
history = AuditlogHistoryField() | ||
|
||
|
||
class CharfieldTextfieldModel(models.Model): | ||
""" | ||
A model with a max length CharField and a Textfield. | ||
This model is used to test the changes_display_dict | ||
method's ability to truncate long text. | ||
""" | ||
|
||
longchar = models.CharField(max_length=255) | ||
longtextfield = models.TextField() | ||
|
||
history = AuditlogHistoryField() | ||
|
||
|
||
class PostgresArrayFieldModel(models.Model): | ||
""" | ||
Test auditlog with Postgres's ArrayField | ||
""" | ||
RED = 'r' | ||
YELLOW = 'y' | ||
GREEN = 'g' | ||
|
||
STATUS_CHOICES = ( | ||
(RED, 'Red'), | ||
(YELLOW, 'Yellow'), | ||
(GREEN, 'Green'), | ||
) | ||
|
||
arrayfield = ArrayField(models.CharField(max_length=1, choices=STATUS_CHOICES), size=3) | ||
|
||
history = AuditlogHistoryField() | ||
|
||
|
@@ -144,5 +215,9 @@ class DateTimeFieldModel(models.Model): | |
auditlog.register(ManyRelatedModel) | ||
auditlog.register(ManyRelatedModel.related.through) | ||
auditlog.register(SimpleExcludeModel, exclude_fields=['text']) | ||
auditlog.register(SimpleMappingModel, mapping_fields={'sku': 'Product No.'}) | ||
auditlog.register(AdditionalDataIncludedModel) | ||
auditlog.register(DateTimeFieldModel) | ||
auditlog.register(ChoicesFieldModel) | ||
auditlog.register(CharfieldTextfieldModel) | ||
auditlog.register(PostgresArrayFieldModel) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class PostgresRouter(object): | ||
""" | ||
A router to control all database operations on models for use with tests | ||
pertaining to the postgres test database. | ||
""" | ||
def db_for_read(self, model, **hints): | ||
""" | ||
Attempts to read postgres models go to postgres db. | ||
""" | ||
if model._meta.model_name.startswith('postgres'): | ||
return 'postgres' | ||
return None | ||
|
||
def db_for_write(self, model, **hints): | ||
""" | ||
Attempts to write postgres models go to postgres db. | ||
""" | ||
if model._meta.model_name.startswith('postgres'): | ||
return 'postgres' | ||
return None | ||
|
||
def allow_relation(self, obj1, obj2, **hints): | ||
""" | ||
Allow relations if a model in the postgres app is involved. | ||
""" | ||
if obj1._meta.model_name.startswith('postgres') or \ | ||
obj2._meta.model_name.startswith('postgres'): | ||
return True | ||
return None | ||
|
||
def allow_migrate(self, db, app_label, model_name=None, **hints): | ||
""" | ||
Make sure the postgres app only appears in the 'postgres db' | ||
database. | ||
""" | ||
if model_name.startswith('postgres'): | ||
return db == 'postgres' | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you inline-comment this? Than it is better understandable what it exactly does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do