[damned-lies: 1/2] api: Add comment to the upload endpoint
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies: 1/2] api: Add comment to the upload endpoint
- Date: Thu, 29 Jul 2021 07:36:09 +0000 (UTC)
commit d8b6ef9a1302de1af5e1f4adca917852d273ece9
Author: Daniel GarcĂa Moreno <dani danigm net>
Date: Thu Jul 29 09:13:39 2021 +0200
api: Add comment to the upload endpoint
This patch adds a comment to the upload endpoint to be able to add
comments when using it from Gtranslator.
The comment parameter is optional so it'll continue working if the
comment is not set.
See https://gitlab.gnome.org/GNOME/gtranslator/-/issues/135
api/tests.py | 14 +++++++++++++-
api/views.py | 3 ++-
2 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/api/tests.py b/api/tests.py
index 0930cec9..e38a1e8e 100644
--- a/api/tests.py
+++ b/api/tests.py
@@ -9,7 +9,7 @@ from languages.models import Language
from people.models import Person
from stats.models import Branch, Domain
from teams.models import Role, Team
-from vertimus.models import State, StateTranslating
+from vertimus.models import Action, State, StateTranslating
from vertimus.views import get_vertimus_state
@@ -158,3 +158,15 @@ class APITests(TestCase):
self.assertEqual(response.json(), {'result': 'OK'})
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].recipients(), [team.mailing_list])
+
+ # Test upload with comment
+ state.change_state(StateTranslating, person=translator)
+ with (test_po).open('rb') as fh:
+ data = {
+ 'file': File(fh),
+ 'comment': 'The comment',
+ }
+ response = self.client.post(url, data=data)
+ self.assertEqual(response.json(), {'result': 'OK'})
+ action = Action.objects.last()
+ self.assertEqual(action.comment, "The comment")
diff --git a/api/views.py b/api/views.py
index 19cbf847..04ee54a6 100644
--- a/api/views.py
+++ b/api/views.py
@@ -235,7 +235,8 @@ class UploadTranslationView(LoginRequiredMixin, VertimusPageMixin, View):
return HttpResponseForbidden('You cannot upload a translation to this module')
action = ActionUT(person=request.user.person, file=request.FILES.get('file'))
- action.apply_on(state, {'comment': '', 'send_to_ml': True})
+ comment = request.POST.get('comment', '')
+ action.apply_on(state, {'comment': comment, 'send_to_ml': True})
return JsonResponse({'result': 'OK'})
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]