From 48693437391ddd9d3c9f732304b4990ff6967989 Mon Sep 17 00:00:00 2001 From: cfdv Date: Fri, 17 Jun 2011 21:43:48 -0500 Subject: [PATCH 01/13] 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 02/13] 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 03/13] 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 04/13] 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 05/13] 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 06/13] 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 07/13] 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 08/13] 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): """ From cfd2cbf3dd0c454556524a649204c51f7a6f6a5b Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 21 Jun 2011 16:04:44 -0500 Subject: [PATCH 09/13] Make sure we *ONLY* ever kill the test database, EVER. --- mediagoblin/tests/__init__.py | 11 +++++++---- mediagoblin/tests/tools.py | 7 ++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mediagoblin/tests/__init__.py b/mediagoblin/tests/__init__.py index 1f1e23e9..8aec4a96 100644 --- a/mediagoblin/tests/__init__.py +++ b/mediagoblin/tests/__init__.py @@ -16,12 +16,15 @@ from mediagoblin import mg_globals +from mediagoblin.tests.tools import MEDIAGOBLIN_TEST_DB_NAME + def setup_package(): pass def teardown_package(): - if mg_globals.db_connection: - print "Killing db ..." - mg_globals.db_connection.drop_database(mg_globals.database.name) - print "... done" + if ((mg_globals.db_connection + and mg_globals.database.name == MEDIAGOBLIN_TEST_DB_NAME)): + print "Killing db ..." + mg_globals.db_connection.drop_database(MEDIAGOBLIN_TEST_DB_NAME) + print "... done" diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index 9e36fc5c..b35d54e0 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -28,7 +28,7 @@ from mediagoblin.decorators import _make_safe from mediagoblin.db.open import setup_connection_and_db_from_config -MEDIAGOBLIN_TEST_DB_NAME = '__mediagoblinunittests__' +MEDIAGOBLIN_TEST_DB_NAME = u'__mediagoblin_tests__' TEST_SERVER_CONFIG = pkg_resources.resource_filename( 'mediagoblin.tests', 'test_paste.ini') TEST_APP_CONFIG = pkg_resources.resource_filename( @@ -78,6 +78,7 @@ def get_test_app(dump_old_app=True): # @@: For now we're dropping collections, but we could also just # collection.remove() ? connection, db = setup_connection_and_db_from_config(app_config) + assert db.name == MEDIAGOBLIN_TEST_DB_NAME collections_to_wipe = [ collection @@ -87,10 +88,6 @@ def get_test_app(dump_old_app=True): for collection in collections_to_wipe: db.drop_collection(collection) - # Don't need these anymore... - del(connection) - del(db) - # TODO: Drop and recreate indexes # setup app and return From 29f1333e722c10d3eff106bd64bb2ded0207e975 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 21 Jun 2011 17:02:49 -0500 Subject: [PATCH 10/13] Extra checks so that we don't even RUN tests unless the right celery environ set --- mediagoblin/tests/__init__.py | 6 ++++-- mediagoblin/tests/tools.py | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/mediagoblin/tests/__init__.py b/mediagoblin/tests/__init__.py index 8aec4a96..adb6a1b3 100644 --- a/mediagoblin/tests/__init__.py +++ b/mediagoblin/tests/__init__.py @@ -16,11 +16,13 @@ from mediagoblin import mg_globals -from mediagoblin.tests.tools import MEDIAGOBLIN_TEST_DB_NAME +from mediagoblin.tests.tools import ( + MEDIAGOBLIN_TEST_DB_NAME, suicide_if_bad_celery_environ) def setup_package(): - pass + suicide_if_bad_celery_environ() + def teardown_package(): if ((mg_globals.db_connection diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index b35d54e0..ebb5f1b5 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -42,17 +42,23 @@ USER_DEV_DIRECTORIES_TO_SETUP = [ 'media/public', 'media/queue', 'beaker/sessions/data', 'beaker/sessions/lock'] +BAD_CELERY_MESSAGE = """\ +Sorry, you *absolutely* must run nosetests with the +mediagoblin.celery_setup.from_tests module. Like so: +$ CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_tests ./bin/nosetests""" + class BadCeleryEnviron(Exception): pass -def get_test_app(dump_old_app=True): +def suicide_if_bad_celery_environ(): if not os.environ.get('CELERY_CONFIG_MODULE') == \ 'mediagoblin.celery_setup.from_tests': - raise BadCeleryEnviron( - u"Sorry, you *absolutely* must run nosetests with the\n" - u"mediagoblin.celery_setup.from_tests module. Like so:\n" - u"$ CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_tests ./bin/nosetests") + raise BadCeleryEnviron(BAD_CELERY_MESSAGE) + + +def get_test_app(dump_old_app=True): + suicide_if_bad_celery_environ() global MGOBLIN_APP global CELERY_SETUP From b9f097a6f91fbe773d5f5dcbb7d904758efeebc1 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 21 Jun 2011 23:25:15 -0500 Subject: [PATCH 11/13] Indenting some sections between if / else blocks in root.html --- mediagoblin/templates/mediagoblin/root.html | 30 ++++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html index 697ac15b..550e0847 100644 --- a/mediagoblin/templates/mediagoblin/root.html +++ b/mediagoblin/templates/mediagoblin/root.html @@ -22,23 +22,21 @@

{% trans %}Welcome to GNU MediaGoblin!{% endtrans %}

{% if request.user %} -

- Submit an item - Edit profile -

- +

+ Submit an item + Edit profile +

{% else %} -

- If you have an account, you can - Login. -

-

- If you don't have an account, please - Register. -

- +

+ If you have an account, you can + Login. +

+

+ If you don't have an account, please + Register. +

{% endif %} {# temporarily, an "image gallery" that isn't one really ;) #} From 46fd661e3479ad9157d45190aba7c8127d9b8f7f Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 21 Jun 2011 23:26:18 -0500 Subject: [PATCH 12/13] Adding an extra space between function definitions --- mediagoblin/edit/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 3de71a64..a9071495 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -69,6 +69,7 @@ def edit_media(request, media): {'media': media, 'form': form}) + @require_active_login def edit_profile(request): From d220f87c120e4c8627a80adaa6fab18ebe85669f Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 21 Jun 2011 23:26:45 -0500 Subject: [PATCH 13/13] I don't think we need the username to be part of the profile editing URL --- mediagoblin/edit/routing.py | 2 +- mediagoblin/templates/mediagoblin/root.html | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mediagoblin/edit/routing.py b/mediagoblin/edit/routing.py index 9604d214..9771207a 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -19,5 +19,5 @@ from routes.route import Route edit_routes = [ # Media editing view handled in user_pages/routing.py - Route('mediagoblin.edit.profile', '/{user}/profile/', + Route('mediagoblin.edit.profile', '/profile/', controller="mediagoblin.edit.views:edit_profile")] diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html index 550e0847..7261f4fc 100644 --- a/mediagoblin/templates/mediagoblin/root.html +++ b/mediagoblin/templates/mediagoblin/root.html @@ -24,9 +24,7 @@ {% if request.user %}

Submit an item - Edit profile + Edit profile

{% else %}