Skip to content

Commit

Permalink
Edit: Get unit early
Browse files Browse the repository at this point in the history
This also avoids getting unit twice when using checksum.

Issue #49
  • Loading branch information
nijel committed Jul 28, 2020
1 parent 138d10a commit 84effb6
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions weblate/trans/views/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,22 @@ def translate(request, project, component, lang):
except (Unit.DoesNotExist, ValueError):
messages.warning(request, _("No string matched your search!"))
return redirect(translation)
else:
# Check boundaries
if not 0 < offset <= num_results:
messages.info(request, _("The translation has come to an end."))
# Delete search
del request.session[search_result["key"]]
# Redirect to translation
return redirect(translation)

# Check boundaries
if not 0 < offset <= num_results:
messages.info(request, _("The translation has come to an end."))
# Delete search
del request.session[search_result["key"]]
# Redirect to translation
return redirect(translation)
# Grab actual unit
try:
unit = translation.unit_set.get(pk=search_result["ids"][offset - 1])
except Unit.DoesNotExist:
# Can happen when using SID for other translation
messages.error(request, _("Invalid search string!"))
return redirect(translation)

# Some URLs we will most likely use
base_unit_url = "{0}?{1}&offset=".format(
Expand Down Expand Up @@ -476,14 +484,6 @@ def translate(request, project, component, lang):
if response is not None:
return response

# Grab actual unit
try:
unit = translation.unit_set.get(pk=search_result["ids"][offset - 1])
except Unit.DoesNotExist:
# Can happen when using SID for other translation
messages.error(request, _("Invalid search string!"))
return redirect(translation)

# Show secondary languages for signed in users
if request.user.is_authenticated:
secondary = unit.get_secondary_units(request.user)
Expand Down

0 comments on commit 84effb6

Please sign in to comment.