baby step towards enabling profile edits
authorcfdv <caldavis@gmail.com>
Sat, 18 Jun 2011 21:42:22 +0000 (16:42 -0500)
committercfdv <caldavis@gmail.com>
Sat, 18 Jun 2011 21:42:22 +0000 (16:42 -0500)
adds
* url and bio fields to database
* form for editing the user profile
* route to the edit profile controller
* view for the profile editing page
* template for the profile editing page
* link to edit profile in the welcome page

still needs
* thorough inspection to see if it makes sense
* tests
* ?

mediagoblin/db/models.py
mediagoblin/edit/forms.py
mediagoblin/edit/routing.py
mediagoblin/edit/views.py
mediagoblin/templates/mediagoblin/edit/edit_profile.html [new file with mode: 0644]
mediagoblin/templates/mediagoblin/root.html

index 4b6518cc59011f81b32eb682f033c0f44d924990..78bec979021b3c2547764dba01b4ae277fbbb74c 100644 (file)
@@ -46,7 +46,7 @@ class User(Document):
         'status': unicode,
         'verification_key': unicode,
         'is_admin': bool,
-        'website_url' : unicode,
+        'url' : unicode,
         'bio' : unicode
         }
 
index ea25141d654eca79d1c7bd7e794902c96639dc89..fb4930a2ce2dfb4ca9a891c9678391d7ab36d292 100644 (file)
@@ -25,3 +25,10 @@ class EditForm(wtforms.Form):
     slug = wtforms.TextField(
         'Slug')
     description = wtforms.TextAreaField('Description of this work')
+
+class EditProfileForm(wtforms.Form):
+    url = wtforms.TextField(
+        'website URL',
+        [wtforms.validators.URL(message='Improperly formed URL')])
+    bio = wtforms.TextAreaField('bio',
+        [wtforms.validators.Length(min=0, max=500)])
index bf0b24987fc1816aa069fb6fd6c216cf51708b61..37595f05d4801b82f867453e7bec0e17333b7d90 100644 (file)
@@ -19,4 +19,6 @@ from routes.route import Route
 
 edit_routes = [
     # Media editing view handled in user_pages/routing.py
+    Route('mediagoblin.edit.profile', '/{user}/profile/',
+        controller="mediagoblin.edit.views:edit_profile")
 ]
index c5f0f435b1ebd281d1ba1a3a19711cf08d102fcf..cb62d2fa31adbba6033f24a03a85e5f82f1a2005 100644 (file)
@@ -59,3 +59,23 @@ def edit_media(request, media):
         'mediagoblin/edit/edit.html',
         {'media': media,
          'form': form})
+    
+@require_active_login
+def edit_profile(request):
+
+    form = forms.EditProfileForm(request.POST,
+        url = user['url'],
+        bio = user['bio'])
+
+    if request.method == 'POST' and form.validate():
+            user['url'] = request.POST['url']
+            user['bio'] = request.POST['bio']
+            user.save()
+
+            return redirect(request, "index", user=user.username)
+
+    return render_to_response(
+        request,
+        'mediagoblin/edit/edit_profile.html',
+        {'user': user,
+         'form': form})
diff --git a/mediagoblin/templates/mediagoblin/edit/edit_profile.html b/mediagoblin/templates/mediagoblin/edit/edit_profile.html
new file mode 100644 (file)
index 0000000..9f6667f
--- /dev/null
@@ -0,0 +1,35 @@
+{#
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011 Free Software Foundation, Inc
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#}
+{% extends "mediagoblin/base.html" %}
+
+{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
+
+{% block mediagoblin_content %}
+  <h1>Edit details for {{ user }}</h1>
+
+  <form action="{{ request.urlgen('mediagoblin.edit.profile',
+                               user=user.username) }}"
+        method="POST" enctype="multipart/form-data">
+    <div class="submit_box form_box">
+      {{ wtforms_util.render_divs(form) }}
+      <div class="form_submit_buttons">
+        <input type="submit" value="submit" class="button" />
+      </div>
+    </div>
+  </form>
+{% endblock %}    
index e5344e08c5a665e56d874900541abf0041bd71b7..7af572b01a7d3e17f326b87c51b0325ff95f77b8 100644 (file)
@@ -23,7 +23,8 @@
 
   {% if request.user %}
   <p>
-    <a href="{{ request.urlgen('mediagoblin.submit.start') }}">Submit an item</a>.
+    <a href="{{ request.urlgen('mediagoblin.submit.start') }}">Submit an item</a> 
+    <a href="{{ request.urlgen('mediagoblin.edit.profile') }}">Edit profile</a>
   </p>
 
   {% else %}