diff options
-rw-r--r-- | mediagoblin/db/migrations.py | 19 | ||||
-rw-r--r-- | mediagoblin/db/models.py | 4 | ||||
-rw-r--r-- | mediagoblin/edit/forms.py | 7 | ||||
-rw-r--r-- | mediagoblin/edit/routing.py | 3 | ||||
-rw-r--r-- | mediagoblin/edit/views.py | 22 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/base.html | 2 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/edit/edit_profile.html | 35 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/root.html | 25 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/user.html | 2 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/utils/profile.html | 35 | ||||
-rw-r--r-- | mediagoblin/tests/__init__.py | 15 | ||||
-rw-r--r-- | mediagoblin/tests/tools.py | 23 |
12 files changed, 161 insertions, 31 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index aacbf079..712f8ab4 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -50,5 +50,20 @@ 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 = {'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'] diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index e034cc29..600b79ff 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, + 'url' : unicode, + 'bio' : unicode } required_fields = ['username', 'created', 'pw_hash', 'email'] @@ -56,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): """ 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..9771207a 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -19,4 +19,5 @@ from routes.route import Route edit_routes = [ # Media editing view handled in user_pages/routing.py -] + Route('mediagoblin.edit.profile', '/profile/', + controller="mediagoblin.edit.views:edit_profile")] diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 6c16a61e..a9071495 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -68,3 +68,25 @@ def edit_media(request, media): 'mediagoblin/edit/edit.html', {'media': media, 'form': form}) + + +@require_active_login +def edit_profile(request): + + user = request.user + form = forms.EditProfileForm(request.POST, + 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 render_to_response( + request, + 'mediagoblin/edit/edit_profile.html', + {'user': user, + 'form': form}) 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 @@ <div class="mediagoblin_header_right"> {% if request.user %} {{ request.user['username'] }}'s account + <a href="{{ request.urlgen('mediagoblin.user_pages.user_home', + user= request.user['username']) }}">home</a> <a href="{{ request.urlgen('mediagoblin.user_pages.user_gallery', user= request.user['username']) }}">gallery</a> (<a href="{{ request.urlgen('mediagoblin.auth.logout') }}">logout</a>) diff --git a/mediagoblin/templates/mediagoblin/edit/edit_profile.html b/mediagoblin/templates/mediagoblin/edit/edit_profile.html new file mode 100644 index 00000000..63bf013f --- /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 <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['username'] }}</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 %} diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html index e5344e08..7261f4fc 100644 --- a/mediagoblin/templates/mediagoblin/root.html +++ b/mediagoblin/templates/mediagoblin/root.html @@ -22,20 +22,19 @@ <h1>{% trans %}Welcome to GNU MediaGoblin!{% endtrans %}</h1> {% if request.user %} - <p> - <a href="{{ request.urlgen('mediagoblin.submit.start') }}">Submit an item</a>. - </p> - + <p> + <a href="{{ request.urlgen('mediagoblin.submit.start') }}">Submit an item</a> + <a href="{{ request.urlgen('mediagoblin.edit.profile') }}">Edit profile</a> + </p> {% else %} - <p> - If you have an account, you can - <a href="{{ request.urlgen('mediagoblin.auth.login') }}">Login</a>. - </p> - <p> - If you don't have an account, please - <a href="{{ request.urlgen('mediagoblin.auth.register') }}">Register</a>. - </p> - + <p> + If you have an account, you can + <a href="{{ request.urlgen('mediagoblin.auth.login') }}">Login</a>. + </p> + <p> + If you don't have an account, please + <a href="{{ request.urlgen('mediagoblin.auth.register') }}">Register</a>. + </p> {% endif %} {# temporarily, an "image gallery" that isn't one really ;) #} 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 %} <h1>User page for '{{ user.username }}'</h1> + + {% 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 <http://www.gnu.org/licenses/>. +#} + +{% block profile_content -%} + <div> + <ul> + {% if user.url %} + <li> + <a href="{{ user.url }}">homepage</a> + </li> + {% endif %} + + {% if user.bio %} + <li> + {{ user.bio }} + </li> + {% endif %} + </ul> + </div> +{% endblock %} diff --git a/mediagoblin/tests/__init__.py b/mediagoblin/tests/__init__.py index 1f1e23e9..adb6a1b3 100644 --- a/mediagoblin/tests/__init__.py +++ b/mediagoblin/tests/__init__.py @@ -16,12 +16,17 @@ from mediagoblin import mg_globals +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: - 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..ebb5f1b5 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( @@ -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 @@ -78,6 +84,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 +94,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 |