Commit 847623d8 authored by Michal Čihař's avatar Michal Čihař

factor out change generating

parent cc4d60a2
......@@ -665,25 +665,7 @@ class Unit(models.Model):
# Generate Change object for this change
if gen_change:
if change_action is not None:
action = change_action
elif oldunit.translated:
action = Change.ACTION_CHANGE
else:
action = Change.ACTION_NEW
if self.translation.subproject.save_history:
history_target = self.target
else:
history_target = ''
# Create change object
Change.objects.create(
unit=self,
translation=self.translation,
action=action,
user=request.user,
target=history_target
)
self.generate_change(request, oldunit, change_action)
# Force commiting on completing translation
if (old_translated < self.translation.translated
......@@ -701,6 +683,32 @@ class Unit(models.Model):
return True
def generate_change(self, request, oldunit, change_action):
'''
Creates Change entry for saving unit.
'''
from trans.models.changes import Change
if change_action is not None:
action = change_action
elif oldunit.translated:
action = Change.ACTION_CHANGE
else:
action = Change.ACTION_NEW
if self.translation.subproject.save_history:
history_target = self.target
else:
history_target = ''
# Create change object
Change.objects.create(
unit=self,
translation=self.translation,
action=action,
user=request.user,
target=history_target
)
def save(self, *args, **kwargs):
'''
Wrapper around save to warn when save did not come from
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment