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 @@
- Submit an item. -
- ++ 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 ;) #} 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 %}