[damned-lies] Commit-related fixes



commit 049208b1ec0975265767fb28a9e9713ca39c9c11
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Aug 24 14:07:14 2013 +0200

    Commit-related fixes

 vertimus/models.py |    9 +++++----
 vertimus/views.py  |    5 ++++-
 2 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/vertimus/models.py b/vertimus/models.py
index 7b8b01c..21c2a2c 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -441,10 +441,11 @@ class Action(ActionAbstract):
         Return the previous Action with an uploaded file related to the
         same state.
         """
+        prev_actions_with_po = Action.objects.filter(file__endswith=".po", state_db=self.state_db)
+        if self.id:
+            prev_actions_with_po = prev_actions_with_po.filter(id__lt=self.id)
         try:
-            action = Action.objects.filter(file__endswith=".po", state_db=self.state_db,
-                id__lt=self.id).latest('id')
-            return action
+            return prev_actions_with_po.latest('id')
         except Action.DoesNotExist:
             return None
 
@@ -620,12 +621,12 @@ class ActionCI(Action):
         proxy = True
 
     def apply_on(self, state, send_to_ml):
+        self.state_db = state
         action_with_po = self.get_previous_action_with_po()
         try:
             state.branch.commit_po(action_with_po.file.path, state.domain, state.language, self.person)
         except:
             # Commit failed, state unchanged
-            # FIXME: somewhere the error should be catched and handled properly
             raise Exception(_("The commit failed. The error was: '%s'") % sys.exc_info()[1])
 
         super(ActionCI, self).apply_on(state, send_to_ml) # Mail sent in super
diff --git a/vertimus/views.py b/vertimus/views.py
index 6bad36a..b73ddb6 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -109,8 +109,11 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
                 try:
                     action.apply_on(state, action_form.cleaned_data.get('send_to_ml'))
                 except SendMailFailed:
-                    messages.error(request, 
+                    messages.error(request,
                         _("A problem occurred while sending mail, no mail have been sent"))
+                except Exception as e:
+                    messages.error(request,
+                        _("An error occurred during applying your action: %s") % e)
 
                 return HttpResponseRedirect(
                     urlresolvers.reverse('vertimus_by_names',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]