Commit graph

133 commits

Author SHA1 Message Date
Keith Bussell
843495f669 Remove multi-db tests to make them more reliable
Fixes #213
2019-11-11 18:13:06 +01:00
Keith Bussell
8b84777117 Ensure db affinity between model and LogEntry
This test case would fail occasionally--sometimes accessing `history`
would try pulling from "default" instead of the "postgres" database.

To fix this issue generally, this change:
https://github.com/jjkester/django-auditlog/pull/94/files#diff-10976dd6652a7dba50d5de998672e49bR60

should be propagated somehow into `AuditlogHistoryField`.
2019-11-11 18:13:06 +01:00
Varuna Bamunusinghe
9be61a84a1 Fix tests for multiple database support. 2019-11-11 18:13:06 +01:00
Keith Bussell
3a82338e59 (feature) Allow AuditlogHistoryField to block cascading deletes (#172)
Fixes #108

Thanks to @andrewwatts for suggesting and researching the approach.
2018-03-27 14:42:36 -04:00
Jethro Muller
bc886fa01d Mark LogEntryAdminMixin methods output as safe where required (#167)
* Mark LogEntryAdminMixin method output as safe where required

Use format_html to provide conditional escaping and mark_safe functionality

* Unwrap function call to prevent py27 and py34 errors
2018-03-01 11:24:00 -05:00
Afsalms
fced0a6dd8 Corrected the issue when audit log when using django Django==2.0.1 (#166)
* Corrected the issue when audit log when using django Django==2.0.1

* Quick fix
2018-02-28 09:47:27 -05:00
Ryan Castner
d9ead64eab
Change syntax to be more terse 2018-01-11 11:18:59 -05:00
Ryan Castner
7fea1c59a1
Merge branch 'master' into bugfix/changes-display-dict-errors 2018-01-11 10:57:16 -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
AmirAli Akbari
560e2028c6 (bugfix) Fall back on actor repr when reverse url fails 2018-01-04 14:26:52 -05:00
Stephen Mc Guinness
881b7326bd (bugfix) Adds hasattr check before threadlocal.auditlog access in set_actor
middleware.set_actor was inconsistent with other methods in checking for
hasattr(threadlocal, 'auditlog')
2018-01-04 14:07:13 -05:00
sven
31db99497a (bugfix) Naive Datetimes Crashing (#107)
* Timezone naive fix
2018-01-04 13:43:23 -05:00
Denis
96f2f3d93e Fixed resource_url to work with non-id models (#147)
* Fixed resource_url to work with non-id models

* Add tests for auditlog admin
2018-01-04 11:49:39 -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
13d3eba674 Update tests to reflect testing against the localized timestamp 2018-01-02 13:13:10 -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
Chris Griffin
ee8bd9bbef
Deprecate the use of field.rel except for django 1.8 2017-06-13 15:15:27 -04:00
Jan-Jelle Kester
22997ded2f Fix import error
Issue #104
2017-02-16 22:24:24 +01:00
Stavros Korokithakis
03def6cdb3
Don't crash if the linked object is not in the admin (fixes #99) 2017-02-16 05:06:12 +02:00
Stavros Korokithakis
c127415a25
Allow register() to be called as a decorator (closes #88) 2017-02-11 05:02:22 +02:00
Jan-Jelle Kester
9bbb77bcda Merge branch 'master' into patch-1 2017-02-09 20:14:26 +01:00
Jan-Jelle Kester
d870f290f7 Merge branch 'master' into resource_url 2017-02-09 20:10:39 +01:00
Jan-Jelle Kester
e967d44bbc Merge branch 'master' into patch-1 2017-02-09 20:10:15 +01:00
Jan-Jelle Kester
2595d6ea64 Merge branch 'master' into use_tz_disabled 2017-02-09 20:06:00 +01:00
Stephen Goodman
62a0d82042 Fixed autologflush for django 1.10 2017-01-26 13:19:23 -06:00
Fernando Espíndola
e6ef7c5319 Use make_naive only if settings.USE_TZ is True. 2017-01-26 01:52:04 -02:00
Fernando Espíndola
38ec7de585 Fix the resource_url method when a model primary key is a models.UUIDField, we need to consider use the object_pk in this case. 2017-01-26 01:21:13 -02:00
Onur YALAZI
eef4a14cd3 Changed to actor's string represantation
Depending on actor's attributes is error prone, developers can extend the user model without the needed attributes.
2017-01-22 11:32:44 +02:00
Jan-Jelle Kester
210143e34c Merge branch 'master' into ticket-82-datetimefields 2017-01-21 20:15:46 +01:00
Onur YALAZI
56a9ab6ab8 LogEntryAdminMixin throws Attribute error If a user misses full_name 2017-01-18 13:40:22 +02:00
Kevin Alberts
80bd115012 Move the value retrieval process to a separate function to make the diff code more DRY. 2017-01-18 09:36:16 +01:00
Kevin Alberts
6f4c6eb8a2 Make it so Django's timezone-aware DateTimeFields remain unchanged when Django resets the timezone. DateFields are not timezone-aware, so they do not need fixing.
Django converts the timezone of DateTimeFields to UTC when the field gets saved. This makes it so when you update a model which includes a DateTimeField, and your server is running in another timezone, the AuditLog will think you changed the timestamp, while it actually is the same time, but in another timezone. This commit adds a specific check in the model_instance_diff function for DateTimeField models (and any subclasses of it), which converts the old and new values to UTC before comparing them to see if they've actually changed. It also adds tests to see if the code works properly.

The extra test_setting (USE_TZ) is added because timezone support is disabled if it is not specified, this setting enables it.
2017-01-11 20:07:10 +01:00
Kevin Alberts
1c28dbb0d6 Updated LogEntryAdmin to use first_name and last_name fields instead of full_name from the actor 2017-01-11 00:12:54 +01:00
Kevin Alberts
f498f740ee Updated LogEntryAdminMixin to use get_full_name() method from Django Auth.User model 2017-01-10 16:55:06 +01:00
isszul
25ca523301 implemented suggested fix in #72 2016-11-02 13:30:05 +00:00
Rob Guttman
20eb91359a enhanced admin interface closes #1 2016-09-02 15:02:42 -04:00
Jan-Jelle Kester
7824fb27f1 Update middleware for Django 1.10 2016-08-17 22:45:02 +02:00
Nitesh Rijal
3aeab92b35 added admin filter by content_types 2016-08-16 18:58:06 +05:45
Nitesh Rijal
022ba4c730 added a simple admin interface for audit log entries 2016-08-16 08:23:36 +05:45
Jan-Jelle Kester
2d9fab421e Merge branch 'master' into flush-command 2016-08-02 17:32:31 +02:00
Jan-Jelle Kester
889cb16c64 Merge branch 'master' into migration-magic 2016-08-02 17:26:48 +02:00
Jan-Jelle Kester
81bcd47ab0 Add management command for deleting all log entries
Issue #57
2016-07-27 18:17:59 +02:00
Jan-Jelle Kester
eb0574d115 Change existing migration to fix issues for MySQL users
Issue #54
2016-07-27 17:32:19 +02:00