Properly handle when message has disappeared

This commit is contained in:
Michal Čihař 2012-02-29 14:11:07 +01:00
parent 85c0ddb2dc
commit 6d88952df5

View File

@ -52,11 +52,14 @@ def translate(request, project, subproject, lang):
except: except:
pos = -1 pos = -1
unit = None
# Any form submitted? # Any form submitted?
if request.method == 'POST': if request.method == 'POST':
form = TranslationForm(request.POST) form = TranslationForm(request.POST)
if form.is_valid(): if form.is_valid():
obj.check_sync() obj.check_sync()
try:
unit = Unit.objects.get(checksum = form.cleaned_data['checksum'], translation = obj) unit = Unit.objects.get(checksum = form.cleaned_data['checksum'], translation = obj)
unit.target = form.cleaned_data['target'] unit.target = form.cleaned_data['target']
unit.fuzzy = form.cleaned_data['fuzzy'] unit.fuzzy = form.cleaned_data['fuzzy']
@ -64,8 +67,11 @@ def translate(request, project, subproject, lang):
# Check and save # Check and save
return HttpResponseRedirect('%s?type=%s&oldpos=%d' % (obj.get_translate_url(), rqtype, pos)) return HttpResponseRedirect('%s?type=%s&oldpos=%d' % (obj.get_translate_url(), rqtype, pos))
except Unit.DoesNotExist:
messages.add_message(request, messages.ERROR, _('Message you wanted to translate is no longer available!'))
else: # If we failed to get unit above or on no POST
if unit is None:
# What unit to show # What unit to show
if direction == 'back': if direction == 'back':
units = obj.unit_set.filter_type(rqtype).filter(position__lt = pos) units = obj.unit_set.filter_type(rqtype).filter(position__lt = pos)