From d88e1d15c7c4903a696830155527f70e33b88c72 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Mon, 8 Aug 2011 00:10:46 -0500 Subject: [PATCH 01/11] Bug #488 - email validation assumes active login - loads username from user object instead of session to remove dependency on active login --- mediagoblin/auth/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index df7e2a88..19dafed0 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -157,7 +157,7 @@ def verify_email(request): return redirect( request, 'mediagoblin.user_pages.user_home', - user=request.user['username']) + user = user['username']) def resend_activation(request): From 84abd2bbc43e2d92d429c679f49e237207057150 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Wed, 10 Aug 2011 12:48:23 -0500 Subject: [PATCH 02/11] Bug #372 - MediaEntry.thumbnail_file not used - deleted the thumbnail_file from the media_entries collection - added a migration to remove the field from previous db versions --- mediagoblin/db/migrations.py | 10 ++++++++++ mediagoblin/db/models.py | 7 +------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 6a8ebcf9..8c088145 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -52,3 +52,13 @@ def mediaentry_mediafiles_main_to_original(database): document['media_files']['original'] = original collection.save(document) + +@RegisterMigration(3) +def mediaentry_remove_thumbnail_file(database): + """ + Use media_files['thumb'] instead of media_entries['thumbnail_file'] + """ + database['media_entries'].update( + {'thumbnail_file': {'$exists': True}}, + {'$unset': {'thumbnail_file': 1}}, + multi=True) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 4ef2d928..aff2a65b 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -169,8 +169,6 @@ class MediaEntry(Document): - attachment_files: A list of "attachment" files, ones that aren't critical to this piece of media but may be usefully relevant to people viewing the work. (currently unused.) - - - thumbnail_file: Deprecated... we should remove this ;) """ __collection__ = 'media_entries' @@ -196,10 +194,7 @@ class MediaEntry(Document): # The following should be lists of lists, in appropriate file # record form - 'attachment_files': list, - - # This one should just be a single file record - 'thumbnail_file': [unicode]} + 'attachment_files': list} required_fields = [ 'uploader', 'created', 'media_type', 'slug'] From f6bf68cae5f2907924e126a3a2f3a2f015292323 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Thu, 11 Aug 2011 00:50:16 -0500 Subject: [PATCH 03/11] Feature #446 - Render the submission form using the render_divs macro - Currently there are individual calls to wtforms_util.render_field_div for each field in the media submit form, which is too verbose - Matched the field ordering in submit/form.py to the verbose version - hacks the correct textareafield rendering with hard-coded rows and columns. - TODO - figure out how to pass the textarea dimensions with **kwargs --- mediagoblin/submit/forms.py | 2 +- mediagoblin/templates/mediagoblin/submit/start.html | 5 +---- mediagoblin/templates/mediagoblin/utils/wtforms.html | 6 +++++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 241d32dc..4519b057 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -22,11 +22,11 @@ from mediagoblin.util import fake_ugettext_passthrough as _ class SubmitStartForm(wtforms.Form): + file = wtforms.FileField(_('File')) title = wtforms.TextField( _('Title'), [wtforms.validators.Length(min=0, max=500)]) description = wtforms.TextAreaField('Description of this work') - file = wtforms.FileField(_('File')) tags = wtforms.TextField( _('Tags'), [tag_length_validator]) diff --git a/mediagoblin/templates/mediagoblin/submit/start.html b/mediagoblin/templates/mediagoblin/submit/start.html index eb34c2e2..3a40850d 100644 --- a/mediagoblin/templates/mediagoblin/submit/start.html +++ b/mediagoblin/templates/mediagoblin/submit/start.html @@ -24,10 +24,7 @@ method="POST" enctype="multipart/form-data">

{% trans %}Submit yer media{% endtrans %}

