Skip to content

Commit

Permalink
Merge pull request #1334 from Signbank/error_reporting
Browse files Browse the repository at this point in the history
#1330: Report constraint error as alert to user, not as message
  • Loading branch information
susanodd authored Oct 11, 2024
2 parents 1274443 + d2ad70e commit ed950dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion media/js/gloss_edit_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ function configure_edit() {
$('.edit_area').editable(edit_post_url, {
params : { a: 0 },
type : 'textarea',
callback : update_view_and_remember_original_value
callback : update_view_and_remember_original_value,
onerror : function(settings, original, xhr){
alert(xhr.responseText);
original.reset();
},
});
// edit_role needs a new/different edit_post_url
$('.edit_role').editable(edit_post_url, {
Expand Down
8 changes: 4 additions & 4 deletions signbank/dictionary/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3445,10 +3445,10 @@ def save(self, *args, **kwargs):
annotationidglosstranslation__language=self.language,
lemma__dataset=dataset)
if not (
(len(glosses_with_same_text) == 1 and glosses_with_same_text[0] == self)
or glosses_with_same_text is None or len(glosses_with_same_text) == 0):
msg = "The annotation idgloss translation text '%s' is not unique within dataset '%s' for gloss '%s'." \
% (self.text, dataset.acronym, self.gloss.id)
(glosses_with_same_text.count() == 1 and glosses_with_same_text.first() == self)
or glosses_with_same_text is None or glosses_with_same_text.count() == 0):
gloss_with_same_text = glosses_with_same_text.first()
msg = f"The annotation idgloss translation text '{self.text}' is not unique within dataset '{dataset.acronym}' for gloss '{self.gloss.id}'. Gloss {gloss_with_same_text.id} also has this text."
raise ValidationError(msg)

super(AnnotationIdglossTranslation, self).save(*args, **kwargs)
Expand Down
4 changes: 1 addition & 3 deletions signbank/dictionary/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,7 @@ def update_annotation_idgloss(request, gloss, field, value):
annotation_idgloss_translation.save()
except ValidationError as e:
feedback_message = getattr(e, 'message', repr(e))
messages.add_message(request, messages.ERROR, feedback_message)
reverse_url = 'dictionary:admin_gloss_view'
return HttpResponseRedirect(reverse(reverse_url, kwargs={'pk': str(gloss.pk)}))
return HttpResponseBadRequest(feedback_message, {'content-type': 'text/plain'})

return HttpResponse(str(value), {'content-type': 'text/plain'})

Expand Down

0 comments on commit ed950dd

Please sign in to comment.