From 48693437391ddd9d3c9f732304b4990ff6967989 Mon Sep 17 00:00:00 2001 From: cfdv Date: Fri, 17 Jun 2011 21:43:48 -0500 Subject: [PATCH 1/8] adds global link to user's home page in the base.html template Issue #315 (add bio and website to user page) * enable profile edits * provide place in user's home page for details to appear --- mediagoblin/templates/mediagoblin/base.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mediagoblin/templates/mediagoblin/base.html b/mediagoblin/templates/mediagoblin/base.html index c7313173..8e5fd55b 100644 --- a/mediagoblin/templates/mediagoblin/base.html +++ b/mediagoblin/templates/mediagoblin/base.html @@ -35,6 +35,8 @@
{% if request.user %} {{ request.user['username'] }}'s account + home gallery (logout) From 279d925e757d9756e09e14316f0d85b6e20624ea Mon Sep 17 00:00:00 2001 From: cfdv Date: Sat, 18 Jun 2011 15:00:05 -0500 Subject: [PATCH 2/8] adds user bio and website url fields to the database --- mediagoblin/db/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index d77cf619..4b6518cc 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -46,6 +46,8 @@ class User(Document): 'status': unicode, 'verification_key': unicode, 'is_admin': bool, + 'website_url' : unicode, + 'bio' : unicode } required_fields = ['username', 'created', 'pw_hash', 'email'] From 630b57a366d10495a89d392c9b02cf432e6a1599 Mon Sep 17 00:00:00 2001 From: cfdv Date: Sat, 18 Jun 2011 16:42:22 -0500 Subject: [PATCH 3/8] 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 %} From 0bf340727e82ffdb03196a5a9a8ff94c7d4ec0f7 Mon Sep 17 00:00:00 2001 From: cfdv Date: Sat, 18 Jun 2011 21:30:56 -0500 Subject: [PATCH 4/8] enables entering user details including website url and bio fixes usage of objects. still need to display the data on user page --- mediagoblin/edit/routing.py | 3 +-- mediagoblin/edit/views.py | 7 ++++--- mediagoblin/templates/mediagoblin/edit/edit_profile.html | 2 +- mediagoblin/templates/mediagoblin/root.html | 4 +++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mediagoblin/edit/routing.py b/mediagoblin/edit/routing.py index 37595f05..9604d214 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -20,5 +20,4 @@ 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") -] + controller="mediagoblin.edit.views:edit_profile")] diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index cb62d2fa..57c9a118 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -63,16 +63,17 @@ def edit_media(request, media): @require_active_login def edit_profile(request): + user = request.user form = forms.EditProfileForm(request.POST, - url = user['url'], - bio = user['bio']) + url = user.get('url'), + bio = user.get('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 redirect(request, "index", user=user['username']) return render_to_response( request, diff --git a/mediagoblin/templates/mediagoblin/edit/edit_profile.html b/mediagoblin/templates/mediagoblin/edit/edit_profile.html index 9f6667fd..63bf013f 100644 --- a/mediagoblin/templates/mediagoblin/edit/edit_profile.html +++ b/mediagoblin/templates/mediagoblin/edit/edit_profile.html @@ -20,7 +20,7 @@ {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% block mediagoblin_content %} -

Edit details for {{ user }}

+

Edit details for {{ user['username'] }}

Submit an item - Edit profile + Edit profile

{% else %} From 699b5475806c43af339d48408a7ea04ae9027c1a Mon Sep 17 00:00:00 2001 From: cfdv Date: Sat, 18 Jun 2011 22:24:32 -0500 Subject: [PATCH 5/8] enables primitive display of profile data on user page --- .../mediagoblin/user_pages/user.html | 2 ++ .../templates/mediagoblin/utils/profile.html | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 mediagoblin/templates/mediagoblin/utils/profile.html diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html index b3708c85..f7a9f3c9 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/user.html +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html @@ -27,6 +27,8 @@ {% block mediagoblin_content -%} {% if user %}

User page for '{{ user.username }}'

+ + {% include "mediagoblin/utils/profile.html" %} {% include "mediagoblin/utils/object_gallery.html" %} diff --git a/mediagoblin/templates/mediagoblin/utils/profile.html b/mediagoblin/templates/mediagoblin/utils/profile.html new file mode 100644 index 00000000..b3f5f0f8 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/utils/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 . +#} + +{% block profile_content -%} +
+
    + {% if user.url %} +
  • + homepage +
  • + {% endif %} + + {% if user.bio %} +
  • + {{ user.bio }} +
  • + {% endif %} +
+
+{% endblock %} From e36ecab0931f25d65169bfcf26d8a56d33eef02a Mon Sep 17 00:00:00 2001 From: cfdv Date: Mon, 20 Jun 2011 13:07:15 -0500 Subject: [PATCH 6/8] adds accommmodations for migration of fields in User: bio and url --- mediagoblin/db/migrations.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index b87988fe..a3e7133c 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -49,5 +49,21 @@ class MediaEntryMigration(DocumentMigration): 'description_html': cleaned_markdown_conversion( doc['description'])}} - -MIGRATE_CLASSES = ['MediaEntry'] +class UserMigration(DocumentMigration): + def allmigration01_add_bio_and_url_profile(self): + """ + User can elaborate profile with home page and biography + """ + self.target = {'username': {'$exists': True}, 'url': {'$exists': False}, + 'bio': {'$exists': False}} + if not self.status: + for doc in self.collection.find(self.target): + self.update = { + '$set': { + 'url': '', + 'bio': ''}} + self.collection.update( + self.target, self.update, multi=True, safe=True) + + +MIGRATE_CLASSES = ['MediaEntry','User'] From 17bb7c388b1f6190a43945e8e2f3e96bb826fb72 Mon Sep 17 00:00:00 2001 From: cfdv Date: Mon, 20 Jun 2011 19:28:02 -0500 Subject: [PATCH 7/8] removes unecessary dependence on existence of username for User migration01, + fix whitespace issues --- mediagoblin/db/migrations.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index a3e7133c..29bc112f 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -54,16 +54,15 @@ class UserMigration(DocumentMigration): """ User can elaborate profile with home page and biography """ - self.target = {'username': {'$exists': True}, 'url': {'$exists': False}, - 'bio': {'$exists': False}} + self.target = {'url': {'$exists': False}, + 'bio': {'$exists': False}} if not self.status: for doc in self.collection.find(self.target): self.update = { - '$set': { - 'url': '', - 'bio': ''}} + '$set': {'url': '', + 'bio': ''}} self.collection.update( self.target, self.update, multi=True, safe=True) -MIGRATE_CLASSES = ['MediaEntry','User'] +MIGRATE_CLASSES = ['MediaEntry', 'User'] From 0472653ee4763e2f045632d49a9eed729a491f97 Mon Sep 17 00:00:00 2001 From: cfdv Date: Mon, 20 Jun 2011 22:47:43 -0500 Subject: [PATCH 8/8] assigns migration steps to User database objects adds the migration_handler to the User db class, connecting the migration steps in ../db/migrations.py to the migration code in gmg_commands --- mediagoblin/db/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index b3de7793..600b79ff 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -58,6 +58,8 @@ class User(Document): 'status': u'needs_email_verification', 'verification_key': lambda: unicode(uuid.uuid4()), 'is_admin': False} + + migration_handler = migrations.UserMigration def check_login(self, password): """