- {{ wtforms_util.render_field_div(submit_form.file) }} - {{ wtforms_util.render_field_div(submit_form.title) }} - {{ wtforms_util.render_textarea_div(submit_form.description) }} - {{ wtforms_util.render_field_div(submit_form.tags) }} + {{ wtforms_util.render_divs(submit_form) }}
diff --git a/mediagoblin/templates/mediagoblin/utils/wtforms.html b/mediagoblin/templates/mediagoblin/utils/wtforms.html index e3d8e137..3b6cff15 100644 --- a/mediagoblin/templates/mediagoblin/utils/wtforms.html +++ b/mediagoblin/templates/mediagoblin/utils/wtforms.html @@ -23,7 +23,11 @@ {% if field.description -%}
{{ _(field.description) }}
{%- endif %} -
{{ field }}
+ {% if field.type == "TextAreaField" %} +
{{ field(rows=8, cols=20) }}
+ {% else %} +
{{ field }}
+ {% endif %} {%- if field.errors -%} {% for error in field.errors %}
From d07be8119de3b2e10ca37d43dfecd4239dc09aba Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Thu, 11 Aug 2011 10:15:30 -0500 Subject: [PATCH 04/11] eliminates textarea handling since rows cols not required in HTML5 --- .../templates/mediagoblin/utils/wtforms.html | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/mediagoblin/templates/mediagoblin/utils/wtforms.html b/mediagoblin/templates/mediagoblin/utils/wtforms.html index 3b6cff15..2639522a 100644 --- a/mediagoblin/templates/mediagoblin/utils/wtforms.html +++ b/mediagoblin/templates/mediagoblin/utils/wtforms.html @@ -23,30 +23,7 @@ {% if field.description -%}
{{ _(field.description) }}
{%- endif %} - {% if field.type == "TextAreaField" %} -
{{ field(rows=8, cols=20) }}
- {% else %} -
{{ field }}
- {% endif %} - {%- if field.errors -%} - {% for error in field.errors %} -
- {{ error }} -
- {% endfor %} - {%- endif %} -
-{%- endmacro %} - -{# Generically render a textarea - # ... mostly the same thing except it includes rows and cols #} -{% macro render_textarea_div(field, rows=8, cols=20) %} -
-
{{ _(field.label.text) }}
- {% if field.description -%} -
{{ _(field.description) }}
- {%- endif %} -
{{ field(rows=rows, cols=cols) }}
+
{{ field }}
{%- if field.errors -%} {% for error in field.errors %}
From f016fc65056c03fd64d40b918da670281835f76d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 11 Aug 2011 11:29:14 -0500 Subject: [PATCH 05/11] Adding slightly clearer docs to MountStorage. --- mediagoblin/storage.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/mediagoblin/storage.py b/mediagoblin/storage.py index 88c748ce..3968fa29 100644 --- a/mediagoblin/storage.py +++ b/mediagoblin/storage.py @@ -290,16 +290,29 @@ class MountStorage(StorageInterface): """ Experimental "Mount" virtual Storage Interface - This isn't an interface to some real storage, instead - it's a redirecting interface, that redirects requests - to other "StorageInterface"s. - For example, requests for ["store1", "a"] to first - storage with the path ["a"], etc. + This isn't an interface to some real storage, instead it's a + redirecting interface, that redirects requests to other + "StorageInterface"s. + + For example, say you have the paths: + + 1. ['user_data', 'cwebber', 'avatar.jpg'] + 2. ['user_data', 'elrond', 'avatar.jpg'] + 3. ['media_entries', '34352f304c3f4d0ad8ad0f043522b6f2', 'thumb.jpg'] + + You could mount media_entries under CloudFileStorage and user_data + under BasicFileStorage. Then 1 would be passed to + BasicFileStorage under the path ['cwebber', 'avatar.jpg'] and 3 + would be passed to CloudFileStorage under + ['34352f304c3f4d0ad8ad0f043522b6f2', 'thumb.jpg']. + + In other words, this is kind of like mounting /home/ and /etc/ + under different filesystems on your operating system... but with + mediagoblin filestorages :) - To set this up, you currently need to call the mount() - method with the target path and a backend, that shall - be available under that target path. - You have to mount things in a sensible order, + To set this up, you currently need to call the mount() method with + the target path and a backend, that shall be available under that + target path. You have to mount things in a sensible order, especially you can't mount ["a", "b"] before ["a"]. """ def __init__(self, **kwargs): From d9204d3a3dd91f63fd43345415ebeb6fc02cc1c8 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Thu, 11 Aug 2011 19:17:56 -0500 Subject: [PATCH 06/11] uses render_divs for the comments form in media.html for completeness --- mediagoblin/templates/mediagoblin/user_pages/media.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index afc0d903..9c0a1cca 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -55,7 +55,7 @@
- {{ wtforms_util.render_field_div(comment_form.comment_content) }} + {{ wtforms_util.render_divs(comment_form) }}
From dc49cf600aba92331419a3566f768b061b8102e3 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 11 Aug 2011 20:15:55 -0500 Subject: [PATCH 07/11] Making the users_with_username function call in the register view slightly cleaner --- mediagoblin/auth/views.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 121a8c8e..dc90173e 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -45,10 +45,8 @@ def register(request): if request.method == 'POST' and register_form.validate(): # TODO: Make sure the user doesn't exist already - users_with_username = \ - request.db.User.find({ - 'username': request.POST['username'].lower() - }).count() + users_with_username = request.db.User.find( + {'username': request.POST['username'].lower()}).count() if users_with_username: register_form.username.errors.append( From 0bf099d7536b5f5f876fa21e4c72f132b7c757a8 Mon Sep 17 00:00:00 2001 From: Alejandro Villanueva Date: Tue, 14 Jun 2011 11:03:56 -0500 Subject: [PATCH 08/11] Checks if the email(lowercase) have been used before to register a user --- mediagoblin/auth/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index dc90173e..61164be8 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -47,10 +47,15 @@ def register(request): users_with_username = request.db.User.find( {'username': request.POST['username'].lower()}).count() + users_with_email = request.db.User.find( + {'email': request.POST['email'].lower()}).count() if users_with_username: register_form.username.errors.append( _(u'Sorry, a user with that name already exists.')) + elif users_with_email: + register_form.email.errors.append( + _(u'Sorry, that email address has already been taken.')) else: # Create the user From 873e4e9d2da8a3976de6c44838f517cfc314d620 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 11 Aug 2011 20:34:12 -0500 Subject: [PATCH 09/11] Also normalize user's emails to .lower() when we accept the user. --- mediagoblin/auth/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 61164be8..91599e47 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -61,7 +61,7 @@ def register(request): # Create the user user = request.db.User() user['username'] = request.POST['username'].lower() - user['email'] = request.POST['email'] + user['email'] = request.POST['email'].lower() user['pw_hash'] = auth_lib.bcrypt_gen_password_hash( request.POST['password']) user.save(validate=True) From 9f6ea47586f78370c42dc9b45782f398bebf7d2e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 11 Aug 2011 20:37:21 -0500 Subject: [PATCH 10/11] If both the username and the email checks fail, warn about both at the same time --- mediagoblin/auth/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 91599e47..ce6b5dfc 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -50,14 +50,18 @@ def register(request): users_with_email = request.db.User.find( {'email': request.POST['email'].lower()}).count() + extra_validation_passes = True + if users_with_username: register_form.username.errors.append( _(u'Sorry, a user with that name already exists.')) - elif users_with_email: + extra_validation_passes = False + if users_with_email: register_form.email.errors.append( _(u'Sorry, that email address has already been taken.')) + extra_validation_passes = False - else: + if extra_validation_passes: # Create the user user = request.db.User() user['username'] = request.POST['username'].lower() From 788272f30034fb2f917496197e317226d21aad2e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 11 Aug 2011 22:44:47 -0500 Subject: [PATCH 11/11] PEP-8ing the keyword argument passing here --- mediagoblin/auth/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 55f42141..9120196f 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -166,7 +166,7 @@ def verify_email(request): return redirect( request, 'mediagoblin.user_pages.user_home', - user = user['username']) + user=user['username']) def resend_activation(request):