mediagoblin-devel
[Top][All Lists]
Advanced

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

Re: [GMG-Devel] Intro [+ patch]


From: ĎÚβĨŐÚŚ Dod
Subject: Re: [GMG-Devel] Intro [+ patch]
Date: Tue, 26 Jun 2018 09:28:29 -0400

> We accept patches via the mailing list. Or you can give us a link to
> 
> your git, we will be happy to merge it.
Eventually, we'll have a publicly-accessible repo

> I would appreciate if you give better description of why the change is
> needed. I don't understand what has changed.

Here's a later version of the patch (contains 2 fixes), with a more elaborate 
comment message

----->8------------------------

>From 1aba32d199afa8a203324468ec4c6d58b717fbff Mon Sep 17 00:00:00 2001
From: The Dod <thedod@localhost>
Date: Tue, 26 Jun 2018 16:06:39 +0300
Subject: [PATCH] 2 bug fixes in editor views

* `WTForms` instances get `__init__`-ed with `defaults` as `kwargs`.
  The first arg is a `request.form` (which is what one must supply if
  this is a `POST` and must *not* supply otherwise).
  The content of that form (empty on `GET`) has higher priority than
  the defaults (which makes the user get an empty form).

* Fix `edit_profile()` to allow changing `location` from a non-blank
  value to blank (i.e. removing the location).
---
 mediagoblin/edit/views.py | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py
index 00c6115..c7f5225 100644
--- a/mediagoblin/edit/views.py
+++ b/mediagoblin/edit/views.py
@@ -1,4 +1,4 @@
-# GNU MediaGoblin -- federated, autonomous media hosting
+
 # Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
 #
 # This program is free software: you can redistribute it and/or modify
@@ -66,7 +66,7 @@ def edit_media(request, media):
         license=media.license)
 
     form = forms.EditForm(
-        request.form,
+        request.method=='POST' and request.form or None,
         **defaults)
 
     if request.method == 'POST' and form.validate():
@@ -208,7 +208,8 @@ def edit_profile(request, url_user=None):
     else:
         location = user.get_location.name
 
-    form = forms.EditProfileForm(request.form,
+    form = forms.EditProfileForm(
+        request.method == 'POST' and request.form or None,
         url=user.url,
         bio=user.bio,
         location=location)
@@ -224,6 +225,8 @@ def edit_profile(request, url_user=None):
             location = user.get_location
             location.name = six.text_type(form.location.data)
             location.save()
+        else:
+            user.location = None
 
         user.save()
 
@@ -248,7 +251,8 @@ EMAIL_VERIFICATION_TEMPLATE = (
 @require_active_login
 def edit_account(request):
     user = request.user
-    form = forms.EditAccountForm(request.form,
+    form = forms.EditAccountForm(
+        request.method == 'POST' and request.form or None,
         wants_comment_notification=user.wants_comment_notification,
         license_preference=user.license_preference,
         wants_notifications=user.wants_notifications)
@@ -344,7 +348,7 @@ def edit_collection(request, collection):
         description=collection.description)
 
     form = forms.EditCollectionForm(
-        request.form,
+        request.method == 'POST' and request.form or None,
         **defaults)
 
     if request.method == 'POST' and form.validate():
@@ -436,7 +440,8 @@ def verify_email(request):
 
 def change_email(request):
     """ View to change the user's email """
-    form = forms.ChangeEmailForm(request.form)
+    form = forms.ChangeEmailForm(
+        request.method == 'POST' and request.form or None)
     user = request.user
 
     # If no password authentication, no need to enter a password
@@ -489,7 +494,8 @@ def change_email(request):
 @require_active_login
 @get_media_entry_by_id
 def edit_metadata(request, media):
-    form = forms.EditMetaDataForm(request.form)
+    form = forms.EditMetaDataForm(
+        request.method == 'POST' and request.form or None)
     if request.method == "POST" and form.validate():
         metadata_dict = dict([(row['identifier'],row['value'])
                             for row in form.media_metadata.data])
-- 
2.7.4



reply via email to

[Prev in Thread] Current Thread [Next in Thread]