Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if unit.state == STATE_FUZZY and unit.previous_source == self.source:
# Unset fuzzy on reverted
unit.state = STATE_TRANSLATED
unit.previous_source = ''
elif unit.state >= STATE_TRANSLATED:
# Set fuzzy on changed
unit.state = STATE_FUZZY
unit.previous_source = previous_source
unit.original_state = unit.state
# Update source index and stats
unit.update_has_comment()
unit.update_has_suggestion()
unit.save()
Fulltext.update_index_unit(unit)
Change.objects.create(
unit=unit,
action=Change.ACTION_SOURCE_CHANGE,
user=user,
author=author,
old=previous_source,
target=self.source,
)
unit.translation.invalidate_cache()
def git_commit(self, user, author, timestamp, skip_push=False, signals=True):
"""Wrapper for committing translation to git."""
repository = self.component.repository
with repository.lock:
# Is there something for commit?
if not self.repo_needs_commit():
return False
# Do actual commit with git lock
self.log_info('committing %s as %s', self.filenames, author)
Change.objects.create(
action=Change.ACTION_COMMIT, translation=self, user=user
)
self.__git_commit(author, timestamp, signals=signals)
# Push if we should
if not skip_push:
self.component.push_if_needed()
return True
def new_unit(self, request, key, value):
with self.component.repository.lock:
self.commit_pending('new unit', request.user)
Change.objects.create(
translation=self,
action=Change.ACTION_NEW_UNIT,
target=value,
user=request.user,
author=request.user,
)
self.store.new_unit(key, value)
self.component.create_translations(request=request)
self.__git_commit(request.user.get_author_name(), timezone.now())
self.component.push_if_needed()
target=error,
user=request.user if request else None,
details={"error": error, "status": status},
)
self.add_alert("MergeFailure", error=error)
# Reset repo back
method_func(abort=True)
# Tell user (if there is any)
messages.error(request, error_msg % force_text(self))
return False
if self.id:
Change.objects.create(
component=self,
action=action,
user=request.user if request else None,
)
# Run post update hook, this should be done with repo lock held
# to avoid posssible race with another update
vcs_post_update.send(
sender=self.__class__, component=self, previous_head=previous_head
)
self.delete_alert("MergeFailure")
self.delete_alert("RepositoryOutdated")
for component in self.linked_childs:
vcs_post_update.send(
sender=component.__class__,
component=component,
def generate_change(self, user, author, change_action):
"""Create Change entry for saving unit."""
# Notify about new contributor
user_changes = Change.objects.filter(translation=self.translation, user=user)
if not user_changes.exists():
Change.objects.create(
unit=self,
action=Change.ACTION_NEW_CONTRIBUTOR,
user=user,
author=author,
)
# Action type to store
if change_action is not None:
action = change_action
elif self.state == STATE_FUZZY:
action = Change.ACTION_MARKED_EDIT
elif self.old_unit.state >= STATE_TRANSLATED:
if self.state == STATE_APPROVED:
action = Change.ACTION_APPROVE
else:
action = Change.ACTION_CHANGE
"%s remote into repo %s..%s",
method,
previous_head,
self.repository.last_revision,
)
except RepositoryException as error:
# Report error
report_error(error, prefix="Failed {}".format(method))
# In case merge has failer recover
error = self.error_text(error)
status = self.repository.status()
# Log error
if self.id:
Change.objects.create(
component=self,
action=action_failed,
target=error,
user=request.user if request else None,
details={"error": error, "status": status},
)
self.add_alert("MergeFailure", error=error)
# Reset repo back
method_func(abort=True)
# Tell user (if there is any)
messages.error(request, error_msg % force_text(self))
return False
same.add_vote(unit.translation, request, Vote.POSITIVE)
return False
# Create the suggestion
suggestion = self.create(
target=target,
unit=unit,
user=user,
userdetails={
'address': get_ip_address(request) if request else '',
'agent': request.META.get('HTTP_USER_AGENT', '') if request else '',
},
)
# Record in change
Change.objects.create(
unit=unit,
suggestion=suggestion,
action=Change.ACTION_SUGGESTION,
user=user,
target=target,
author=user,
)
# Add unit vote
if vote:
suggestion.add_vote(unit.translation, request, Vote.POSITIVE)
# Update suggestion stats
if user is not None:
user.profile.suggested += 1
user.profile.save()