Commit graph

56 commits

Author SHA1 Message Date
Ryan Castner
d9ead64eab
Change syntax to be more terse 2018-01-11 11:18:59 -05:00
Ryan Castner
e22c2f7d6b Fix crash when verbose_name is not defined on a model and field is not defined in mapping_fields. Defaults to field.name as a fallback 2018-01-11 10:56:31 -05:00
Ryan Castner
f6ade2078b
Merge branch 'master' into bugfix/changes-display-dict-errors 2018-01-04 09:14:55 -05:00
Rod Manning
4dee03497c Add Django 2.0 Support (#154)
* Add changes for django 2.0

Made the following changes to ensure compatibility with django 2.0:

1. Replaced function calls to `is_authenticated()` with reference to
   property `is_authenticated`.

2. Added try/except call to import `django.core.urlresolvers` (now
   called `django.urls`.

   Also added an `... as ...` statement to ensure that references in the
   code to `urlresolvers` don't need to be changed.

3. Fixed calls statement of `on_delete` arg to all ForeignKey
   fields.

   Note that previously a kwarg was acceptable, but this is now a
   positional arg, and the selected `on_delete` method has been
   retained.

* Update tox tests and consequentual changes

Updated tox.ini to also test django 2.0 on python 3+. Some changes made
to previous commits required to ensure all tests passed:

- Added `compat.py` to have a `is_authenticated()` function to check
  authentication.

  This was necessary as the property/method call for `is_authenticated`
  is no compatible between django 1.8 (LTS) and 2.0.

  Changed AuditLogMiddleware to call this compatibility function instead
  of the django built-ins as a result.

- Changes made to `auditlog/models.py` to apply kwargs to both `to=` and
  `on_delete=` for consistency of handling in all version tested.

Incorrect django version specified for tox.ini. Now fixed.

* Add 'on_delete' kwarg to initial migration

Added and re-arranged 'on_delete' and 'to' kwargs in initial migration
to ensure compatbility with later versions of Django.

Also included updated manifest with changes required due to django 2.0
work.

* Add TestCase for compat.py

Added simple test case for compat.py file.

* Changes follow code review 2017-12-21

* More changes following code review 2017-12-28

1. Added detailed commentary to `compat.py` to ensure reason why
   `is_authenticated()` compatibility function is needed

2. Changed `hasattr` to `callable` in compat.is_authenticated()

3. Fixed typo in migration 0001 to use correct `on_delete` function
2018-01-02 13:50:45 -05:00
Ryan Castner
76a4ea0f95 Fix issue where base_field.choices has options but we short circuit on an empty field.choices 2018-01-02 13:12:44 -05:00
Ryan Castner
a94ca4d5fd Use django's timezone to provide utc tzinfo 2018-01-02 12:34:52 -05:00
Ryan Castner
6cb9a27dca Exclude fields with no internal type, e.g. relationships like foreign keys and reverse foreign keys, from the changes_display_dict output. 2018-01-02 12:28:37 -05:00
Ryan Castner
a98bf9d7a5 The previous conditional did not work as expected, when field.choices returns an empty dict the boolean is False and the operator does not shortcircuit as expected. This causes field.base_field.choices to be evaluated which crashes as it does not exist and field.choices was supposed to be the input. The updated version fixes this bug. 2018-01-02 12:28:02 -05:00
Ryan Castner
2105366379 Datetimes are stored without tzinfo, but as UTC. changes_display_dict now adds in UTC tzinfo then casts DateTimes to the server's settings.TIME_ZONE. 2018-01-02 12:24:49 -05:00
Ryan Castner
45760c6316 Fixes #93 - Add 'changes_display_dict' property to 'LogEntry' model to display diff in a more human readable format (#94)
Fixes #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, datefields, timefields, and datetimefields. Supports `django-multiselectfield` with choices and Postgres's ArrayField with choices.

Textfields and Charfields longer than 140 characters are truncated with an ellipsis appended.
Date, Time and DateTime fields are rendered according to `L10N`, or if turned off fall back on Django settings defaults for DATE_FORMAT, TIME_FORMAT and DATETIME_FORMAT.

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 `verbose_name` as defined on the model or the Django default `verbose_name`. Partial mapping is supported, all fields do not need to be mapped to use the feature.

* Add django-multiselectfield test dep

* Add psycopg2 test dep

* Add postgres testing database and router

* Add postgres support to travis builds

* Add support for multiple databases. LogEntry saves to same database of the model its associated to

* If any literal evals fail default to None

* Add support for Postgres ArrayField in changes_display_dict

* Revert to old travis image while they are fixing issues with it

* Update docs

* Add full test coverage
2017-09-13 10:57:47 -04:00
Grant McConnaughey
cf190fce7a Support models with UUID primary keys (#111)
Fixes #110 to add support for UUID primary keys in related many to many querysets in the `get_for_objects()` method.

Forces queryset evaluation in `get_for_objects()` to cache the queryset, reducing additional db queries.
2017-06-29 10:19:33 -04:00
Jan-Jelle Kester
65ae0e6705 Upgrade django-jsonfield dependency 2016-07-27 17:27:48 +02:00
Jan-Jelle Kester
091dccf6a7 Proposed fix for issue #45 2016-01-23 22:38:02 +01:00
Jan-Jelle Kester
7524801bb7 Remove unwanted blank line 2016-01-23 21:13:43 +01:00
Justin Littman
16a8b158e0 Change get_for_objects to distinguish between number and text keys. 2016-01-05 11:59:43 -05:00
Scott Adams
26237a9863 Code nazi told me to put db_index=True at the front of the queue 2015-10-19 04:24:12 +02:00
Scott Adams
c4ed32b89b Add db_index=True to object_pk 2015-10-18 03:17:41 +02:00
jay7958
59fc9eff18 Changed import statement and reference to GenericRelation in order
to remove the following Django Warning:
site-packages/auditlog/models.py:6: RemovedInDjango19Warning:
  django.contrib.contenttypes.generic is deprecated and will be
  removed in Django 1.9. Its contents have been moved to the
  fields, forms, and admin submodules of
  django.contrib.contenttypes.
    from django.contrib.contenttypes import generic
2015-08-20 12:53:59 -05:00
Jan-Jelle Kester
dab0342cf6 Merge branch 'master' into release-0.3.0
Conflicts:
	src/auditlog/diff.py
2015-07-22 01:06:32 +02:00
Jan-Jelle Kester
ef4b93a551 Merge pull request #29 from jjkester/threadlocals
Use threadlocals and log remote address
2015-07-21 23:50:40 +02:00
Jan-Jelle Kester
952536f255 Additional field for metadata 2015-07-21 23:46:31 +02:00
Ann Paul
23927ea317 Add verbose name to the additional_data field
Directly call the get_additional_data method without instance
2015-06-03 08:47:50 -07:00
Jan-Jelle Kester
0c0d1dffe1 Only set remote_addr in set_actor method 2015-06-03 16:49:04 +02:00
Jan-Jelle Kester
93e468ab03 Add remote address field to LogEntry and autopopulate it when possible 2015-06-03 16:45:51 +02:00
Ann Paul
72cdde6864 Change naming to use additional_data 2015-06-01 09:24:13 -07:00
Jan-Jelle Kester
ff09a69c6f Improve documentation 2015-05-31 15:06:06 +02:00
Jan-Jelle Kester
1173d3bc91 Fix issue with possible duplicates in get_for_objects method 2015-05-31 13:52:29 +02:00
Jan-Jelle Kester
3623812ab4 Some work on m2m relationships 2015-05-15 15:14:57 +02:00
Jan-Jelle Kester
3b04d88441 Improve code documentation 2015-05-15 01:25:44 +02:00
Jan-Jelle Kester
ae8461d1fe Merge pull request #22 from jjkester/python3
Support Python 3 as well as Python 2
2015-05-15 00:30:47 +02:00
Jan-Jelle Kester
f54623d3c1 Merge pull request #14 from johnrtipton/master
Compatibility with django-polymorphic
2015-04-29 12:06:37 +02:00
Ann Paul
6a7908f2ca Add detailed_object_repr JSONField to logentry model 2015-04-23 15:02:58 -07:00
John R. Tipton
cc2e489f75 - Check for model using isinstance
- Check for model using isinstance and pk using _get_pk_value
2015-02-19 09:03:39 -05:00
Jan-Jelle Kester
e97c601038 First try at making Auditlog work with Python 3
Issue #15
2015-02-16 22:17:22 +01:00
Jan-Jelle Kester
bee1f08f58 Support both int and long types for numeric primary keys
Issue #10
2015-02-16 21:46:35 +01:00
Jan-Jelle Kester
eb50f0dffd Fix value lookup for nonexistent relations 2015-02-16 17:06:17 +01:00
Jan-Jelle Kester
71ba81928b Merge branch 'master' of https://github.com/jjkester/django-auditlog 2015-02-16 16:34:35 +01:00
Jan-Jelle Kester
978e50fc35 Fix South compatibility for AuditlogHistoryField 2015-02-16 16:34:22 +01:00
John R. Tipton
16a55e1924 - Compatibility with django-polymorphic
Check for _meta attribute instead of __class__, since an integer has an
__class__ attribute.
2015-02-13 09:23:23 -05:00
John R. Tipton
dc9d6739fe - Compatibility with django-polymorphic
django-polymorphic self._get_pk_value returns the class object.  If
this happens, we try adding _id to the pk_field.
2015-02-12 15:54:59 -05:00
Vittorio Zamboni
4ae09eb8b4 Changed registry from list to dictionary and use register kwargs to track fields that must be changed or excluded 2014-10-03 15:13:03 +02:00
Jan-Jelle Kester
d778bb3a9e Add South compatibility for AuditlogHistoryField
Untested, suggested solution per issue #7
2014-07-08 15:57:45 +02:00
Jan-Jelle Kester
41d3948606 Progress with tests 2014-03-14 17:15:31 +01:00
Jan-Jelle Kester
a2f4c98fa1 Add some documentation 2013-12-18 17:27:11 +01:00
Jan-Jelle Kester
2bcc022fdf Fix utility methods with dynamic primary key discovery, also some style fixes 2013-12-18 17:24:41 +01:00
Jan-Jelle Kester
1bde6de50a Extra utility methods on LogEntryManager with correct terminology, small style fix 2013-12-18 17:17:38 +01:00
Jan-Jelle Kester
f5aed059bf Add changes_dict and changes_str utility methods to LogEntry model 2013-12-11 17:14:07 +01:00
Jan-Jelle Kester
8c541fe416 Remove html_formated_string method on LogEntry model
The method name was incorrectly spelled and the method was not flexible enough. This functionality will be replaced by a more flexible method and/or a template tag.
2013-12-11 16:58:32 +01:00
Jan-Jelle Kester
ec051d11f0 Merge remote-tracking branch 'origin/master'
Conflicts:
	src/auditlog/middleware.py
2013-12-11 16:55:05 +01:00
Francisco Pérez Ferrer
19291f54d9 some util functions 2013-11-27 23:04:49 -05:00