Skip to content

Commit 1c4f31c

Browse files
committed
Resolve conflicts after merge with master
2 parents 3179eaf + 8a1a23e commit 1c4f31c

File tree

19 files changed

+300
-62
lines changed

19 files changed

+300
-62
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ python:
77
- 3.3
88
- 3.4
99
- 3.5
10+
- 3.6
1011

1112
env:
1213
- DJANGO="Django>=1.6,<1.7"
1314
- DJANGO="Django>=1.7,<1.8"
1415
- DJANGO="Django>=1.8,<1.9"
1516
- DJANGO="Django>=1.9,<1.10"
1617
- DJANGO="Django>=1.10,<1.11"
18+
- DJANGO="Django>=1.11,<1.12"
1719

1820
install:
1921
- pip install -U coverage codecov
@@ -30,9 +32,15 @@ matrix:
3032
env: DJANGO="Django>=1.6,<1.7"
3133
- python: 3.5
3234
env: DJANGO="Django>=1.7,<1.8"
35+
- python: 3.6
36+
env: DJANGO="Django>=1.6,<1.7"
37+
- python: 3.6
38+
env: DJANGO="Django>=1.7,<1.8"
3339
- python: 3.3
3440
env: DJANGO="Django>=1.9,<1.10"
3541
- python: 3.3
3642
env: DJANGO="Django>=1.10,<1.11"
43+
- python: 3.3
44+
env: DJANGO="Django>=1.11,<1.12"
3745

3846
after_success: codecov

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Authors
1010
- Daniel Levy
1111
- Daniel Roschka
1212
- David Hite
13+
- Eduardo Cuducos
1314
- George Vilches
1415
- Grzegorz Bialy
1516
- Hamish Downer
@@ -22,6 +23,7 @@ Authors
2223
- Jonathan Sanchez
2324
- Josh Fyne
2425
- Klaas van Schelven
26+
- Maciej "RooTer" Urbański
2527
- Martin Bachwerk
2628
- Marty Alchin
2729
- Mauricio de Abreu Antunes

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tip (unreleased)
5151
- Fix a bug when models have a ``ForeignKey`` with ``primary_key=True``
5252
- Do NOT delete the history elements when a user is deleted.
5353
- Add support for ``latest``
54+
- Allow setting a reason for change. [using option changeReason]
5455

5556
1.5.3 (2014-11-18)
5657
------------------

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ include MANIFEST.in
22
include *.rst
33
include *.txt
44
recursive-include docs *.rst
5+
recursive-include simple_history/locale *
56
recursive-include simple_history/templates *

docs/advanced.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,43 @@ And you don't want to stored the changes for the field ``pub_date``, it is neces
239239
history = HistoricalRecords(excluded_fields=['pub_date'])
240240
241241
By default, django-simple-history stores the changes for all fields in the model.
242+
243+
Change Reason
244+
-------------
245+
246+
Change reason is a message to explain why the change was made in the instance. It is stored in the
247+
field ``history_change_reason`` and its default value is ``None``.
248+
249+
By default, the django-simple-history gets the change reason in the field ``changeReason`` of the instance. Also, is possible to pass
250+
the ``changeReason`` explicitly. For this, after a save or delete in an instance, is necessary call the
251+
function ``utils.update_change_reason``. The first argument of this function is the instance and the seccond
252+
is the message that represents the change reason.
253+
254+
For instance, for the model:
255+
256+
.. code-block:: python
257+
258+
from django.db import models
259+
from simple_history.models import HistoricalRecords
260+
261+
class Poll(models.Model):
262+
question = models.CharField(max_length=200)
263+
history = HistoricalRecords()
264+
265+
You can create a instance with a implicity change reason.
266+
267+
.. code-block:: python
268+
269+
poll = Poll(question='Question 1')
270+
poll.changeReason = 'Add a question'
271+
poll.save()
272+
273+
Or you can pass the change reason explicitly:
274+
275+
.. code-block:: python
276+
277+
from simple_history.utils import update_change_reason
278+
279+
poll = Poll(question='Question 1')
280+
poll.save()
281+
update_change_reason(poll, 'Add a question')

runtests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
]
2828

