Repository: liberapay/liberapay.com

Issue:
Going back to default language after saving the translation of "presentation" in some other language 
When I write a translated version of the "presentation" in a given language (in my example it was english) and that I click on save, I am automatically sent to to the project presentation in the default language of my liberapay account (in my case it was french). So one can think that the translated version failed to save, and is lost forever, which is not the case, if one chooses again the presentation in the language version that was just ment to be saved it is indeed saved, but why after saving getting back to the default language? 


Discussion:
I can confirm that this is the behavior. It looks like a bug.

Resolving patch:
diff --git a/liberapay/models/participant.py b/liberapay/models/participant.py
--- a/liberapay/models/participant.py
+++ b/liberapay/models/participant.py
@@ -1864,13 +1864,16 @@ def is_char_forbidden(char):
 
         return new_public_name
 
-    def update_avatar(self, src=None, cursor=None):
+    def update_avatar(self, src=None, cursor=None, avatar_email=None):
         if self.status == 'stub':
             assert src is None
 
         src = self.avatar_src if src is None else src
-        platform, key = src.split(':', 1) if src else (None, None)
-        email = self.avatar_email or self.email or self.get_any_email(cursor)
+        platform, user_id = src.split(':', 1) if src else (None, None)
+
+        if avatar_email is None:
+            avatar_email = self.avatar_email
+        email = avatar_email or self.email or self.get_any_email(cursor)
 
         if platform == 'libravatar' or platform is None and email:
             if not email:
@@ -1896,19 +1899,19 @@ def update_avatar(self, src=None, cursor=None):
                   FROM elsewhere
                  WHERE participant = %s
                    AND platform = %s
-                -- AND user_id = %%s  -- not implemented yet
-            """, (self.id, platform))
-
-        if not avatar_url:
-            return
+                   AND coalesce(user_id = %s, true)
+            """, (self.id, platform, user_id or None))
 
+        if avatar_email == '':
+            avatar_email = None
         (cursor or self.db).run("""
             UPDATE participants
-               SET avatar_url = %s
+               SET avatar_url = coalesce(%s, avatar_url)
                  , avatar_src = %s
+                 , avatar_email = %s
              WHERE id = %s
-        """, (avatar_url, src, self.id))
-        self.set_attributes(avatar_src=src, avatar_url=avatar_url)
+        """, (avatar_url, src, avatar_email, self.id))
+        self.set_attributes(avatar_src=src, avatar_url=avatar_url, avatar_email=avatar_email)
 
         return avatar_url
 
diff --git a/liberapay/utils/__init__.py b/liberapay/utils/__init__.py
--- a/liberapay/utils/__init__.py
+++ b/liberapay/utils/__init__.py
@@ -187,7 +187,7 @@ def form_post_success(state, msg='', redirect_url=None):
         raise response.json({"msg": msg} if msg else {})
     else:
         if not redirect_url:
-            redirect_url = request.body.get('back_to') or request.path.raw
+            redirect_url = request.body.get('back_to') or request.line.uri.decoded
             redirect_url = response.sanitize_untrusted_url(redirect_url)
         redirect_url = _modify_query(redirect_url, 'success', b64encode_s(msg))
         response.redirect(redirect_url)


Test patch: