From 630b57a366d10495a89d392c9b02cf432e6a1599 Mon Sep 17 00:00:00 2001 From: cfdv Date: Sat, 18 Jun 2011 16:42:22 -0500 Subject: [PATCH] baby step towards enabling profile edits 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 | 2 +- mediagoblin/edit/forms.py | 7 ++++ mediagoblin/edit/routing.py | 2 ++ mediagoblin/edit/views.py | 20 +++++++++++ .../mediagoblin/edit/edit_profile.html | 35 +++++++++++++++++++ mediagoblin/templates/mediagoblin/root.html | 3 +- 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 mediagoblin/templates/mediagoblin/edit/edit_profile.html diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 4b6518cc..78bec979 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -46,7 +46,7 @@ class User(Document): 'status': unicode, 'verification_key': unicode, 'is_admin': bool, - 'website_url' : unicode, + 'url' : unicode, 'bio' : unicode } diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index ea25141d..fb4930a2 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -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)]) diff --git a/mediagoblin/edit/routing.py b/mediagoblin/edit/routing.py index bf0b2498..37595f05 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -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") ] diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index c5f0f435..cb62d2fa 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -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 index 00000000..9f6667fd --- /dev/null +++ b/mediagoblin/templates/mediagoblin/edit/edit_profile.html @@ -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 . +#} +{% extends "mediagoblin/base.html" %} + +{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} + +{% block mediagoblin_content %} +

Edit details for {{ user }}

+ +
+
+ {{ wtforms_util.render_divs(form) }} +
+ +
+
+
+{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html index e5344e08..7af572b0 100644 --- a/mediagoblin/templates/mediagoblin/root.html +++ b/mediagoblin/templates/mediagoblin/root.html @@ -23,7 +23,8 @@ {% if request.user %}

- Submit an item. + Submit an item + Edit profile

{% else %} -- 2.25.1