2929
DEFAULT_SETTINGS = dict(
30+
ALLOWED_HOSTS=['localhost'],
3031
AUTH_USER_MODEL='custom_user.CustomUser',
3132
ROOT_URLCONF='simple_history.tests.urls',
3233
MEDIA_ROOT=media_root,
@@ -45,6 +46,11 @@
4546
TEMPLATES=[{
4647
'BACKEND': 'django.template.backends.django.DjangoTemplates',
4748
'APP_DIRS': True,
49+
'OPTIONS': {
50+
'context_processors': [
51+
'django.contrib.auth.context_processors.auth',
52+
]
53+
},
4854
}],
4955
)
5056

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
'Programming Language :: Python :: 3.2',
3131
'Programming Language :: Python :: 3.3',
3232
'Programming Language :: Python :: 3.4',
33+
'Programming Language :: Python :: 3.5',
34+
'Programming Language :: Python :: 3.6',
3335
"License :: OSI Approved :: BSD License",
3436
],
3537
tests_require=tests_require,
Binary file not shown.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the PACKAGE package.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: \n"
9+
"Report-Msgid-Bugs-To: \n"
10+
"POT-Creation-Date: 2017-06-01 11:02-0300\n"
11+
"PO-Revision-Date: 2017-06-01 11:06-0300\n"
12+
"Language: pt_BR\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: 8bit\n"
16+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
17+
"Last-Translator: \n"
18+
"Language-Team: \n"
19+
"X-Generator: Poedit 1.8.11\n"
20+
21+
#: simple_history/admin.py:73
22+
#, python-format
23+
msgid "Change history: %s"
24+
msgstr "Histórico de modificações: %s"
25+
26+
#: simple_history/admin.py:92
27+
#, python-format
28+
msgid "The %(name)s \"%(obj)s\" was changed successfully."
29+
msgstr "%(name)s \"%(obj)s\" modificados com sucesso."
30+
31+
#: simple_history/admin.py:98
32+
msgid "You may edit it again below"
33+
msgstr "Você pode fazer novas modificações abaixo:"
34+
35+
#: simple_history/admin.py:156
36+
#, python-format
37+
msgid "Revert %s"
38+
msgstr "Reverter %s"
39+
40+
#: simple_history/templates/simple_history/object_history.html:10
41+
msgid ""
42+
"Choose a date from the list below to revert to a previous version of this "
43+
"object."
44+
msgstr ""
45+
"Escolha a data desejada na lista a seguir para reverter as modificações "
46+
"feitas nesse objeto."
47+
48+
#: simple_history/templates/simple_history/object_history.html:17
49+
msgid "Object"
50+
msgstr "Objeto"
51+
52+
#: simple_history/templates/simple_history/object_history.html:18
53+
msgid "Date/time"
54+
msgstr "Data/hora"
55+
56+
#: simple_history/templates/simple_history/object_history.html:19
57+
msgid "Comment"
58+
msgstr "Comentário"
59+
60+
#: simple_history/templates/simple_history/object_history.html:20
61+
msgid "Changed by"
62+
msgstr "Modificado por"
63+
64+
#: simple_history/templates/simple_history/object_history.html:46
65+
msgid "This object doesn't have a change history."
66+
msgstr "Esse objeto não tem um histórico de modificações."
67+
68+
#: simple_history/templates/simple_history/object_history_form.html:7
69+
msgid "Home"
70+
msgstr "Início"
71+
72+
#: simple_history/templates/simple_history/object_history_form.html:11
73+
msgid "History"
74+
msgstr "Histórico"
75+
76+
#: simple_history/templates/simple_history/object_history_form.html:12
77+
#, python-format
78+
msgid "Revert %(verbose_name)s"
79+
msgstr "Reverter %(verbose_name)s"
80+
81+
#: simple_history/templates/simple_history/object_history_form.html:21
82+
msgid ""
83+
"Press the 'Revert' button below to revert to this version of the object."
84+
msgstr ""
85+
"Clique em 'Reverter' para reverter as modificações feitas nesse objeto."
86+
87+
#: simple_history/templates/simple_history/object_history_form.html:21
88+
msgid "Or press the 'Change History' button to edit the history."
89+
msgstr ""
90+
"Ou clique em 'Histórico de Modificações' para modificar o histórico."
91+
92+
#: simple_history/templates/simple_history/submit_line.html:3
93+
msgid "Revert"
94+
msgstr "Reverter"
95+
96+
#: simple_history/templates/simple_history/submit_line.html:4
97+
msgid "Change History"
98+
msgstr "Histórico de Modificações"

simple_history/models.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
import importlib
55
import threading
66

7-
from django.db import models, router
8-
from django.db.models.fields.proxy import OrderWrt
97
from django.conf import settings
108
from django.contrib import admin
9+
from django.db import models, router
10+
from django.db.models.fields.proxy import OrderWrt
1111
from django.utils import six
12-
from django.utils.encoding import python_2_unicode_compatible
13-
from django.utils.encoding import smart_text
12+
from django.utils.encoding import python_2_unicode_compatible, smart_text
1413
from django.utils.timezone import now
15-
from django.utils.translation import string_concat
14+
from django.utils.translation import string_concat, ugettext as _
15+
16+
from . import exceptions
17+
from .manager import HistoryDescriptor
1618

1719
try:
1820
from django.apps import apps
@@ -26,8 +28,6 @@
2628
add_introspection_rules(
2729
[], ["^simple_history.models.CustomForeignKeyField"])
2830

29-
from . import exceptions
30-
from .manager import HistoryDescriptor
3131

3232
registered_models = {}
3333

@@ -213,13 +213,15 @@ def get_instance(self):
213213
return {
214214
'history_id': models.AutoField(primary_key=True),
215215
'history_date': models.DateTimeField(),
216+
'history_change_reason': models.CharField(max_length=100,
217+
null=True),
216218
'history_user': models.ForeignKey(
217219
user_model, null=True, related_name=self.user_related_name,
218220
on_delete=models.SET_NULL),
219221
'history_type': models.CharField(max_length=1, choices=(
220-
('+', 'Created'),
221-
('~', 'Changed'),
222-
('-', 'Deleted'),
222+
('+', _('Created')),
223+
('~', _('Changed')),
224+
('-', _('Deleted')),
223225
)),
224226
'history_object': HistoricalObjectDescriptor(model, self.fields_included(model)),
225227
'instance': property(get_instance),
@@ -258,12 +260,14 @@ def post_delete(self, instance, **kwargs):
258260
def create_historical_record(self, instance, history_type):
259261
history_date = getattr(instance, '_history_date', now())
260262
history_user = self.get_history_user(instance)
263+
history_change_reason = getattr(instance, 'changeReason', None)
261264
manager = getattr(instance, self.manager_name)
262265
attrs = {}
263266
for field in self.fields_included(instance):
264267
attrs[field.attname] = getattr(instance, field.attname)
265268
manager.create(history_date=history_date, history_type=history_type,
266-
history_user=history_user, **attrs)
269+
history_user=history_user,
270+
history_change_reason=history_change_reason, **attrs)
267271

268272
def get_history_user(self, instance):
269273
"""Get the modifying user from instance or middleware."""

0 commit comments

Comments
 (0)