Skip to content

Commit

Permalink
Issue 93 (#3)
Browse files Browse the repository at this point in the history
* Add coverage

Fixes jazzband#93 - Add 'changes_display_dict' property to 'LogEntry' model to display diff in a more human readable format

'changes_display_dict' currently handles fields with choices, long textfields and charfields, and datetime fields.
Fields with choices display in the diff with their human readable text.
Textfields and Charfields longer than 140 characters are truncated with an ellipsis appended.
Datetime fields are rendered with the format 'Aug. 21, 2017, 02:25pm'

A new kwarg was added to 'AuditlogModelRegistry' called 'mapping_fields'. The kwarg allows the user to map the
fields in the model to a more human readable or intuitive name. If a field isn't mapped it will default to the
name as defined in the model. Partial mapping is supported, all fields do not need to be mapped to use the feature.

Tests added for 'changes_display_dict'
Tests added for 'mapping_fields' property

Added python 3.5 support

Updated Documentation

Update .travis.yml to use requirements_test.txt as well in build

* Fix bug where integer fields and others would be able to be parsed by dateutil's parser and would get formatted as datetime output. Introspection is used to see if the internal field type is DateTime, Date, or Time and then try to parse it and format it appropriately. This adds functionality in that DateTime, Date and Time each now have their separate formats.
  • Loading branch information
audiolion authored Feb 20, 2017
1 parent 59913c1 commit b6fd0bc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/auditlog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,24 @@ def changes_display_dict(self):
values_display.append(choices_dict.get(value, 'None'))
else:
for value in values:
try:
value = parser.parse(value)
value = value.strftime("%b %d, %Y %I:%M %p")
except ValueError:
pass

if "DateTime" in field.get_internal_type():
try:
value = parser.parse(value)
value = value.strftime("%b %d, %Y %I:%M %p")
except ValueError:
pass
elif "Date" in field.get_internal_type():
try:
value = parser.parse(value)
value = value.strftime("%b %d, %Y")
except ValueError:
pass
elif "Time" in field.get_internal_type():
try:
value = parser.parse(value)
value = value.strftime("%I:%M %p")
except ValueError:
pass
if len(value) > 140:
value = "{}...".format(value[:140])

Expand Down

0 comments on commit b6fd0bc

Please sign in to comment.