From e323a06851cf2a5c7f26d4a969185323c20c8d9d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 19 Apr 2011 19:05:46 -0500 Subject: Start of the submit view, but not much there quite yet. --- mediagoblin/submit/__init__.py | 0 mediagoblin/submit/forms.py | 26 ++++++++++++++++++++++++++ mediagoblin/submit/routing.py | 22 ++++++++++++++++++++++ mediagoblin/submit/views.py | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 mediagoblin/submit/__init__.py create mode 100644 mediagoblin/submit/forms.py create mode 100644 mediagoblin/submit/routing.py create mode 100644 mediagoblin/submit/views.py (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/__init__.py b/mediagoblin/submit/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py new file mode 100644 index 00000000..fe51e7fd --- /dev/null +++ b/mediagoblin/submit/forms.py @@ -0,0 +1,26 @@ +# 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 . + + +import wtforms + + +class SubmitStartForm(wtforms.Form): + title = wtforms.TextField( + 'Title', + [wtforms.validators.Length(min=1, max=500)]) + description = wtforms.TextAreaField('Description of this work') + file = wtforms.FileField('File') diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py new file mode 100644 index 00000000..b2713540 --- /dev/null +++ b/mediagoblin/submit/routing.py @@ -0,0 +1,22 @@ +# 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 . + +from routes.route import Route + +submit_routes = [ + Route('mediagoblin.submit.start', '/', + controller='mediagoblin.submit.views:submit_start'), + ] diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py new file mode 100644 index 00000000..aa0f8121 --- /dev/null +++ b/mediagoblin/submit/views.py @@ -0,0 +1,37 @@ +# 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 . + + +from webob import Response, exc + +from mediagoblin.decorators import require_active_login +from mediagoblin.submit import forms as submit_forms + + +@require_active_login +def submit_start(request): + """ + First view for submitting a file. + """ + submit_form = submit_forms.SubmitStartForm() + + # render + template = request.template_env.get_template( + 'mediagoblin/submit/start.html') + return Response( + template.render( + {'request': request, + 'submit_form': submit_form})) -- cgit v1.2.3 From f6f524bf5990c116d59868dd0edeafcc1ba58e09 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 23 Apr 2011 12:56:01 -0500 Subject: submit_start written in a way that, by golly, you'd think maybe it'd work --- mediagoblin/submit/views.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index aa0f8121..1d93e070 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -16,6 +16,7 @@ from webob import Response, exc +from werkzeug.utils import secure_filename from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms @@ -28,6 +29,39 @@ def submit_start(request): """ submit_form = submit_forms.SubmitStartForm() + if request.method == 'POST' and submit_form.validate(): + # create entry and save in database + entry = request.db.MediaEntry() + entry['title'] = request.POST['title'] + entry['description'] = request.POST.get(['description']) + entry['media_type'] = u'image' # heh + entry['uploader'] = request.user + + # Save, just so we can get the entry id for the sake of using + # it to generate the file path + entry.save(validate=False) + + # Now store generate the queueing related filename + queue_filepath = request.app.queue_store.get_unique_filepath( + ['media_entries', + unicode(request.user['_id']), + unicode(entry['_id']), + secure_filename(request.POST['file'].filename)]) + + # queue appropriately + queue_file = request.app.queue_store.get_file( + queue_filepath, 'wb') + + queue_file.write(request.POST['file'].file.read()) + + # Add queued filename to the entry + entry.setdefault('queue_files', []).add(queue_filepath) + entry.save(validate=True) + + # redirect + return exc.HTTPFound( + location=request.urlgen("mediagoblin.submit.submit_success")) + # render template = request.template_env.get_template( 'mediagoblin/submit/start.html') @@ -35,3 +69,13 @@ def submit_start(request): template.render( {'request': request, 'submit_form': submit_form})) + + +@require_active_login +def submit_success(request): + # render + template = request.template_env.get_template( + 'mediagoblin/submit/success.html') + return Response( + template.render( + {'request': request})) -- cgit v1.2.3 From 2732c28676f1bd36c17bd1afe30cdd3cae3ceb59 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 23 Apr 2011 13:06:27 -0500 Subject: A stupid success view. --- mediagoblin/submit/routing.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index b2713540..3f61b1f4 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -19,4 +19,6 @@ from routes.route import Route submit_routes = [ Route('mediagoblin.submit.start', '/', controller='mediagoblin.submit.views:submit_start'), + Route('mediagoblin.submit.success', '/', + controller='mediagoblin.submit.views:submit_success'), ] -- cgit v1.2.3 From e21e7bfeb41a8ed6ab8fa3b27132efd84355ff36 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 23 Apr 2011 13:15:09 -0500 Subject: Enclose queue_file writing in with statement so that it's closed correctly. --- mediagoblin/submit/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1d93e070..54201796 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -52,7 +52,8 @@ def submit_start(request): queue_file = request.app.queue_store.get_file( queue_filepath, 'wb') - queue_file.write(request.POST['file'].file.read()) + with queue_file: + queue_file.write(request.POST['file'].file.read()) # Add queued filename to the entry entry.setdefault('queue_files', []).add(queue_filepath) -- cgit v1.2.3 From 204392362ffbe94159838cdff6c4d3b6968a003d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 23 Apr 2011 13:29:15 -0500 Subject: Submission of image works :) /me pours some sparkling grape juice --- mediagoblin/submit/routing.py | 2 +- mediagoblin/submit/views.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index 3f61b1f4..cff28acb 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -19,6 +19,6 @@ from routes.route import Route submit_routes = [ Route('mediagoblin.submit.start', '/', controller='mediagoblin.submit.views:submit_start'), - Route('mediagoblin.submit.success', '/', + Route('mediagoblin.submit.success', '/success/', controller='mediagoblin.submit.views:submit_success'), ] diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 54201796..1f55336f 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -27,7 +27,7 @@ def submit_start(request): """ First view for submitting a file. """ - submit_form = submit_forms.SubmitStartForm() + submit_form = submit_forms.SubmitStartForm(request.POST) if request.method == 'POST' and submit_form.validate(): # create entry and save in database @@ -56,12 +56,12 @@ def submit_start(request): queue_file.write(request.POST['file'].file.read()) # Add queued filename to the entry - entry.setdefault('queue_files', []).add(queue_filepath) + entry.setdefault('queue_files', []).append(queue_filepath) entry.save(validate=True) # redirect return exc.HTTPFound( - location=request.urlgen("mediagoblin.submit.submit_success")) + location=request.urlgen("mediagoblin.submit.success")) # render template = request.template_env.get_template( @@ -72,7 +72,6 @@ def submit_start(request): 'submit_form': submit_form})) -@require_active_login def submit_success(request): # render template = request.template_env.get_template( -- cgit v1.2.3 From 03afc828ce11523c46d81c1fa4667ec9604ef528 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 23 Apr 2011 14:13:33 -0500 Subject: Properly require files when users submit --- mediagoblin/submit/views.py | 72 +++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 32 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1f55336f..926c7011 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -15,6 +15,8 @@ # along with this program. If not, see . +from cgi import FieldStorage + from webob import Response, exc from werkzeug.utils import secure_filename @@ -30,38 +32,44 @@ def submit_start(request): submit_form = submit_forms.SubmitStartForm(request.POST) if request.method == 'POST' and submit_form.validate(): - # create entry and save in database - entry = request.db.MediaEntry() - entry['title'] = request.POST['title'] - entry['description'] = request.POST.get(['description']) - entry['media_type'] = u'image' # heh - entry['uploader'] = request.user - - # Save, just so we can get the entry id for the sake of using - # it to generate the file path - entry.save(validate=False) - - # Now store generate the queueing related filename - queue_filepath = request.app.queue_store.get_unique_filepath( - ['media_entries', - unicode(request.user['_id']), - unicode(entry['_id']), - secure_filename(request.POST['file'].filename)]) - - # queue appropriately - queue_file = request.app.queue_store.get_file( - queue_filepath, 'wb') - - with queue_file: - queue_file.write(request.POST['file'].file.read()) - - # Add queued filename to the entry - entry.setdefault('queue_files', []).append(queue_filepath) - entry.save(validate=True) - - # redirect - return exc.HTTPFound( - location=request.urlgen("mediagoblin.submit.success")) + if not (request.POST.has_key('file') + and isinstance(request.POST['file'], FieldStorage) + and request.POST['file'].file): + submit_form.file.errors.append( + u'You must provide a file.') + else: + # create entry and save in database + entry = request.db.MediaEntry() + entry['title'] = request.POST['title'] + entry['description'] = request.POST.get(['description']) + entry['media_type'] = u'image' # heh + entry['uploader'] = request.user + + # Save, just so we can get the entry id for the sake of using + # it to generate the file path + entry.save(validate=False) + + # Now store generate the queueing related filename + queue_filepath = request.app.queue_store.get_unique_filepath( + ['media_entries', + unicode(request.user['_id']), + unicode(entry['_id']), + secure_filename(request.POST['file'].filename)]) + + # queue appropriately + queue_file = request.app.queue_store.get_file( + queue_filepath, 'wb') + + with queue_file: + queue_file.write(request.POST['file'].file.read()) + + # Add queued filename to the entry + entry.setdefault('queue_files', []).append(queue_filepath) + entry.save(validate=True) + + # redirect + return exc.HTTPFound( + location=request.urlgen("mediagoblin.submit.success")) # render template = request.template_env.get_template( -- cgit v1.2.3 From fa7f9c6184286f2b56f353b21ffaf1e1577569a3 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 6 May 2011 09:37:24 -0500 Subject: Process media! Successfully! --- mediagoblin/submit/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 926c7011..9c4eb3a4 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -22,6 +22,7 @@ from werkzeug.utils import secure_filename from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms +from mediagoblin.process_media import process_media_initial @require_active_login @@ -52,7 +53,6 @@ def submit_start(request): # Now store generate the queueing related filename queue_filepath = request.app.queue_store.get_unique_filepath( ['media_entries', - unicode(request.user['_id']), unicode(entry['_id']), secure_filename(request.POST['file'].filename)]) @@ -64,9 +64,12 @@ def submit_start(request): queue_file.write(request.POST['file'].file.read()) # Add queued filename to the entry - entry.setdefault('queue_files', []).append(queue_filepath) + entry['queued_media_file'] = queue_filepath entry.save(validate=True) + # queue it for processing + process_media_initial.delay(unicode(entry['_id'])) + # redirect return exc.HTTPFound( location=request.urlgen("mediagoblin.submit.success")) -- cgit v1.2.3 From ec61f094926c7d64bd76f7d4dc79ce859d6f60ef Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Mon, 9 May 2011 00:23:12 +0200 Subject: Fix description submission in form handling When we submitted an image the description would remain empty. THis was because of some weird typo in form handling. Get an attribute with .get('description') and not with .get(['description']). With this patch, descriptions actually go into the database. Signed-off-by: Sebastian Spaeth --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 9c4eb3a4..5e262f12 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -42,7 +42,7 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() entry['title'] = request.POST['title'] - entry['description'] = request.POST.get(['description']) + entry['description'] = request.POST.get('description') entry['media_type'] = u'image' # heh entry['uploader'] = request.user -- cgit v1.2.3 From bb49e56f8c855ea567d61ad63f93610b31d4eb27 Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Mon, 9 May 2011 00:06:38 -0400 Subject: On image submission, do not require title. If none entered, default to filename. --- mediagoblin/submit/forms.py | 2 +- mediagoblin/submit/views.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index fe51e7fd..51ca349d 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -21,6 +21,6 @@ import wtforms class SubmitStartForm(wtforms.Form): title = wtforms.TextField( 'Title', - [wtforms.validators.Length(min=1, max=500)]) + [wtforms.validators.Length(min=-1, max=500)]) description = wtforms.TextAreaField('Description of this work') file = wtforms.FileField('File') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 5e262f12..1b28e339 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - +from os.path import splitext from cgi import FieldStorage from webob import Response, exc @@ -39,9 +39,11 @@ def submit_start(request): submit_form.file.errors.append( u'You must provide a file.') else: + filename = request.POST['file'].filename + # create entry and save in database entry = request.db.MediaEntry() - entry['title'] = request.POST['title'] + entry['title'] = request.POST['title'] or unicode(splitext(filename)[0]) entry['description'] = request.POST.get('description') entry['media_type'] = u'image' # heh entry['uploader'] = request.user @@ -54,7 +56,7 @@ def submit_start(request): queue_filepath = request.app.queue_store.get_unique_filepath( ['media_entries', unicode(entry['_id']), - secure_filename(request.POST['file'].filename)]) + secure_filename(filename)]) # queue appropriately queue_file = request.app.queue_store.get_file( -- cgit v1.2.3 From a8e2812b054f49e4085bf6b8c0b9e0c5f1b8d312 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 12 May 2011 23:40:47 -0500 Subject: min=0 makes more sense than min=-1 --- mediagoblin/submit/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 51ca349d..3fd9ea49 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -21,6 +21,6 @@ import wtforms class SubmitStartForm(wtforms.Form): title = wtforms.TextField( 'Title', - [wtforms.validators.Length(min=-1, max=500)]) + [wtforms.validators.Length(min=0, max=500)]) description = wtforms.TextAreaField('Description of this work') file = wtforms.FileField('File') -- cgit v1.2.3 From 0546833c6ea4dcaaa82861819916760dd62d8fa7 Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Fri, 13 May 2011 12:18:52 -0400 Subject: Generate unique slugs for newly submitted images. --- mediagoblin/submit/views.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1b28e339..95a416e2 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -52,6 +52,9 @@ def submit_start(request): # it to generate the file path entry.save(validate=False) + # Generate a slug from the title + entry.generate_slug() + # Now store generate the queueing related filename queue_filepath = request.app.queue_store.get_unique_filepath( ['media_entries', -- cgit v1.2.3 From 16509be160470202147d3b711126c7928790777d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 22 May 2011 16:06:45 -0500 Subject: Update all the views so that they use the uploader reference instead of uploader embedding --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 95a416e2..262f2b12 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -46,7 +46,7 @@ def submit_start(request): entry['title'] = request.POST['title'] or unicode(splitext(filename)[0]) entry['description'] = request.POST.get('description') entry['media_type'] = u'image' # heh - entry['uploader'] = request.user + entry['uploader'] = request.user['_id'] # Save, just so we can get the entry id for the sake of using # it to generate the file path -- cgit v1.2.3 From 5603d4df8fcf1a7a5b85906dad0049d7e79cce6c Mon Sep 17 00:00:00 2001 From: Jakob Kramer Date: Thu, 2 Jun 2011 17:35:20 +0200 Subject: should fix #324 --- mediagoblin/submit/security.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 mediagoblin/submit/security.py (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/security.py b/mediagoblin/submit/security.py new file mode 100644 index 00000000..db4c860d --- /dev/null +++ b/mediagoblin/submit/security.py @@ -0,0 +1,32 @@ +# 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 . + +from mimetypes import guess_type + +from Image import open as image_open + +ALLOWED = ['image/jpeg', 'image/png', 'image/tiff', 'image/gif'] + +def check_filetype(posted_file): + if not guess_type(posted_file.filename) in ALLOWED: + return False + + try: + image = image_open(posted_file.file) + except IOError: + return False + + return True -- cgit v1.2.3 From 3eeadc922a669af9b4df4a41dc464bf6587802c1 Mon Sep 17 00:00:00 2001 From: Jakob Kramer Date: Thu, 2 Jun 2011 17:47:38 +0200 Subject: add changes in mediagoblin/submit/views.py --- mediagoblin/submit/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 262f2b12..5ddf992f 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -21,7 +21,7 @@ from webob import Response, exc from werkzeug.utils import secure_filename from mediagoblin.decorators import require_active_login -from mediagoblin.submit import forms as submit_forms +from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media_initial @@ -38,6 +38,9 @@ def submit_start(request): and request.POST['file'].file): submit_form.file.errors.append( u'You must provide a file.') + elif not security.check_filetype(request.POST['file']): + submit_form.file.errors.append( + u'The file doesn\'t seem to be an image!') else: filename = request.POST['file'].filename -- cgit v1.2.3 From b5d3aec615fd32439c9fc708d2266dc1cdfecc9d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 4 Jun 2011 17:36:36 -0500 Subject: Moving all views over to using util.render_template()! --- mediagoblin/submit/views.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 262f2b12..256f5be9 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -20,6 +20,7 @@ from cgi import FieldStorage from webob import Response, exc from werkzeug.utils import secure_filename +from mediagoblin.util import render_template from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms from mediagoblin.process_media import process_media_initial @@ -80,18 +81,14 @@ def submit_start(request): location=request.urlgen("mediagoblin.submit.success")) # render - template = request.template_env.get_template( - 'mediagoblin/submit/start.html') return Response( - template.render( - {'request': request, - 'submit_form': submit_form})) + render_template( + request, 'mediagoblin/submit/start.html', + {'submit_form': submit_form})) def submit_success(request): # render - template = request.template_env.get_template( - 'mediagoblin/submit/success.html') return Response( - template.render( - {'request': request})) + render_template( + request, 'mediagoblin/submit/success.html', {})) -- cgit v1.2.3 From 1c63ad5d352f5eb38a4d634b9aea84cbeee269a4 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 5 Jun 2011 15:25:45 +0200 Subject: Create render_to_reponse and use it everywhere. Just a shortcut for Response(render_template(...)) --- mediagoblin/submit/views.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 256f5be9..a51e14e6 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -17,10 +17,10 @@ from os.path import splitext from cgi import FieldStorage -from webob import Response, exc +from webob import exc from werkzeug.utils import secure_filename -from mediagoblin.util import render_template +from mediagoblin.util import render_to_response from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms from mediagoblin.process_media import process_media_initial @@ -81,14 +81,12 @@ def submit_start(request): location=request.urlgen("mediagoblin.submit.success")) # render - return Response( - render_template( + return render_to_response( request, 'mediagoblin/submit/start.html', - {'submit_form': submit_form})) + {'submit_form': submit_form}) def submit_success(request): # render - return Response( - render_template( - request, 'mediagoblin/submit/success.html', {})) + return render_to_response( + request, 'mediagoblin/submit/success.html', {}) -- cgit v1.2.3 From c9c24934357300c436ac63531f91b7608f80fd21 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 5 Jun 2011 16:02:12 +0200 Subject: Reformat render_to_response calls Just a simple indentation and ordering change, no functional change. --- mediagoblin/submit/views.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index a51e14e6..95257b72 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -80,13 +80,11 @@ def submit_start(request): return exc.HTTPFound( location=request.urlgen("mediagoblin.submit.success")) - # render - return render_to_response( - request, 'mediagoblin/submit/start.html', - {'submit_form': submit_form}) + return render_to_response(request, + 'mediagoblin/submit/start.html', + {'submit_form': submit_form}) def submit_success(request): - # render - return render_to_response( - request, 'mediagoblin/submit/success.html', {}) + return render_to_response(request, + 'mediagoblin/submit/success.html', {}) -- cgit v1.2.3 From 9150244afa45628dd752a67272129d30d6c72224 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 5 Jun 2011 15:49:08 +0200 Subject: Create redirect shortcut and use it around This is just replacing exc.HTTPFound(location=request.urlgen(...)) by redirect(request, ...). No magic. --- mediagoblin/submit/views.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 95257b72..d4ecc75a 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -17,10 +17,9 @@ from os.path import splitext from cgi import FieldStorage -from webob import exc from werkzeug.utils import secure_filename -from mediagoblin.util import render_to_response +from mediagoblin.util import render_to_response, redirect from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms from mediagoblin.process_media import process_media_initial @@ -76,9 +75,7 @@ def submit_start(request): # queue it for processing process_media_initial.delay(unicode(entry['_id'])) - # redirect - return exc.HTTPFound( - location=request.urlgen("mediagoblin.submit.success")) + return redirect(request, "mediagoblin.submit.success") return render_to_response(request, 'mediagoblin/submit/start.html', -- cgit v1.2.3 From 9038c9f9acc4cfa257a52def2b292e6142e7d86a Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 5 Jun 2011 15:41:08 -0500 Subject: I have a strong preference for aligning all parameters in a function call. --- mediagoblin/submit/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index d4ecc75a..b409b64d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -77,11 +77,12 @@ def submit_start(request): return redirect(request, "mediagoblin.submit.success") - return render_to_response(request, + return render_to_response( + request, 'mediagoblin/submit/start.html', {'submit_form': submit_form}) def submit_success(request): - return render_to_response(request, - 'mediagoblin/submit/success.html', {}) + return render_to_response( + request, 'mediagoblin/submit/success.html', {}) -- cgit v1.2.3 From 2262b2a9e1aad834bce8782216c3d8068a008618 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 5 Jun 2011 15:58:35 -0500 Subject: Made a simple template rendering view and switched a bunch of code over to using it --- mediagoblin/submit/routing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index cff28acb..3edbab70 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -20,5 +20,5 @@ submit_routes = [ Route('mediagoblin.submit.start', '/', controller='mediagoblin.submit.views:submit_start'), Route('mediagoblin.submit.success', '/success/', - controller='mediagoblin.submit.views:submit_success'), - ] + template='mediagoblin/submit/success.html', + controller='mediagoblin.views:simple_template_render')] -- cgit v1.2.3 From fe4ffb860fcf211406861a726c64439435964f4c Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 6 Jun 2011 07:57:05 -0500 Subject: Added a comment to clarify that this shouldn't stay here. --- mediagoblin/submit/security.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/security.py b/mediagoblin/submit/security.py index db4c860d..5a06a499 100644 --- a/mediagoblin/submit/security.py +++ b/mediagoblin/submit/security.py @@ -24,6 +24,8 @@ def check_filetype(posted_file): if not guess_type(posted_file.filename) in ALLOWED: return False + # TODO: This should be handled by the processing stage. We should + # handle error detection there. try: image = image_open(posted_file.file) except IOError: -- cgit v1.2.3 From eb21f9a6cb24adeeea10e26442f92a968a38c53e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 7 Jun 2011 00:36:24 -0500 Subject: Fixing check_filetype... We need to check the first part of the guess_type returned tuple, and also this try: except: doesn't belong here, so killing. --- mediagoblin/submit/security.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/security.py b/mediagoblin/submit/security.py index 5a06a499..b2cb6d88 100644 --- a/mediagoblin/submit/security.py +++ b/mediagoblin/submit/security.py @@ -16,19 +16,11 @@ from mimetypes import guess_type -from Image import open as image_open ALLOWED = ['image/jpeg', 'image/png', 'image/tiff', 'image/gif'] def check_filetype(posted_file): - if not guess_type(posted_file.filename) in ALLOWED: - return False - - # TODO: This should be handled by the processing stage. We should - # handle error detection there. - try: - image = image_open(posted_file.file) - except IOError: + if not guess_type(posted_file.filename)[0] in ALLOWED: return False return True -- cgit v1.2.3 From 44e2da2fe60a3b8765d0fef5a9ce0c3e5997dd01 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 12 Jun 2011 03:24:31 +0200 Subject: Added Markdown rendering for `media_entry` --- mediagoblin/submit/views.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index e9b5c37e..21562e6f 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -48,6 +48,13 @@ def submit_start(request): entry = request.db.MediaEntry() entry['title'] = request.POST['title'] or unicode(splitext(filename)[0]) entry['description'] = request.POST.get('description') + + import markdown + md = markdown.Markdown( + safe_mode = 'escape') + entry['description_html'] = md.convert( + entry['description']) + entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] -- cgit v1.2.3 From 44e51d3464e719e596e1480b7af2957742a9085b Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Wed, 15 Jun 2011 23:07:54 +0200 Subject: Made changes according to http://bugs.foocorp.net/issues/363#note-5 --- mediagoblin/submit/views.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 21562e6f..437a5a51 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -19,11 +19,13 @@ from cgi import FieldStorage from werkzeug.utils import secure_filename -from mediagoblin.util import render_to_response, redirect +from mediagoblin.util import render_to_response, redirect, clean_html from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media_initial +import markdown + @require_active_login def submit_start(request): @@ -49,11 +51,11 @@ def submit_start(request): entry['title'] = request.POST['title'] or unicode(splitext(filename)[0]) entry['description'] = request.POST.get('description') - import markdown md = markdown.Markdown( safe_mode = 'escape') - entry['description_html'] = md.convert( - entry['description']) + entry['description_html'] = clean_html( + md.convert( + entry['description'])) entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] -- cgit v1.2.3 From 4bf8e8888c7df6717eb43487136cc9d5c155bc6c Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 19 Jun 2011 20:41:40 -0500 Subject: Adds util.cleaned_markdown_conversion() and uses it in the submission process This simplifies the markdown processing & html cleaning of descritions and etc by providing a wrapper function that we can use in multiple locations. --- mediagoblin/submit/views.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 437a5a51..6139614e 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -19,13 +19,12 @@ from cgi import FieldStorage from werkzeug.utils import secure_filename -from mediagoblin.util import render_to_response, redirect, clean_html +from mediagoblin.util import ( + render_to_response, redirect, cleaned_markdown_conversion) from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media_initial -import markdown - @require_active_login def submit_start(request): @@ -48,14 +47,13 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() - entry['title'] = request.POST['title'] or unicode(splitext(filename)[0]) + entry['title'] = ( + request.POST['title'] + or unicode(splitext(filename)[0])) + entry['description'] = request.POST.get('description') - - md = markdown.Markdown( - safe_mode = 'escape') - entry['description_html'] = clean_html( - md.convert( - entry['description'])) + entry['description_html'] = cleaned_markdown_conversion( + entry['description']) entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] -- cgit v1.2.3 From 4dc7444119f81d1858a2f31457f3a86af1f6a72d Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 3 Jul 2011 07:50:35 +0200 Subject: Feature #409 - Submitting an image should redirect you back to user's page w/ a message * Successful submission redirects to the logged in user's page (your own, presumably). * "Woohoo! Submitted!" is launched into the tube of session messages to appear on next pageload. If you're not aborting in the window of 210ms it takes for the client to respond to the 302 and load the logged in user's/your page that is, YMMV. --- mediagoblin/submit/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 6139614e..4c7476b0 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -24,6 +24,7 @@ from mediagoblin.util import ( from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media_initial +from mediagoblin.messages import add_message, SUCCESS @require_active_login @@ -85,7 +86,10 @@ def submit_start(request): # queue it for processing process_media_initial.delay(unicode(entry['_id'])) - return redirect(request, "mediagoblin.submit.success") + add_message(request, SUCCESS, 'Woohoo! Submitted!') + + return redirect(request, "mediagoblin.user_pages.user_home", + user = request.user['username']) return render_to_response( request, -- cgit v1.2.3 From 04a95150646247abd13992b5c103a6d780d8861b Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Fri, 8 Jul 2011 01:59:44 -0500 Subject: F360(tagging) - adds tag fields for submission, edit and display --- mediagoblin/submit/forms.py | 1 + mediagoblin/submit/views.py | 2 ++ 2 files changed, 3 insertions(+) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 3fd9ea49..0e0fd086 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -24,3 +24,4 @@ class SubmitStartForm(wtforms.Form): [wtforms.validators.Length(min=0, max=500)]) description = wtforms.TextAreaField('Description of this work') file = wtforms.FileField('File') + tags = wtforms.TextField('Tags') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 4c7476b0..cdd58786 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -16,6 +16,7 @@ from os.path import splitext from cgi import FieldStorage +from string import split from werkzeug.utils import secure_filename @@ -58,6 +59,7 @@ def submit_start(request): entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] + entry['tags'] = split(request.POST.get('tags')) # Save, just so we can get the entry id for the sake of using # it to generate the file path -- cgit v1.2.3 From eedc5428fd4fa775405084c74baa186d9c41efda Mon Sep 17 00:00:00 2001 From: Rasmus Larsson Date: Sat, 9 Jul 2011 02:47:06 +0200 Subject: Removed route, view and template file for "Submit Success" page --- mediagoblin/submit/routing.py | 5 +---- mediagoblin/submit/views.py | 5 ----- 2 files changed, 1 insertion(+), 9 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index 3edbab70..5585ecb0 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -18,7 +18,4 @@ from routes.route import Route submit_routes = [ Route('mediagoblin.submit.start', '/', - controller='mediagoblin.submit.views:submit_start'), - Route('mediagoblin.submit.success', '/success/', - template='mediagoblin/submit/success.html', - controller='mediagoblin.views:simple_template_render')] + controller='mediagoblin.submit.views:submit_start')] diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 4c7476b0..1848f5e5 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -95,8 +95,3 @@ def submit_start(request): request, 'mediagoblin/submit/start.html', {'submit_form': submit_form}) - - -def submit_success(request): - return render_to_response( - request, 'mediagoblin/submit/success.html', {}) -- cgit v1.2.3 From cdf538bd6163a47b4c4a6326c943b6deaf2c495a Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Tue, 12 Jul 2011 20:06:17 -0500 Subject: adds filter function to parse and clean tags field input - for some reason the tags are showing up in the media edit form with u'..' and surrounded with []. I don't know why, grr --- mediagoblin/submit/forms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 0e0fd086..e13d5425 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -17,6 +17,8 @@ import wtforms +from mediagoblin.util import convert_to_tag_list + class SubmitStartForm(wtforms.Form): title = wtforms.TextField( @@ -24,4 +26,4 @@ class SubmitStartForm(wtforms.Form): [wtforms.validators.Length(min=0, max=500)]) description = wtforms.TextAreaField('Description of this work') file = wtforms.FileField('File') - tags = wtforms.TextField('Tags') + tags = wtforms.TextField('Tags', filters=[convert_to_tag_list]) -- cgit v1.2.3 From 6f2e4585cc7475362205a9ddb0e69d6da2b6dc85 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Tue, 12 Jul 2011 22:26:10 -0500 Subject: uses standard functions instead of form filters and fixes taglist default - seems simpler to use the same tag field processing procedures on media submit and edit, so now processing with a regular function instead of a form filter. Filters run on form load and post by default. - moved tags to sidebar - taglist defaults to [] instead of None - adds case sensitivity toggle --- mediagoblin/submit/forms.py | 4 +--- mediagoblin/submit/views.py | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index e13d5425..0e0fd086 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -17,8 +17,6 @@ import wtforms -from mediagoblin.util import convert_to_tag_list - class SubmitStartForm(wtforms.Form): title = wtforms.TextField( @@ -26,4 +24,4 @@ class SubmitStartForm(wtforms.Form): [wtforms.validators.Length(min=0, max=500)]) description = wtforms.TextAreaField('Description of this work') file = wtforms.FileField('File') - tags = wtforms.TextField('Tags', filters=[convert_to_tag_list]) + tags = wtforms.TextField('Tags') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index cdd58786..46ec4cea 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -21,7 +21,8 @@ from string import split from werkzeug.utils import secure_filename from mediagoblin.util import ( - render_to_response, redirect, cleaned_markdown_conversion) + render_to_response, redirect, cleaned_markdown_conversion, \ + convert_to_tag_list) from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media_initial @@ -59,7 +60,7 @@ def submit_start(request): entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] - entry['tags'] = split(request.POST.get('tags')) + entry['tags'] = convert_to_tag_list(request.POST.get('tags')) # Save, just so we can get the entry id for the sake of using # it to generate the file path -- cgit v1.2.3 From cc7ff3c50513ae169abab196f32de97af30e6744 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Tue, 12 Jul 2011 23:58:25 -0500 Subject: enforces maximum tag length with (in)appropriate messaging --- mediagoblin/submit/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 46ec4cea..bda77b1d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -60,7 +60,9 @@ def submit_start(request): entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] - entry['tags'] = convert_to_tag_list(request.POST.get('tags')) + + # Process the user's folksonomy "tags" + entry['tags'] = convert_to_tag_list(request) # Save, just so we can get the entry id for the sake of using # it to generate the file path -- cgit v1.2.3 From 909371cdceace162af880c275b9e6e70488e3029 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Wed, 20 Jul 2011 23:54:32 -0500 Subject: raises tag length error in form context instead of in message queue --- mediagoblin/submit/forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 0e0fd086..1a5a7f4e 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -16,6 +16,7 @@ import wtforms +from mediagoblin.util import tag_length_validator, TOO_LONG_TAG_WARNING class SubmitStartForm(wtforms.Form): @@ -24,4 +25,6 @@ class SubmitStartForm(wtforms.Form): [wtforms.validators.Length(min=0, max=500)]) description = wtforms.TextAreaField('Description of this work') file = wtforms.FileField('File') - tags = wtforms.TextField('Tags') + tags = wtforms.TextField( + 'Tags', + [tag_length_validator]) -- cgit v1.2.3 From 6b9ee0ca13b99ee20f9d0c680a950c6a7494a5a0 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 24 Jul 2011 23:12:46 -0500 Subject: Store the task id of a processing action in the database. --- mediagoblin/submit/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1848f5e5..f19bf22e 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -84,7 +84,8 @@ def submit_start(request): entry.save(validate=True) # queue it for processing - process_media_initial.delay(unicode(entry['_id'])) + result = process_media_initial.delay(unicode(entry['_id'])) + entry['queued_task_id'] = result.task_id add_message(request, SUCCESS, 'Woohoo! Submitted!') -- cgit v1.2.3 From 97e4498c10c803c9d239011d4c48efef52673ec3 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Mon, 25 Jul 2011 23:48:51 -0500 Subject: on submission, use inline error messaging instead of message queue - the function that converts the user's tag string into a list of tags now accepts a string, but the media submit view was still submitting the request object, like we were going to add any errors to the session. Now the submit view passes the tag string --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index bda77b1d..edde4400 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -62,7 +62,7 @@ def submit_start(request): entry['uploader'] = request.user['_id'] # Process the user's folksonomy "tags" - entry['tags'] = convert_to_tag_list(request) + entry['tags'] = convert_to_tag_list(request.POST.get('tags')) # Save, just so we can get the entry id for the sake of using # it to generate the file path -- cgit v1.2.3 From 0712a06dc6d6b05cb78d4b10af12c051e8f765e3 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Wed, 27 Jul 2011 14:42:09 -0500 Subject: changes tags to a list of dicts in the db, adding tag slugs - adds a function to convert the tag list of dicts to a text string properly delimited for loading into forms - tag string conversion function updated to generate list of dicts - updates all mentions of the conversion of the string to the tags db object - adds a tags template utility and updates the media template accordingly --- mediagoblin/submit/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index edde4400..c5ac8c62 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -22,7 +22,7 @@ from werkzeug.utils import secure_filename from mediagoblin.util import ( render_to_response, redirect, cleaned_markdown_conversion, \ - convert_to_tag_list) + convert_to_tag_list_of_dicts) from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media_initial @@ -62,7 +62,8 @@ def submit_start(request): entry['uploader'] = request.user['_id'] # Process the user's folksonomy "tags" - entry['tags'] = convert_to_tag_list(request.POST.get('tags')) + entry['tags'] = convert_to_tag_list_of_dicts( + request.POST.get('tags')) # Save, just so we can get the entry id for the sake of using # it to generate the file path -- cgit v1.2.3 From fc3dc2554179b9e08209ed27a750bb581fe2d85c Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Wed, 27 Jul 2011 16:16:05 -0700 Subject: Adds license header --- mediagoblin/submit/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/__init__.py b/mediagoblin/submit/__init__.py index e69de29b..a8eeb5ed 100644 --- a/mediagoblin/submit/__init__.py +++ b/mediagoblin/submit/__init__.py @@ -0,0 +1,17 @@ +# 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 . + + -- cgit v1.2.3 From 3539dc8fb6cb59c6a52cb116e8993d73cd26f0d5 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 30 Jul 2011 21:44:36 -0500 Subject: TOO_LONG_TAG_WARNING isn't needed in this module --- mediagoblin/submit/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 1a5a7f4e..f02c95a6 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -16,7 +16,7 @@ import wtforms -from mediagoblin.util import tag_length_validator, TOO_LONG_TAG_WARNING +from mediagoblin.util import tag_length_validator class SubmitStartForm(wtforms.Form): -- cgit v1.2.3 From 2c4374938f05782cd8aceb789098f787d04adc51 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Fri, 5 Aug 2011 22:08:29 +0200 Subject: Feature #482 - Media attachments --- mediagoblin/submit/forms.py | 3 +++ mediagoblin/submit/views.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index f02c95a6..9b35a8c3 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -28,3 +28,6 @@ class SubmitStartForm(wtforms.Form): tags = wtforms.TextField( 'Tags', [tag_length_validator]) + attachment = wtforms.FileField( + 'Attachment', + [wtforms.validators.Optional()]) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 87e57dda..213b2494 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -14,6 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . + +import mediagoblin.mg_globals as mg_globals +from datetime import datetime + from os.path import splitext from cgi import FieldStorage from string import split @@ -72,6 +76,31 @@ def submit_start(request): # Generate a slug from the title entry.generate_slug() + # Add any attachements + if (mg_globals.app_config['allow_attachments'] + and request.POST.has_key('attachment') + and isinstance(request.POST['attachment'], FieldStorage) + and request.POST['attachment'].file): + + attachment_public_filepath = mg_globals.public_store.get_unique_filepath( + ['media_entries', + unicode('attachment-%s' % entry['_id']), + secure_filename(request.POST['attachment'].filename)]) + + attachment_public_file = mg_globals.public_store.get_file( + attachment_public_filepath, 'wb') + + try: + attachment_public_file.write(request.POST['attachment'].file.read()) + finally: + request.POST['attachment'].file.close() + + entry['attachment_files'] = [dict( + name=request.POST['attachment'].filename, + filepath=attachment_public_filepath, + created=datetime.utcnow() + )] + # Now store generate the queueing related filename queue_filepath = request.app.queue_store.get_unique_filepath( ['media_entries', @@ -100,4 +129,5 @@ def submit_start(request): return render_to_response( request, 'mediagoblin/submit/start.html', - {'submit_form': submit_form}) + {'submit_form': submit_form, + 'app_config': mg_globals.app_config}) -- cgit v1.2.3 From 4b1adc132cf45507e2f910122992230d428c6856 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 8 Aug 2011 22:53:39 -0500 Subject: Marked relevant strings in python views/forms for translation via ugettext --- mediagoblin/submit/forms.py | 8 +++++--- mediagoblin/submit/views.py | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index f02c95a6..ccb62a03 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -16,15 +16,17 @@ import wtforms + from mediagoblin.util import tag_length_validator +from mediagoblin.util import pass_to_ugettext as _ class SubmitStartForm(wtforms.Form): title = wtforms.TextField( - 'Title', + _('Title'), [wtforms.validators.Length(min=0, max=500)]) description = wtforms.TextAreaField('Description of this work') - file = wtforms.FileField('File') + file = wtforms.FileField(_('File')) tags = wtforms.TextField( - 'Tags', + _('Tags'), [tag_length_validator]) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 87e57dda..ba13b755 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -23,6 +23,7 @@ from werkzeug.utils import secure_filename from mediagoblin.util import ( render_to_response, redirect, cleaned_markdown_conversion, \ convert_to_tag_list_of_dicts) +from mediagoblin.util import pass_to_ugettext as _ from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media_initial @@ -41,10 +42,10 @@ def submit_start(request): and isinstance(request.POST['file'], FieldStorage) and request.POST['file'].file): submit_form.file.errors.append( - u'You must provide a file.') + _(u'You must provide a file.')) elif not security.check_filetype(request.POST['file']): submit_form.file.errors.append( - u'The file doesn\'t seem to be an image!') + _(u"The file doesn't seem to be an image!")) else: filename = request.POST['file'].filename @@ -92,7 +93,7 @@ def submit_start(request): # queue it for processing process_media_initial.delay(unicode(entry['_id'])) - add_message(request, SUCCESS, 'Woohoo! Submitted!') + add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", user = request.user['username']) -- cgit v1.2.3 From 7960ac985f9b5a80063f21012d53793cb2d22dd9 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 10 Aug 2011 12:07:59 -0500 Subject: Converting all forms to use the "fake/null" gettext conversion function Gettext doesn't actually get run right in the form but we do need to wrap the strings in _() so stuff extracts :) --- mediagoblin/submit/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index ccb62a03..241d32dc 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -18,7 +18,7 @@ import wtforms from mediagoblin.util import tag_length_validator -from mediagoblin.util import pass_to_ugettext as _ +from mediagoblin.util import fake_ugettext_passthrough as _ class SubmitStartForm(wtforms.Form): -- cgit v1.2.3 From d990a3799846a06ada11805ca4f2806eb1bf8b5e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 10 Aug 2011 20:26:22 -0500 Subject: We should save the entry *after* we add the queued_task_id. --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 59d8fe3f..53711236 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -88,11 +88,11 @@ def submit_start(request): # Add queued filename to the entry entry['queued_media_file'] = queue_filepath - entry.save(validate=True) # queue it for processing result = process_media_initial.delay(unicode(entry['_id'])) entry['queued_task_id'] = result.task_id + entry.save(validate=True) add_message(request, SUCCESS, _('Woohoo! Submitted!')) -- cgit v1.2.3 From f64e5250906401a3d5a5fc587521bc31e146859c Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 10 Aug 2011 21:03:16 -0500 Subject: Generate the ObjectId() manually instead of via .save() --- mediagoblin/submit/views.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index ba13b755..a3a58400 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -20,6 +20,7 @@ from string import split from werkzeug.utils import secure_filename +from mediagoblin.db.util import ObjectId from mediagoblin.util import ( render_to_response, redirect, cleaned_markdown_conversion, \ convert_to_tag_list_of_dicts) @@ -51,6 +52,7 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() + entry['_id'] = ObjectId() entry['title'] = ( request.POST['title'] or unicode(splitext(filename)[0])) @@ -66,10 +68,6 @@ def submit_start(request): entry['tags'] = convert_to_tag_list_of_dicts( request.POST.get('tags')) - # Save, just so we can get the entry id for the sake of using - # it to generate the file path - entry.save(validate=False) - # Generate a slug from the title entry.generate_slug() -- cgit v1.2.3 From f6bf68cae5f2907924e126a3a2f3a2f015292323 Mon Sep 17 00:00:00 2001 From: Caleb Forbes Davis V Date: Thu, 11 Aug 2011 00:50:16 -0500 Subject: 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') 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]) -- cgit v1.2.3 From 07934b442f7cd3abae18eecdf533de004f88e6b1 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 11 Aug 2011 11:30:26 -0500 Subject: Moving things around a bit/commenting in the submit view to make the workflow clearer --- mediagoblin/submit/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index d4858c87..1e8c6a68 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -87,9 +87,13 @@ def submit_start(request): # Add queued filename to the entry entry['queued_media_file'] = queue_filepath - # queue it for processing + # Save now so we have this data before kicking off processing + entry.save(validate=False) + result = process_media_initial.delay(unicode(entry['_id'])) - entry['queued_task_id'] = result.task_id + + # Save the task id + entry['queued_task_id'] = unicode(result.task_id) entry.save(validate=True) add_message(request, SUCCESS, _('Woohoo! Submitted!')) -- cgit v1.2.3 From 4a477e246d07a4c26f084db2596caf3310b78609 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 13 Aug 2011 10:59:34 -0500 Subject: Proper handling of processor failures, working as hoped! BaseProcessingFail based exceptions recorded and marked appropriately in the database. Other exceptions also caught and marked (or rather not marked) appropriately in the database as well. --- mediagoblin/submit/views.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1e8c6a68..25b3664b 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -14,9 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import uuid + from os.path import splitext from cgi import FieldStorage -from string import split from werkzeug.utils import secure_filename @@ -27,7 +28,7 @@ from mediagoblin.util import ( from mediagoblin.util import pass_to_ugettext as _ from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security -from mediagoblin.process_media import process_media_initial +from mediagoblin.process_media import process_media from mediagoblin.messages import add_message, SUCCESS @@ -87,15 +88,24 @@ def submit_start(request): # Add queued filename to the entry entry['queued_media_file'] = queue_filepath - # Save now so we have this data before kicking off processing - entry.save(validate=False) - - result = process_media_initial.delay(unicode(entry['_id'])) + # We generate this ourselves so we know what the taks id is for + # retrieval later. + # (If we got it off the task's auto-generation, there'd be a risk of + # a race condition when we'd save after sending off the task) + task_id = unicode(uuid.uuid4()) + entry['queued_task_id'] = task_id - # Save the task id - entry['queued_task_id'] = unicode(result.task_id) + # Save now so we have this data before kicking off processing entry.save(validate=True) + # Pass off to processing + # + # (... don't change entry after this point to avoid race + # conditions with changes to the document via processing code) + process_media.apply_async( + [unicode(entry['_id'])], {}, + task_id=task_id) + add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", -- cgit v1.2.3 From 6788b4123ef00241d6b6c80ca93d655e4307d6e3 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 13 Aug 2011 12:21:06 -0500 Subject: Capture and properly handle errors. Handled in several places: - In the run() of the ProcessMedia itself for handled (BaseProcessingFail derived) errors (best to do these not in on_failure because the errors are highlighted in celeryd in a way that looks inappropriate for when the errors are well handled) - In ProcessMedia.on_failure() for all other errors - In the submit view where all exceptions are caught, media is marked at having failed, then the error is re-raised. (The reason for this is that users running in "lazy" mode will get errors propagated by celery and so on_failure won't run for them.) --- mediagoblin/submit/views.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 25b3664b..1ba17954 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -28,7 +28,7 @@ from mediagoblin.util import ( from mediagoblin.util import pass_to_ugettext as _ from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security -from mediagoblin.process_media import process_media +from mediagoblin.process_media import process_media, mark_entry_failed from mediagoblin.messages import add_message, SUCCESS @@ -102,9 +102,22 @@ def submit_start(request): # # (... don't change entry after this point to avoid race # conditions with changes to the document via processing code) - process_media.apply_async( - [unicode(entry['_id'])], {}, - task_id=task_id) + try: + process_media.apply_async( + [unicode(entry['_id'])], {}, + task_id=task_id) + except BaseException as exc: + # The purpose of this section is because when running in "lazy" + # or always-eager-with-exceptions-propagated celery mode that + # the failure handling won't happen on Celery end. Since we + # expect a lot of users to run things in this way we have to + # capture stuff here. + # + # ... not completely the diaper pattern because the exception is + # re-raised :) + mark_entry_failed(entry[u'_id'], exc) + # re-raise the exception + raise add_message(request, SUCCESS, _('Woohoo! Submitted!')) -- cgit v1.2.3 From 08750772eaf140266d1be0aac5024f581664012b Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Mon, 22 Aug 2011 02:57:40 -0700 Subject: + 'confirm' section for confirmation dialogues + implemented delete functionality * fixed several instances of 'must be an instance of unicode, not str' --- mediagoblin/submit/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1ba17954..5bcc5393 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -55,10 +55,10 @@ def submit_start(request): entry = request.db.MediaEntry() entry['_id'] = ObjectId() entry['title'] = ( - request.POST['title'] + unicode(request.POST['title']) or unicode(splitext(filename)[0])) - entry['description'] = request.POST.get('description') + entry['description'] = unicode(request.POST.get('description')) entry['description_html'] = cleaned_markdown_conversion( entry['description']) -- cgit v1.2.3 From 3a8c3a38559f2f81d6155c2349fcddc5ecd6ef28 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Mon, 22 Aug 2011 18:06:28 +0200 Subject: Feature #482 - Media attachments - * Moved attachment uploading to separate view * Support for multiple attachments! --- mediagoblin/submit/forms.py | 3 --- mediagoblin/submit/views.py | 25 ------------------------- 2 files changed, 28 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 9b35a8c3..f02c95a6 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -28,6 +28,3 @@ class SubmitStartForm(wtforms.Form): tags = wtforms.TextField( 'Tags', [tag_length_validator]) - attachment = wtforms.FileField( - 'Attachment', - [wtforms.validators.Optional()]) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 213b2494..126cf3a8 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -76,31 +76,6 @@ def submit_start(request): # Generate a slug from the title entry.generate_slug() - # Add any attachements - if (mg_globals.app_config['allow_attachments'] - and request.POST.has_key('attachment') - and isinstance(request.POST['attachment'], FieldStorage) - and request.POST['attachment'].file): - - attachment_public_filepath = mg_globals.public_store.get_unique_filepath( - ['media_entries', - unicode('attachment-%s' % entry['_id']), - secure_filename(request.POST['attachment'].filename)]) - - attachment_public_file = mg_globals.public_store.get_file( - attachment_public_filepath, 'wb') - - try: - attachment_public_file.write(request.POST['attachment'].file.read()) - finally: - request.POST['attachment'].file.close() - - entry['attachment_files'] = [dict( - name=request.POST['attachment'].filename, - filepath=attachment_public_filepath, - created=datetime.utcnow() - )] - # Now store generate the queueing related filename queue_filepath = request.app.queue_store.get_unique_filepath( ['media_entries', -- cgit v1.2.3 From 12a100e4d8bdda7bd2353403a7e08e3a94669498 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Thu, 1 Sep 2011 20:49:54 -0400 Subject: 508. Updates copyright/license information --- mediagoblin/submit/__init__.py | 2 +- mediagoblin/submit/forms.py | 2 +- mediagoblin/submit/routing.py | 2 +- mediagoblin/submit/security.py | 2 +- mediagoblin/submit/views.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/__init__.py b/mediagoblin/submit/__init__.py index a8eeb5ed..576bd0f5 100644 --- a/mediagoblin/submit/__init__.py +++ b/mediagoblin/submit/__init__.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. # # 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 diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 4519b057..17df6be6 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. # # 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 diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index 5585ecb0..03e01f45 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. # # 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 diff --git a/mediagoblin/submit/security.py b/mediagoblin/submit/security.py index b2cb6d88..9d62a36e 100644 --- a/mediagoblin/submit/security.py +++ b/mediagoblin/submit/security.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. # # 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 diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index b9395145..e24d78f3 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. # # 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 -- cgit v1.2.3 From a237735a70fb7d4a4ffabbf09fdb8f104a24698d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 5 Sep 2011 18:19:24 -0500 Subject: Mark description field's label for translation --- mediagoblin/submit/forms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 17df6be6..a999c714 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -26,7 +26,8 @@ class SubmitStartForm(wtforms.Form): title = wtforms.TextField( _('Title'), [wtforms.validators.Length(min=0, max=500)]) - description = wtforms.TextAreaField('Description of this work') + description = wtforms.TextAreaField( + _('Description of this work')) tags = wtforms.TextField( _('Tags'), [tag_length_validator]) -- cgit v1.2.3 From 93bdab9daad3ae431afd41a2efaefae05a555d88 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Fri, 23 Sep 2011 02:35:57 +0200 Subject: Multimedia support - Commiting from a not yet finished state - Details below * DONE Initially testing with arista ** DONE Video display templates *** TODO Multi-browser support ** TODO Video thumbnails ** TODO Link to original video ** TODO Video cropping Also contains a lot of "debug" print's --- mediagoblin/submit/views.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index e24d78f3..78f52160 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -28,8 +28,9 @@ from mediagoblin.util import ( from mediagoblin.util import pass_to_ugettext as _ from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security -from mediagoblin.process_media import process_media, mark_entry_failed +from mediagoblin.process_media import mark_entry_failed from mediagoblin.messages import add_message, SUCCESS +from mediagoblin.media_types import get_media_type_and_manager @require_active_login @@ -45,15 +46,15 @@ def submit_start(request): and request.POST['file'].file): submit_form.file.errors.append( _(u'You must provide a file.')) - elif not security.check_filetype(request.POST['file']): - submit_form.file.errors.append( - _(u"The file doesn't seem to be an image!")) else: filename = request.POST['file'].filename + media_type, media_manager = get_media_type_and_manager(filename) + # create entry and save in database entry = request.db.MediaEntry() entry['_id'] = ObjectId() + entry['media_type'] = unicode(media_type) entry['title'] = ( unicode(request.POST['title']) or unicode(splitext(filename)[0])) @@ -62,7 +63,6 @@ def submit_start(request): entry['description_html'] = cleaned_markdown_conversion( entry['description']) - entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] # Process the user's folksonomy "tags" @@ -72,6 +72,7 @@ def submit_start(request): # Generate a slug from the title entry.generate_slug() + # Now store generate the queueing related filename queue_filepath = request.app.queue_store.get_unique_filepath( ['media_entries', @@ -103,7 +104,7 @@ def submit_start(request): # (... don't change entry after this point to avoid race # conditions with changes to the document via processing code) try: - process_media.apply_async( + media_manager['processor'].apply_async( [unicode(entry['_id'])], {}, task_id=task_id) except BaseException as exc: -- cgit v1.2.3 From ae3bc7fabf8e0abb5f3d8b6534ca451890bbe90b Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Sat, 1 Oct 2011 09:31:42 -0400 Subject: Moved common, translation, template, and url code out of util.py and into tools/[file].py --- mediagoblin/submit/forms.py | 2 +- mediagoblin/submit/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index a999c714..200ce4e4 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -18,7 +18,7 @@ import wtforms from mediagoblin.util import tag_length_validator -from mediagoblin.util import fake_ugettext_passthrough as _ +from mediagoblin.tools.translate import fake_ugettext_passthrough as _ class SubmitStartForm(wtforms.Form): diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index e24d78f3..cd34e006 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -25,7 +25,7 @@ from mediagoblin.db.util import ObjectId from mediagoblin.util import ( render_to_response, redirect, cleaned_markdown_conversion, \ convert_to_tag_list_of_dicts) -from mediagoblin.util import pass_to_ugettext as _ +from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media, mark_entry_failed -- cgit v1.2.3 From 152a3bfaa36d58e44979f217c5799531f780250f Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Sat, 1 Oct 2011 18:05:44 -0400 Subject: Finished splitting util.py into separate files. --- mediagoblin/submit/forms.py | 2 +- mediagoblin/submit/views.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 200ce4e4..25d6e304 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -17,7 +17,7 @@ import wtforms -from mediagoblin.util import tag_length_validator +from mediagoblin.tools.text import tag_length_validator from mediagoblin.tools.translate import fake_ugettext_passthrough as _ diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index cd34e006..7134235e 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -22,10 +22,9 @@ from cgi import FieldStorage from werkzeug.utils import secure_filename from mediagoblin.db.util import ObjectId -from mediagoblin.util import ( - render_to_response, redirect, cleaned_markdown_conversion, \ - convert_to_tag_list_of_dicts) +from mediagoblin.tools.text import cleaned_markdown_conversion, convert_to_tag_list_of_dicts from mediagoblin.tools.translate import pass_to_ugettext as _ +from mediagoblin.tools.response import render_to_response, redirect from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media, mark_entry_failed -- cgit v1.2.3 From 243c3843bd574129caa7663e25d1a843b2d2dd30 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 1 Oct 2011 15:10:02 -0700 Subject: Whitespace and formatting cleanup. * Removed trailing whitespace * Line length < 80 where possible * Honor conventions on number of blank lines * Honor conventions about spaces around :, = --- mediagoblin/submit/__init__.py | 2 -- mediagoblin/submit/security.py | 2 +- mediagoblin/submit/views.py | 16 +++++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/__init__.py b/mediagoblin/submit/__init__.py index 576bd0f5..ba347c69 100644 --- a/mediagoblin/submit/__init__.py +++ b/mediagoblin/submit/__init__.py @@ -13,5 +13,3 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - - diff --git a/mediagoblin/submit/security.py b/mediagoblin/submit/security.py index 9d62a36e..6708baf7 100644 --- a/mediagoblin/submit/security.py +++ b/mediagoblin/submit/security.py @@ -16,9 +16,9 @@ from mimetypes import guess_type - ALLOWED = ['image/jpeg', 'image/png', 'image/tiff', 'image/gif'] + def check_filetype(posted_file): if not guess_type(posted_file.filename)[0] in ALLOWED: return False diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index e24d78f3..22a13b6d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -61,8 +61,8 @@ def submit_start(request): entry['description'] = unicode(request.POST.get('description')) entry['description_html'] = cleaned_markdown_conversion( entry['description']) - - entry['media_type'] = u'image' # heh + + entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] # Process the user's folksonomy "tags" @@ -90,8 +90,10 @@ def submit_start(request): # We generate this ourselves so we know what the taks id is for # retrieval later. - # (If we got it off the task's auto-generation, there'd be a risk of - # a race condition when we'd save after sending off the task) + + # (If we got it off the task's auto-generation, there'd be + # a risk of a race condition when we'd save after sending + # off the task) task_id = unicode(uuid.uuid4()) entry['queued_task_id'] = task_id @@ -113,8 +115,8 @@ def submit_start(request): # expect a lot of users to run things in this way we have to # capture stuff here. # - # ... not completely the diaper pattern because the exception is - # re-raised :) + # ... not completely the diaper pattern because the + # exception is re-raised :) mark_entry_failed(entry[u'_id'], exc) # re-raise the exception raise @@ -122,7 +124,7 @@ def submit_start(request): add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", - user = request.user['username']) + user=request.user['username']) return render_to_response( request, -- cgit v1.2.3 From 285ffeddf3542201b83072d3be544c85e9c487c2 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 1 Oct 2011 15:10:41 -0700 Subject: has_key is deprecated, converting uses to use "in" operator. --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 22a13b6d..d450ca21 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -40,7 +40,7 @@ def submit_start(request): submit_form = submit_forms.SubmitStartForm(request.POST) if request.method == 'POST' and submit_form.validate(): - if not (request.POST.has_key('file') + if not ('file' in request.POST and isinstance(request.POST['file'], FieldStorage) and request.POST['file'].file): submit_form.file.errors.append( -- cgit v1.2.3 From eabe6b678a98fd06d9cd8463935a3b842f41485c Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 13 Nov 2011 19:25:06 +0100 Subject: Dot-Notation for "_id" Note: Migrations can't use "Dot Notation"! Migrations run on pymongo, not mongokit. So they can't use the "Dot Notation". This isn't really a big issue, as migrations are anyway quite mongo specific. --- mediagoblin/submit/views.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 25f7d79d..bd63bd18 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -52,7 +52,7 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() - entry['_id'] = ObjectId() + entry._id = ObjectId() entry['title'] = ( unicode(request.POST['title']) or unicode(splitext(filename)[0])) @@ -62,7 +62,7 @@ def submit_start(request): entry['description']) entry['media_type'] = u'image' # heh - entry['uploader'] = request.user['_id'] + entry['uploader'] = request.user._id # Process the user's folksonomy "tags" entry['tags'] = convert_to_tag_list_of_dicts( @@ -74,7 +74,7 @@ def submit_start(request): # Now store generate the queueing related filename queue_filepath = request.app.queue_store.get_unique_filepath( ['media_entries', - unicode(entry['_id']), + unicode(entry._id), secure_filename(filename)]) # queue appropriately @@ -105,7 +105,7 @@ def submit_start(request): # conditions with changes to the document via processing code) try: process_media.apply_async( - [unicode(entry['_id'])], {}, + [unicode(entry._id)], {}, task_id=task_id) except BaseException as exc: # The purpose of this section is because when running in "lazy" @@ -116,7 +116,7 @@ def submit_start(request): # # ... not completely the diaper pattern because the # exception is re-raised :) - mark_entry_failed(entry[u'_id'], exc) + mark_entry_failed(entry._id, exc) # re-raise the exception raise -- cgit v1.2.3 From 3618a9ac5112c657fd095a0f9cbd346921a4e800 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 17:11:37 +0100 Subject: Dot-Notation: x._id = ObjectId() doesn't seem to work properly For whatever reason, this does not work as expected: entry._id = ObjectId() Need to go this way: entry['_id'] = ObjectId() --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index bd63bd18..139b1d1d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -52,7 +52,7 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() - entry._id = ObjectId() + entry['_id'] = ObjectId() entry['title'] = ( unicode(request.POST['title']) or unicode(splitext(filename)[0])) -- cgit v1.2.3 From cee794a8f7ac82ee7681f749e56411c910e281a6 Mon Sep 17 00:00:00 2001 From: Jef van Schendel Date: Sun, 20 Nov 2011 15:34:40 +0100 Subject: Fix for bug #467, "Add explanatory copy to add/edit picture pages saying that tags are comma-separated" --- mediagoblin/submit/forms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 25d6e304..48a21f02 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -30,4 +30,6 @@ class SubmitStartForm(wtforms.Form): _('Description of this work')) tags = wtforms.TextField( _('Tags'), - [tag_length_validator]) + [tag_length_validator], + description=_( + "Seperate tags by commas or spaces.")) -- cgit v1.2.3 From 8e5f974684ce4e329a5022459f2e536fa4e15edd Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Mon, 21 Nov 2011 23:18:40 +0100 Subject: Fixes after merging video branch into master - Removed debug output from init/celery - Moved process_media/__init__ to processing.py - Centralized the processing.ProcessMedia task class - Updated media managers to reference the processing function instead of the ProcessMedia instance - Updated new-style image processing to previous, newer old-style image processing - Updated video transcoding - Changed method in progress output, sometimes message.structure['percent'] raises KeyError --- mediagoblin/submit/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index dd1c3d1b..21381e39 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -19,6 +19,8 @@ import uuid from os.path import splitext from cgi import FieldStorage +from celery import registry + from werkzeug.utils import secure_filename from mediagoblin.db.util import ObjectId @@ -27,7 +29,7 @@ from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.response import render_to_response, redirect from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security -from mediagoblin.process_media import mark_entry_failed +from mediagoblin.processing import mark_entry_failed, ProcessMedia from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import get_media_type_and_manager @@ -104,8 +106,9 @@ def submit_start(request): # # (... don't change entry after this point to avoid race # conditions with changes to the document via processing code) + process_media = registry.tasks[ProcessMedia.name] try: - media_manager['processor'].apply_async( + process_media.apply_async( [unicode(entry._id)], {}, task_id=task_id) except BaseException as exc: -- cgit v1.2.3 From 0bce749b21595fb0e33e2a109902b71e4611d483 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Mon, 21 Nov 2011 23:38:31 +0100 Subject: Fixes after merging video into master - part 2 - Added handling of InvalidFileType to submit.views - Updated test_celery_setup and test_submission tests to reflect the changes to the media procesing infrastructure --- mediagoblin/submit/views.py | 135 ++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 66 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 21381e39..3def44ce 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -31,7 +31,7 @@ from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.processing import mark_entry_failed, ProcessMedia from mediagoblin.messages import add_message, SUCCESS -from mediagoblin.media_types import get_media_type_and_manager +from mediagoblin.media_types import get_media_type_and_manager, InvalidFileType @require_active_login @@ -48,86 +48,89 @@ def submit_start(request): submit_form.file.errors.append( _(u'You must provide a file.')) else: - filename = request.POST['file'].filename + try: + filename = request.POST['file'].filename + media_type, media_manager = get_media_type_and_manager(filename) - media_type, media_manager = get_media_type_and_manager(filename) + # create entry and save in database + entry = request.db.MediaEntry() + entry['_id'] = ObjectId() + entry['media_type'] = unicode(media_type) + entry['title'] = ( + unicode(request.POST['title']) + or unicode(splitext(filename)[0])) - # create entry and save in database - entry = request.db.MediaEntry() - entry['_id'] = ObjectId() - entry['media_type'] = unicode(media_type) - entry['title'] = ( - unicode(request.POST['title']) - or unicode(splitext(filename)[0])) + entry['description'] = unicode(request.POST.get('description')) + entry['description_html'] = cleaned_markdown_conversion( + entry['description']) - entry['description'] = unicode(request.POST.get('description')) - entry['description_html'] = cleaned_markdown_conversion( - entry['description']) - - entry['uploader'] = request.user['_id'] + entry['uploader'] = request.user['_id'] - # Process the user's folksonomy "tags" - entry['tags'] = convert_to_tag_list_of_dicts( - request.POST.get('tags')) + # Process the user's folksonomy "tags" + entry['tags'] = convert_to_tag_list_of_dicts( + request.POST.get('tags')) - # Generate a slug from the title - entry.generate_slug() + # Generate a slug from the title + entry.generate_slug() - # Now store generate the queueing related filename - queue_filepath = request.app.queue_store.get_unique_filepath( - ['media_entries', - unicode(entry._id), - secure_filename(filename)]) + # Now store generate the queueing related filename + queue_filepath = request.app.queue_store.get_unique_filepath( + ['media_entries', + unicode(entry._id), + secure_filename(filename)]) - # queue appropriately - queue_file = request.app.queue_store.get_file( - queue_filepath, 'wb') + # queue appropriately + queue_file = request.app.queue_store.get_file( + queue_filepath, 'wb') - with queue_file: - queue_file.write(request.POST['file'].file.read()) + with queue_file: + queue_file.write(request.POST['file'].file.read()) - # Add queued filename to the entry - entry['queued_media_file'] = queue_filepath + # Add queued filename to the entry + entry['queued_media_file'] = queue_filepath - # We generate this ourselves so we know what the taks id is for - # retrieval later. + # We generate this ourselves so we know what the taks id is for + # retrieval later. - # (If we got it off the task's auto-generation, there'd be - # a risk of a race condition when we'd save after sending - # off the task) - task_id = unicode(uuid.uuid4()) - entry['queued_task_id'] = task_id + # (If we got it off the task's auto-generation, there'd be + # a risk of a race condition when we'd save after sending + # off the task) + task_id = unicode(uuid.uuid4()) + entry['queued_task_id'] = task_id - # Save now so we have this data before kicking off processing - entry.save(validate=True) + # Save now so we have this data before kicking off processing + entry.save(validate=True) - # Pass off to processing - # - # (... don't change entry after this point to avoid race - # conditions with changes to the document via processing code) - process_media = registry.tasks[ProcessMedia.name] - try: - process_media.apply_async( - [unicode(entry._id)], {}, - task_id=task_id) - except BaseException as exc: - # The purpose of this section is because when running in "lazy" - # or always-eager-with-exceptions-propagated celery mode that - # the failure handling won't happen on Celery end. Since we - # expect a lot of users to run things in this way we have to - # capture stuff here. + # Pass off to processing # - # ... not completely the diaper pattern because the - # exception is re-raised :) - mark_entry_failed(entry._id, exc) - # re-raise the exception - raise - - add_message(request, SUCCESS, _('Woohoo! Submitted!')) - - return redirect(request, "mediagoblin.user_pages.user_home", - user=request.user['username']) + # (... don't change entry after this point to avoid race + # conditions with changes to the document via processing code) + process_media = registry.tasks[ProcessMedia.name] + try: + process_media.apply_async( + [unicode(entry._id)], {}, + task_id=task_id) + except BaseException as exc: + # The purpose of this section is because when running in "lazy" + # or always-eager-with-exceptions-propagated celery mode that + # the failure handling won't happen on Celery end. Since we + # expect a lot of users to run things in this way we have to + # capture stuff here. + # + # ... not completely the diaper pattern because the + # exception is re-raised :) + mark_entry_failed(entry._id, exc) + # re-raise the exception + raise + + add_message(request, SUCCESS, _('Woohoo! Submitted!')) + + return redirect(request, "mediagoblin.user_pages.user_home", + user=request.user['username']) + except InvalidFileType, exc: + submit_form.file.errors.append( + _(u'Invalid file type.')) return render_to_response( request, -- cgit v1.2.3 From 9382221fe2d3e69b7900cfb7461abfdb443b4d10 Mon Sep 17 00:00:00 2001 From: Manuel Urbano Santos Date: Sun, 27 Nov 2011 14:31:20 +0100 Subject: Fix the text "Seperate tags by commas and spaces" since spaces are not used to seperate anymore. --- mediagoblin/submit/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 48a21f02..ad420771 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -32,4 +32,4 @@ class SubmitStartForm(wtforms.Form): _('Tags'), [tag_length_validator], description=_( - "Seperate tags by commas or spaces.")) + "Seperate tags by commas.")) -- cgit v1.2.3 From 5a4e3ff1e2a0f2ed451bc191c1d44bcd694b8e75 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 15:39:57 +0100 Subject: Dot-Notation for Users.username --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 3def44ce..6beb6b18 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -127,7 +127,7 @@ def submit_start(request): add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", - user=request.user['username']) + user=request.user.username) except InvalidFileType, exc: submit_form.file.errors.append( _(u'Invalid file type.')) -- cgit v1.2.3 From 1ceb4fc8682dd00c15376b75a3d9222cac6fb5bd Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 21 Nov 2011 20:18:38 +0100 Subject: Dot-Notation for MediaEntry.uploader --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 6beb6b18..64d4b541 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -64,7 +64,7 @@ def submit_start(request): entry['description_html'] = cleaned_markdown_conversion( entry['description']) - entry['uploader'] = request.user['_id'] + entry.uploader = request.user._id # Process the user's folksonomy "tags" entry['tags'] = convert_to_tag_list_of_dicts( -- cgit v1.2.3 From ec82fbd85c93c88d177e9f5c7a7414a2b47fa17e Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 23 Nov 2011 00:10:42 +0100 Subject: Dot-Notation for MediaEntry.title --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 64d4b541..1805e293 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -56,7 +56,7 @@ def submit_start(request): entry = request.db.MediaEntry() entry['_id'] = ObjectId() entry['media_type'] = unicode(media_type) - entry['title'] = ( + entry.title = ( unicode(request.POST['title']) or unicode(splitext(filename)[0])) -- cgit v1.2.3 From 1d9399660416fe5a04d322303986434815bc15f0 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 4 Dec 2011 20:06:42 +0100 Subject: Dot-Notation for MediaEntry.description(_html) --- mediagoblin/submit/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1805e293..8da71341 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -60,9 +60,9 @@ def submit_start(request): unicode(request.POST['title']) or unicode(splitext(filename)[0])) - entry['description'] = unicode(request.POST.get('description')) - entry['description_html'] = cleaned_markdown_conversion( - entry['description']) + entry.description = unicode(request.POST.get('description')) + entry.description_html = cleaned_markdown_conversion( + entry.description) entry.uploader = request.user._id -- cgit v1.2.3 From f4ee839939e4215820df3132b62c51f721510f77 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 4 Dec 2011 20:16:01 +0100 Subject: Dot-Notation for MediaEntry.media_type --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 8da71341..4e4c7c43 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -55,7 +55,7 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() entry['_id'] = ObjectId() - entry['media_type'] = unicode(media_type) + entry.media_type = unicode(media_type) entry.title = ( unicode(request.POST['title']) or unicode(splitext(filename)[0])) -- cgit v1.2.3 From 6f559060785270d32a6ca99d2cdb89b5fedfaf9e Mon Sep 17 00:00:00 2001 From: Jef van Schendel Date: Fri, 30 Dec 2011 19:45:00 +0100 Subject: Fix #715: On media submit page, "Separate" is misspelled --- mediagoblin/submit/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index ad420771..e21b00ee 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -32,4 +32,4 @@ class SubmitStartForm(wtforms.Form): _('Tags'), [tag_length_validator], description=_( - "Seperate tags by commas.")) + "Separate tags by commas.")) -- cgit v1.2.3 From a246ccca69e863904718537f45a17d226b33a123 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Wed, 30 Nov 2011 21:21:39 +0100 Subject: ASCII media type support & fix a bug in file submission error handling * Added ASCII media processing * Added ASCII media display * Added ASCII media type Rebased from Joar Wandborg's ascii art branch (squashed to remove the commits borrowing code of dubious license) Fixed a bug in file submission error handling: - Moved file-extension condition out of loop (what did it do there?) - Updated file submission tests - Changed error handling in file submission, should now report more than absolutely necessary. --- mediagoblin/submit/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 4e4c7c43..443d0e52 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -128,9 +128,13 @@ def submit_start(request): return redirect(request, "mediagoblin.user_pages.user_home", user=request.user.username) - except InvalidFileType, exc: + except Exception as e: + ''' + This section is intended to catch exceptions raised in + mediagobling.media_types + ''' submit_form.file.errors.append( - _(u'Invalid file type.')) + e) return render_to_response( request, -- cgit v1.2.3 From 4601c30c2e80734cf3a18472c2e29a7f920b9604 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sat, 31 Dec 2011 22:57:08 +0100 Subject: Fixed submission error handling and broken tests - Fixed broken test_auth test - Fixed error handling on submission, it now raises the exception if it is not explicitly relevant to file submission. --- mediagoblin/submit/views.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 443d0e52..60693bd6 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -31,7 +31,8 @@ from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.processing import mark_entry_failed, ProcessMedia from mediagoblin.messages import add_message, SUCCESS -from mediagoblin.media_types import get_media_type_and_manager, InvalidFileType +from mediagoblin.media_types import get_media_type_and_manager, \ + InvalidFileType, FileTypeNotSupported @require_active_login @@ -133,8 +134,13 @@ def submit_start(request): This section is intended to catch exceptions raised in mediagobling.media_types ''' - submit_form.file.errors.append( - e) + + if isinstance(e, InvalidFileType) or \ + isinstance(e, FileTypeNotSupported): + submit_form.file.errors.append( + e) + else: + raise return render_to_response( request, -- cgit v1.2.3 From 8545cfc97d9336b100881bd3ebafd4a5f4882dd3 Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 13 Dec 2011 11:18:39 +0100 Subject: Dot-Notation for MediaEntry.queued_media_file --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 60693bd6..dd273c7f 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -89,7 +89,7 @@ def submit_start(request): queue_file.write(request.POST['file'].file.read()) # Add queued filename to the entry - entry['queued_media_file'] = queue_filepath + entry.queued_media_file = queue_filepath # We generate this ourselves so we know what the taks id is for # retrieval later. -- cgit v1.2.3 From 9c196287ad26f52acb38d6c37560848da23151a6 Mon Sep 17 00:00:00 2001 From: Jef van Schendel Date: Wed, 4 Jan 2012 17:48:16 +0100 Subject: Add Markdown for submit page, edit page, profile edit page; thus fixing ticket #690 --- mediagoblin/submit/forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index e21b00ee..7ef3638f 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -27,7 +27,10 @@ class SubmitStartForm(wtforms.Form): _('Title'), [wtforms.validators.Length(min=0, max=500)]) description = wtforms.TextAreaField( - _('Description of this work')) + _('Description of this work'), + description=_("""You can use + + Markdown for formatting.""")) tags = wtforms.TextField( _('Tags'), [tag_length_validator], -- cgit v1.2.3 From 5b1a7bae3c8e56ea9b512dcbba6b8a512304a956 Mon Sep 17 00:00:00 2001 From: Michele Azzolari Date: Wed, 11 Jan 2012 15:48:37 +0100 Subject: Added PuSH capability --- mediagoblin/submit/views.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index dd273c7f..d5aa60fa 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -20,6 +20,7 @@ from os.path import splitext from cgi import FieldStorage from celery import registry +import urllib,urllib2 from werkzeug.utils import secure_filename @@ -125,6 +126,19 @@ def submit_start(request): # re-raise the exception raise + if mg_globals.app_config["push_enabled"]: + feed_url=request.urlgen( + 'mediagoblin.user_pages.atom_feed', + qualified=True,user=request.user.username) + hubparameters = { + 'hub.mode': 'publish', + 'hub.url': feed_url} + huburl = mg_globals.app_config["push_url"] + hubdata = urllib.urlencode(hubparameters) + hubheaders = {"Content-type": "application/x-www-form-urlencoded"} + hubrequest = urllib2.Request(huburl, hubdata,hubheaders) + hubresponse = urllib2.urlopen(hubrequest) + add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", -- cgit v1.2.3 From 7f251b037bd5207652ca73f556e90b9633786a3c Mon Sep 17 00:00:00 2001 From: Michele Azzolari Date: Thu, 12 Jan 2012 00:00:28 +0100 Subject: As suggested by Elrond, we use only one setting --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index d5aa60fa..de280422 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -126,7 +126,7 @@ def submit_start(request): # re-raise the exception raise - if mg_globals.app_config["push_enabled"]: + if mg_globals.app_config["push_url"]: feed_url=request.urlgen( 'mediagoblin.user_pages.atom_feed', qualified=True,user=request.user.username) -- cgit v1.2.3 From bb025ebda14297b721f8816d13980a477f62bca6 Mon Sep 17 00:00:00 2001 From: Michele Azzolari Date: Thu, 12 Jan 2012 11:05:05 +0100 Subject: As per spec, we permit to have more then 1 hub --- mediagoblin/submit/views.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index de280422..65243ca1 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -126,18 +126,20 @@ def submit_start(request): # re-raise the exception raise - if mg_globals.app_config["push_url"]: + if mg_globals.app_config["push_urls"]: feed_url=request.urlgen( 'mediagoblin.user_pages.atom_feed', qualified=True,user=request.user.username) hubparameters = { 'hub.mode': 'publish', 'hub.url': feed_url} - huburl = mg_globals.app_config["push_url"] hubdata = urllib.urlencode(hubparameters) - hubheaders = {"Content-type": "application/x-www-form-urlencoded"} - hubrequest = urllib2.Request(huburl, hubdata,hubheaders) - hubresponse = urllib2.urlopen(hubrequest) + hubheaders = { + "Content-type": "application/x-www-form-urlencoded", + "Connection": "close"} + for huburl in mg_globals.app_config["push_urls"]: + hubrequest = urllib2.Request(huburl, hubdata,hubheaders) + hubresponse = urllib2.urlopen(hubrequest) add_message(request, SUCCESS, _('Woohoo! Submitted!')) -- cgit v1.2.3 From 25b48323a86a1036112f2f33c889d5d12d5dee9c Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Tue, 17 Jan 2012 00:33:55 -0500 Subject: First crack at basic license support. --- mediagoblin/submit/forms.py | 5 ++++- mediagoblin/submit/views.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 25d6e304..be85b9a9 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -19,7 +19,7 @@ import wtforms from mediagoblin.tools.text import tag_length_validator from mediagoblin.tools.translate import fake_ugettext_passthrough as _ - +from mediagoblin.tools.licenses import licenses_as_choices class SubmitStartForm(wtforms.Form): file = wtforms.FileField(_('File')) @@ -31,3 +31,6 @@ class SubmitStartForm(wtforms.Form): tags = wtforms.TextField( _('Tags'), [tag_length_validator]) + license = wtforms.SelectField( + _('License'), + choices=licenses_as_choices()) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 7134235e..ecfa9943 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -60,6 +60,10 @@ def submit_start(request): entry['description'] = unicode(request.POST.get('description')) entry['description_html'] = cleaned_markdown_conversion( entry['description']) + + entry['license'] = ( + unicode(request.POST.get('license')) + or '') entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] -- cgit v1.2.3 From 77b91efcc260cf5f4e7d2b544a02a12c51f45ad4 Mon Sep 17 00:00:00 2001 From: Michele Azzolari Date: Tue, 17 Jan 2012 22:42:36 +0100 Subject: We handle exceptions if PuSH fails --- mediagoblin/submit/views.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 65243ca1..91498b09 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -21,6 +21,7 @@ from cgi import FieldStorage from celery import registry import urllib,urllib2 +import logging from werkzeug.utils import secure_filename @@ -131,15 +132,24 @@ def submit_start(request): 'mediagoblin.user_pages.atom_feed', qualified=True,user=request.user.username) hubparameters = { - 'hub.mode': 'publish', - 'hub.url': feed_url} + 'hub.mode': 'publish', + 'hub.url': feed_url} hubdata = urllib.urlencode(hubparameters) hubheaders = { "Content-type": "application/x-www-form-urlencoded", "Connection": "close"} for huburl in mg_globals.app_config["push_urls"]: - hubrequest = urllib2.Request(huburl, hubdata,hubheaders) - hubresponse = urllib2.urlopen(hubrequest) + hubrequest = urllib2.Request(huburl, hubdata, hubheaders) + try: + hubresponse = urllib2.urlopen(hubrequest) + except urllib2.HTTPError as exc: + # This is not a big issue, the item will be fetched + # by the PuSH server next time we hit it + logging.getLogger(__name__).warning( + "push url %r gave error %r", huburl, exc.code) + except urllib2.URLError as exc: + logging.getLogger(__name__).warning( + "push url %r is unreachable %r", huburl, exc.reason) add_message(request, SUCCESS, _('Woohoo! Submitted!')) -- cgit v1.2.3 From c03d13cd791ac41db1be72e8a5d4d2eaa6cc6087 Mon Sep 17 00:00:00 2001 From: Michele Azzolari Date: Tue, 17 Jan 2012 23:15:47 +0100 Subject: Cleaned the code --- mediagoblin/submit/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 91498b09..33868785 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -23,6 +23,8 @@ from celery import registry import urllib,urllib2 import logging +_log = logging.getLogger(__name__) + from werkzeug.utils import secure_filename from mediagoblin.db.util import ObjectId @@ -145,10 +147,10 @@ def submit_start(request): except urllib2.HTTPError as exc: # This is not a big issue, the item will be fetched # by the PuSH server next time we hit it - logging.getLogger(__name__).warning( + _log.warning( "push url %r gave error %r", huburl, exc.code) except urllib2.URLError as exc: - logging.getLogger(__name__).warning( + _log.warning( "push url %r is unreachable %r", huburl, exc.reason) add_message(request, SUCCESS, _('Woohoo! Submitted!')) -- cgit v1.2.3 From 97ec97dbc77373819939557ad20c72a0aced5d61 Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Wed, 18 Jan 2012 21:21:49 -0500 Subject: Minor formatting and syntax fix. --- mediagoblin/submit/forms.py | 1 + mediagoblin/submit/views.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 08234822..4ff52609 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -21,6 +21,7 @@ from mediagoblin.tools.text import tag_length_validator from mediagoblin.tools.translate import fake_ugettext_passthrough as _ from mediagoblin.tools.licenses import licenses_as_choices + class SubmitStartForm(wtforms.Form): file = wtforms.FileField(_('File')) title = wtforms.TextField( diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index b91fdb8d..8911bf82 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -69,7 +69,7 @@ def submit_start(request): entry.description_html = cleaned_markdown_conversion( entry.description) - entry['license'] = ( + entry.license = ( unicode(request.POST.get('license')) or '') -- cgit v1.2.3 From 3c351460e1dbed9e789e363f1d5635160bce8d84 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 21 Jan 2012 19:24:36 +0100 Subject: Fix unit tests with new license support Make the license field in the forms optional and let them properly be defaulted to "". --- mediagoblin/submit/forms.py | 1 + mediagoblin/submit/views.py | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 4ff52609..1ff59c18 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -39,4 +39,5 @@ class SubmitStartForm(wtforms.Form): "Separate tags by commas.")) license = wtforms.SelectField( _('License'), + [wtforms.validators.Optional(),], choices=licenses_as_choices()) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 8911bf82..832203a4 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -69,9 +69,7 @@ def submit_start(request): entry.description_html = cleaned_markdown_conversion( entry.description) - entry.license = ( - unicode(request.POST.get('license')) - or '') + entry.license = unicode(request.POST.get('license', '')) entry.uploader = request.user._id -- cgit v1.2.3 From 2788e6a16484330ce1091ae57a87a4da362936c6 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 21 Jan 2012 16:40:39 -0600 Subject: License "all rights reserved" default should be None/NULL, not empty string --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 832203a4..f70e4ba5 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -69,7 +69,7 @@ def submit_start(request): entry.description_html = cleaned_markdown_conversion( entry.description) - entry.license = unicode(request.POST.get('license', '')) + entry.license = unicode(request.POST.get('license', "")) or None entry.uploader = request.user._id -- cgit v1.2.3 From de91730336951f27cb83c3e60ac2d071bb3d4cef Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 4 Jan 2012 22:00:44 +0100 Subject: Nearly complete support for Tags These changes allow all of the rest of the code to use tags in sql as they were used on mongo. It's not efficient at all, as changing tags usually means to remove all old tags and adding all new. The only problem here is: Old slugs for tags are not removed, because they're shared across all MediaTags and dropping orphans is not always easy. --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index f70e4ba5..0efee803 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -74,7 +74,7 @@ def submit_start(request): entry.uploader = request.user._id # Process the user's folksonomy "tags" - entry['tags'] = convert_to_tag_list_of_dicts( + entry.tags = convert_to_tag_list_of_dicts( request.POST.get('tags')) # Generate a slug from the title -- cgit v1.2.3 From cf29e8a824e0ef4612f1144f079c80c1d20b89e5 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 2 Feb 2012 09:44:13 -0600 Subject: It's 2012 all up in here --- mediagoblin/submit/__init__.py | 2 +- mediagoblin/submit/forms.py | 2 +- mediagoblin/submit/routing.py | 2 +- mediagoblin/submit/security.py | 2 +- mediagoblin/submit/views.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/__init__.py b/mediagoblin/submit/__init__.py index ba347c69..621845ba 100644 --- a/mediagoblin/submit/__init__.py +++ b/mediagoblin/submit/__init__.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # 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 diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 1ff59c18..7d9e8fcf 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # 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 diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index 03e01f45..8ce23cd9 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # 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 diff --git a/mediagoblin/submit/security.py b/mediagoblin/submit/security.py index 6708baf7..5dbc0db4 100644 --- a/mediagoblin/submit/security.py +++ b/mediagoblin/submit/security.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # 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 diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 0efee803..cdd097ec 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # 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 -- cgit v1.2.3 From ec4261a449c11b015190bc90dd9ae828261065cd Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Wed, 15 Feb 2012 01:15:29 +0100 Subject: Changed media processing delegation to a 'sniffing' method - Added sniff handlers to all media plugins All of them except audio returning False for ANYTHING at the moment. --- mediagoblin/submit/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index cdd097ec..4fafe1e3 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -35,7 +35,7 @@ from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.processing import mark_entry_failed, ProcessMedia from mediagoblin.messages import add_message, SUCCESS -from mediagoblin.media_types import get_media_type_and_manager, \ +from mediagoblin.media_types import sniff_media, \ InvalidFileType, FileTypeNotSupported @@ -55,7 +55,11 @@ def submit_start(request): else: try: filename = request.POST['file'].filename - media_type, media_manager = get_media_type_and_manager(filename) + + # Sniff the submitted media to determine which + # media plugin should handle processing + media_type, media_manager = sniff_media( + request.POST['file']) # create entry and save in database entry = request.db.MediaEntry() @@ -164,7 +168,6 @@ def submit_start(request): This section is intended to catch exceptions raised in mediagobling.media_types ''' - if isinstance(e, InvalidFileType) or \ isinstance(e, FileTypeNotSupported): submit_form.file.errors.append( -- cgit v1.2.3 From 1e72e075f8d542f4aa1ad0262f4fd1a5645cc731 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 13 Feb 2012 13:42:59 +0100 Subject: Drop pre-rendered html: MediaEntry.description_html After a bit of discussion, we decided to drop the pre-rendered html from the database and render it on the fly. In another step, we will use some proper caching method to cache this stuff. This commit affects the MediaEntry.description_html part. --- mediagoblin/submit/views.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index cdd097ec..845400ca 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -28,7 +28,7 @@ _log = logging.getLogger(__name__) from werkzeug.utils import secure_filename from mediagoblin.db.util import ObjectId -from mediagoblin.tools.text import cleaned_markdown_conversion, convert_to_tag_list_of_dicts +from mediagoblin.tools.text import convert_to_tag_list_of_dicts from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.response import render_to_response, redirect from mediagoblin.decorators import require_active_login @@ -66,8 +66,6 @@ def submit_start(request): or unicode(splitext(filename)[0])) entry.description = unicode(request.POST.get('description')) - entry.description_html = cleaned_markdown_conversion( - entry.description) entry.license = unicode(request.POST.get('license', "")) or None -- cgit v1.2.3 From 572d4f01ff3bee75574c00bc85bc8a2700ba9828 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 19 Feb 2012 12:13:26 +0100 Subject: Use task_id in generating the queue file path The task_id is created anyway as a UUID. So it is very unique per definition. The only thing needed for the queue file path is a unique part. Before the objectid of the MediaEntry was used instead. But in the sql world the objectid is only available after an "insert" on the db. And creating the queue_file_path afterwards would require an "update" on the db. We can save that. ... for now. --- mediagoblin/submit/views.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 845400ca..df5b15c0 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -78,11 +78,18 @@ def submit_start(request): # Generate a slug from the title entry.generate_slug() + # We generate this ourselves so we know what the taks id is for + # retrieval later. + + # (If we got it off the task's auto-generation, there'd be + # a risk of a race condition when we'd save after sending + # off the task) + task_id = unicode(uuid.uuid4()) # Now store generate the queueing related filename queue_filepath = request.app.queue_store.get_unique_filepath( ['media_entries', - unicode(entry._id), + task_id, secure_filename(filename)]) # queue appropriately @@ -95,14 +102,7 @@ def submit_start(request): # Add queued filename to the entry entry.queued_media_file = queue_filepath - # We generate this ourselves so we know what the taks id is for - # retrieval later. - - # (If we got it off the task's auto-generation, there'd be - # a risk of a race condition when we'd save after sending - # off the task) - task_id = unicode(uuid.uuid4()) - entry['queued_task_id'] = task_id + entry.queued_task_id = task_id # Save now so we have this data before kicking off processing entry.save(validate=True) -- cgit v1.2.3 From 58f96a13e463fb417968cc92ec2ac5d4404641e4 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 25 Dec 2011 16:01:59 +0100 Subject: Allow .id instead of ._id for the Mongo backend To allow easier migration to the SQLAlchemy style .id give the User and MediaEntry mongo classes an alias attribute of .id that maps to ['_id']. Use it in the upload process, because this was one of the last positions with a ['_id'] instead of ._id (due to a bug in mongokit). --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index df5b15c0..1e145e9d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -59,7 +59,7 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() - entry['_id'] = ObjectId() + entry.id = ObjectId() entry.media_type = unicode(media_type) entry.title = ( unicode(request.POST['title']) -- cgit v1.2.3 From eace050a7d41333e659f049d61b7505fc5fbf627 Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 21 Mar 2012 11:39:52 +0100 Subject: Move celery task into own task.py Move the actual celery task from processing/__init__.py into its own .../task.py. That way it can be imported as needed. --- mediagoblin/submit/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1e145e9d..feda0cb2 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -33,7 +33,8 @@ from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.response import render_to_response, redirect from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security -from mediagoblin.processing import mark_entry_failed, ProcessMedia +from mediagoblin.processing import mark_entry_failed +from mediagoblin.processing.task import ProcessMedia from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import get_media_type_and_manager, \ InvalidFileType, FileTypeNotSupported -- cgit v1.2.3 From 32d8cf45114634d7d862db8b6255e07a1b94ffde Mon Sep 17 00:00:00 2001 From: Jakob Kramer Date: Fri, 23 Mar 2012 22:13:48 +0100 Subject: remove unused `mg.submit.security' module --- mediagoblin/submit/security.py | 26 -------------------------- mediagoblin/submit/views.py | 2 +- 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 mediagoblin/submit/security.py (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/security.py b/mediagoblin/submit/security.py deleted file mode 100644 index 5dbc0db4..00000000 --- a/mediagoblin/submit/security.py +++ /dev/null @@ -1,26 +0,0 @@ -# GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. -# -# 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 . - -from mimetypes import guess_type - -ALLOWED = ['image/jpeg', 'image/png', 'image/tiff', 'image/gif'] - - -def check_filetype(posted_file): - if not guess_type(posted_file.filename)[0] in ALLOWED: - return False - - return True diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index feda0cb2..1df676ab 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -32,7 +32,7 @@ from mediagoblin.tools.text import convert_to_tag_list_of_dicts from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.response import render_to_response, redirect from mediagoblin.decorators import require_active_login -from mediagoblin.submit import forms as submit_forms, security +from mediagoblin.submit import forms as submit_forms from mediagoblin.processing import mark_entry_failed from mediagoblin.processing.task import ProcessMedia from mediagoblin.messages import add_message, SUCCESS -- cgit v1.2.3 From 7a258b1408ba1e7e7ec39549057bd450face8d85 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sun, 8 Jul 2012 10:04:58 -0400 Subject: Fix docstring typo. --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 517fb646..72186136 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -167,7 +167,7 @@ def submit_start(request): except Exception as e: ''' This section is intended to catch exceptions raised in - mediagobling.media_types + mediagoblin.media_types ''' if isinstance(e, InvalidFileType) or \ isinstance(e, FileTypeNotSupported): -- cgit v1.2.3 From be5be1154fd22c548125ce5a055af1bdfdad9526 Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Fri, 17 Aug 2012 00:54:40 -0400 Subject: Added basic collection functionality --- mediagoblin/submit/forms.py | 10 ++++++++++ mediagoblin/submit/routing.py | 5 ++++- mediagoblin/submit/views.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index 7d9e8fcf..bd1e904f 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -41,3 +41,13 @@ class SubmitStartForm(wtforms.Form): _('License'), [wtforms.validators.Optional(),], choices=licenses_as_choices()) + +class AddCollectionForm(wtforms.Form): + title = wtforms.TextField( + _('Title'), + [wtforms.validators.Length(min=0, max=500), wtforms.validators.Required()]) + description = wtforms.TextAreaField( + _('Description of this collection'), + description=_("""You can use + + Markdown for formatting.""")) diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index 8ce23cd9..1e399d1e 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -18,4 +18,7 @@ from routes.route import Route submit_routes = [ Route('mediagoblin.submit.start', '/', - controller='mediagoblin.submit.views:submit_start')] + controller='mediagoblin.submit.views:submit_start'), + Route('mediagoblin.submit.collection', '/collection', + controller='mediagoblin.submit.views:add_collection'), + ] diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 72186136..a9b13778 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from mediagoblin import messages import mediagoblin.mg_globals as mg_globals import uuid from os.path import splitext @@ -181,3 +182,46 @@ def submit_start(request): 'mediagoblin/submit/start.html', {'submit_form': submit_form, 'app_config': mg_globals.app_config}) + +@require_active_login +def add_collection(request, media=None): + """ + View to create a new collection + """ + submit_form = submit_forms.AddCollectionForm(request.POST) + + if request.method == 'POST' and submit_form.validate(): + try: + collection = request.db.Collection() + collection.id = ObjectId() + + collection.title = unicode(request.POST['title']) + + collection.description = unicode(request.POST.get('description')) + collection.creator = request.user._id + collection.generate_slug() + + # Make sure this user isn't duplicating an existing collection + existing_collection = request.db.Collection.find_one({ + 'creator': request.user._id, + 'title':collection.title}) + + if existing_collection: + messages.add_message( + request, messages.ERROR, _('You already have a collection called "%s"!' % collection.title)) + else: + collection.save(validate=True) + + add_message(request, SUCCESS, _('Collection "%s" added!' % collection.title)) + + return redirect(request, "mediagoblin.user_pages.user_home", + user=request.user.username) + + except Exception as e: + raise + + return render_to_response( + request, + 'mediagoblin/submit/collection.html', + {'submit_form': submit_form, + 'app_config': mg_globals.app_config}) -- cgit v1.2.3 From f1d06e1d6c604c72028082a477248d26e81cad5b Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Thu, 27 Sep 2012 21:41:48 +0200 Subject: Switch from webob.Request to werkzeug.wrappers.Request --- mediagoblin/submit/views.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index a9b13778..7974bec0 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -18,7 +18,6 @@ from mediagoblin import messages import mediagoblin.mg_globals as mg_globals import uuid from os.path import splitext -from cgi import FieldStorage from celery import registry import urllib @@ -28,6 +27,7 @@ import logging _log = logging.getLogger(__name__) from werkzeug.utils import secure_filename +from werkzeug.datastructures import FileStorage from mediagoblin.db.util import ObjectId from mediagoblin.tools.text import convert_to_tag_list_of_dicts @@ -50,19 +50,19 @@ def submit_start(request): submit_form = submit_forms.SubmitStartForm(request.POST) if request.method == 'POST' and submit_form.validate(): - if not ('file' in request.POST - and isinstance(request.POST['file'], FieldStorage) - and request.POST['file'].file): + if not ('file' in request.files + and isinstance(request.files['file'], FileStorage) + and request.files['file'].stream): submit_form.file.errors.append( _(u'You must provide a file.')) else: try: - filename = request.POST['file'].filename + filename = request.files['file'].filename # Sniff the submitted media to determine which # media plugin should handle processing media_type, media_manager = sniff_media( - request.POST['file']) + request.files['file']) # create entry and save in database entry = request.db.MediaEntry() @@ -104,7 +104,7 @@ def submit_start(request): queue_filepath, 'wb') with queue_file: - queue_file.write(request.POST['file'].file.read()) + queue_file.write(request.files['file'].stream.read()) # Add queued filename to the entry entry.queued_media_file = queue_filepath @@ -205,13 +205,13 @@ def add_collection(request, media=None): existing_collection = request.db.Collection.find_one({ 'creator': request.user._id, 'title':collection.title}) - + if existing_collection: messages.add_message( request, messages.ERROR, _('You already have a collection called "%s"!' % collection.title)) else: collection.save(validate=True) - + add_message(request, SUCCESS, _('Collection "%s" added!' % collection.title)) return redirect(request, "mediagoblin.user_pages.user_home", -- cgit v1.2.3 From 111a609df526bd3690fc03e623eaf5826f33f4d2 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sat, 29 Sep 2012 21:07:15 +0200 Subject: Replaced all request.POST with request.form, ... - Fixed error handling in OAuth plugin - Changed request.POST file fields to request.files --- mediagoblin/submit/views.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 7974bec0..02026f45 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -47,7 +47,7 @@ def submit_start(request): """ First view for submitting a file. """ - submit_form = submit_forms.SubmitStartForm(request.POST) + submit_form = submit_forms.SubmitStartForm(request.form) if request.method == 'POST' and submit_form.validate(): if not ('file' in request.files @@ -69,18 +69,18 @@ def submit_start(request): entry.id = ObjectId() entry.media_type = unicode(media_type) entry.title = ( - unicode(request.POST['title']) + unicode(request.form['title']) or unicode(splitext(filename)[0])) - entry.description = unicode(request.POST.get('description')) + entry.description = unicode(request.form.get('description')) - entry.license = unicode(request.POST.get('license', "")) or None + entry.license = unicode(request.form.get('license', "")) or None entry.uploader = request.user._id # Process the user's folksonomy "tags" entry.tags = convert_to_tag_list_of_dicts( - request.POST.get('tags')) + request.form.get('tags')) # Generate a slug from the title entry.generate_slug() @@ -188,16 +188,16 @@ def add_collection(request, media=None): """ View to create a new collection """ - submit_form = submit_forms.AddCollectionForm(request.POST) + submit_form = submit_forms.AddCollectionForm(request.form) if request.method == 'POST' and submit_form.validate(): try: collection = request.db.Collection() collection.id = ObjectId() - collection.title = unicode(request.POST['title']) + collection.title = unicode(request.form['title']) - collection.description = unicode(request.POST.get('description')) + collection.description = unicode(request.form.get('description')) collection.creator = request.user._id collection.generate_slug() -- cgit v1.2.3 From 7742dcc1fbda04c3a1c76a057a1a93a8f504502e Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 14 Oct 2012 13:46:31 +0200 Subject: Switched most stuff over from Routes Removed the Routes routing functionality and replaced it with werkzeug.routes. Most views are functional. Known issues: - Translation integration with the request object is not yet figured out. This breaks 404 pages. --- mediagoblin/submit/routing.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index 1e399d1e..cbed1895 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -14,11 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from routes.route import Route +from mediagoblin.routing import add_route -submit_routes = [ - Route('mediagoblin.submit.start', '/', - controller='mediagoblin.submit.views:submit_start'), - Route('mediagoblin.submit.collection', '/collection', - controller='mediagoblin.submit.views:add_collection'), - ] +add_route('mediagoblin.submit.start', + '/submit/', 'mediagoblin.submit.views:submit_start') +add_route('collection_home', '/submit/collection', 'mediagoblin.submit.views:add_collection') -- cgit v1.2.3 From 0d857844b12b033ee8ecdbcfa474781f835bee59 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 14 Oct 2012 16:26:23 -0500 Subject: Added rudimentary route "mounting" w/ werkzeug routes; fixed auth routes auth routes fixes: - mounted the auth routes at /auth/ - removed crufty old verification email route --- mediagoblin/submit/routing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index cbed1895..fbe3c39c 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -18,4 +18,4 @@ from mediagoblin.routing import add_route add_route('mediagoblin.submit.start', '/submit/', 'mediagoblin.submit.views:submit_start') -add_route('collection_home', '/submit/collection', 'mediagoblin.submit.views:add_collection') +add_route('mediagoblin.submit.collection', '/submit/collection', 'mediagoblin.submit.views:add_collection') -- cgit v1.2.3 From 5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 30 Nov 2012 10:49:06 +0100 Subject: Move DBModel._id -> DBModel.id We were refering to model._id in most of the code base as this is what Mongo uses. However, each use of _id required a) fixup of queries: e.g. what we did in our find() and find_one() functions moving all '_id' to 'id'. It also required using AliasFields to make the ._id attribute available. This all means lots of superfluous fixing and transitioning in a SQL world. It will also not work in the long run. Much newer code already refers to the objects by model.id (e.g. in the oauth plugin), which will break with Mongo. So let's be honest, rip out the _id mongoism and live with .id as the one canonical way to address objects. This commit modifies all users and providers of model._id to use model.id instead. This patch works with or without Mongo removed first, but will break Mongo usage (even more than before) I have not bothered to fixup db.mongo.* and db.sql.convert (which converts from Mongo to SQL) Signed-off-by: Sebastian Spaeth --- mediagoblin/submit/views.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 02026f45..3628fa0d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -76,7 +76,7 @@ def submit_start(request): entry.license = unicode(request.form.get('license', "")) or None - entry.uploader = request.user._id + entry.uploader = request.user.id # Process the user's folksonomy "tags" entry.tags = convert_to_tag_list_of_dicts( @@ -121,7 +121,7 @@ def submit_start(request): process_media = registry.tasks[ProcessMedia.name] try: process_media.apply_async( - [unicode(entry._id)], {}, + [unicode(entry.id)], {}, task_id=task_id) except BaseException as exc: # The purpose of this section is because when running in "lazy" @@ -132,7 +132,7 @@ def submit_start(request): # # ... not completely the diaper pattern because the # exception is re-raised :) - mark_entry_failed(entry._id, exc) + mark_entry_failed(entry.id, exc) # re-raise the exception raise @@ -198,12 +198,12 @@ def add_collection(request, media=None): collection.title = unicode(request.form['title']) collection.description = unicode(request.form.get('description')) - collection.creator = request.user._id + collection.creator = request.user.id collection.generate_slug() # Make sure this user isn't duplicating an existing collection existing_collection = request.db.Collection.find_one({ - 'creator': request.user._id, + 'creator': request.user.id, 'title':collection.title}) if existing_collection: -- cgit v1.2.3 From 3d9143323019e0793451eac60eef8e55c09f6c47 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 16 Dec 2012 00:50:20 +0100 Subject: Move things from routing.py to tools/routing.py This stops a cyclic import. Move add_route, mount and endpoint_to_controller into tools/routing.py and change all callers. --- mediagoblin/submit/routing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/routing.py b/mediagoblin/submit/routing.py index fbe3c39c..085344fd 100644 --- a/mediagoblin/submit/routing.py +++ b/mediagoblin/submit/routing.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from mediagoblin.routing import add_route +from mediagoblin.tools.routing import add_route add_route('mediagoblin.submit.start', '/submit/', 'mediagoblin.submit.views:submit_start') -- cgit v1.2.3 From b39d1f2351352fca21666137fa137eb64926a036 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 23 Dec 2012 21:01:13 +0100 Subject: Mongo removal: Remove the validate=True arg to obj.save() all callers were forced to use validate=True anyway. So remove this useless stuff. --- mediagoblin/submit/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 3628fa0d..1f0e927e 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -112,7 +112,7 @@ def submit_start(request): entry.queued_task_id = task_id # Save now so we have this data before kicking off processing - entry.save(validate=True) + entry.save() # Pass off to processing # @@ -210,7 +210,7 @@ def add_collection(request, media=None): messages.add_message( request, messages.ERROR, _('You already have a collection called "%s"!' % collection.title)) else: - collection.save(validate=True) + collection.save() add_message(request, SUCCESS, _('Collection "%s" added!' % collection.title)) -- cgit v1.2.3 From ac8212fe657802eaf9dfd9d6c0f28f25b750399e Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 23 Dec 2012 21:44:05 +0100 Subject: Remove mongo style .id = ObjectId() On SQL we can't generate the primary key on our own. So just remove this stuff. --- mediagoblin/submit/views.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1f0e927e..b52fca33 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -29,7 +29,6 @@ _log = logging.getLogger(__name__) from werkzeug.utils import secure_filename from werkzeug.datastructures import FileStorage -from mediagoblin.db.util import ObjectId from mediagoblin.tools.text import convert_to_tag_list_of_dicts from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.response import render_to_response, redirect @@ -66,7 +65,6 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() - entry.id = ObjectId() entry.media_type = unicode(media_type) entry.title = ( unicode(request.form['title']) @@ -193,10 +191,8 @@ def add_collection(request, media=None): if request.method == 'POST' and submit_form.validate(): try: collection = request.db.Collection() - collection.id = ObjectId() collection.title = unicode(request.form['title']) - collection.description = unicode(request.form.get('description')) collection.creator = request.user.id collection.generate_slug() -- cgit v1.2.3 From be1f0f7d33440d96c2bcc1c7f3dfd5cbb356e54f Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 17 Dec 2012 19:42:31 +0100 Subject: upload refactor: push url handling Start to refactor our upload handling in main submit and the api. Start factoring out the handling of PuSH url handling. --- mediagoblin/submit/lib.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ mediagoblin/submit/views.py | 28 ++----------------------- 2 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 mediagoblin/submit/lib.py (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py new file mode 100644 index 00000000..57069e84 --- /dev/null +++ b/mediagoblin/submit/lib.py @@ -0,0 +1,50 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# 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 . + +import urllib +import urllib2 +import logging + +from mediagoblin import mg_globals + +_log = logging.getLogger(__name__) + + +def handle_push_urls(request): + if mg_globals.app_config["push_urls"]: + feed_url = request.urlgen( + 'mediagoblin.user_pages.atom_feed', + qualified=True, + user=request.user.username) + hubparameters = { + 'hub.mode': 'publish', + 'hub.url': feed_url} + hubdata = urllib.urlencode(hubparameters) + hubheaders = { + "Content-type": "application/x-www-form-urlencoded", + "Connection": "close"} + for huburl in mg_globals.app_config["push_urls"]: + hubrequest = urllib2.Request(huburl, hubdata, hubheaders) + try: + hubresponse = urllib2.urlopen(hubrequest) + except urllib2.HTTPError as exc: + # This is not a big issue, the item will be fetched + # by the PuSH server next time we hit it + _log.warning( + "push url %r gave error %r", huburl, exc.code) + except urllib2.URLError as exc: + _log.warning( + "push url %r is unreachable %r", huburl, exc.reason) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index b52fca33..6d4c8be3 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -20,8 +20,6 @@ import uuid from os.path import splitext from celery import registry -import urllib -import urllib2 import logging _log = logging.getLogger(__name__) @@ -39,6 +37,7 @@ from mediagoblin.processing.task import ProcessMedia from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import sniff_media, \ InvalidFileType, FileTypeNotSupported +from mediagoblin.submit.lib import handle_push_urls @require_active_login @@ -134,30 +133,7 @@ def submit_start(request): # re-raise the exception raise - if mg_globals.app_config["push_urls"]: - feed_url = request.urlgen( - 'mediagoblin.user_pages.atom_feed', - qualified=True, - user=request.user.username) - hubparameters = { - 'hub.mode': 'publish', - 'hub.url': feed_url} - hubdata = urllib.urlencode(hubparameters) - hubheaders = { - "Content-type": "application/x-www-form-urlencoded", - "Connection": "close"} - for huburl in mg_globals.app_config["push_urls"]: - hubrequest = urllib2.Request(huburl, hubdata, hubheaders) - try: - hubresponse = urllib2.urlopen(hubrequest) - except urllib2.HTTPError as exc: - # This is not a big issue, the item will be fetched - # by the PuSH server next time we hit it - _log.warning( - "push url %r gave error %r", huburl, exc.code) - except urllib2.URLError as exc: - _log.warning( - "push url %r is unreachable %r", huburl, exc.reason) + handle_push_urls(request) add_message(request, SUCCESS, _('Woohoo! Submitted!')) -- cgit v1.2.3 From 86bb44ef121e64e2a2c7ad175af444000a7ca0c9 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 17 Dec 2012 19:54:26 +0100 Subject: Factor out the actual calling of the processing. Calling the processing task and handling the exceptions is easy, but has a bunch of caveats, so factor it out into an easy callable function. --- mediagoblin/submit/lib.py | 24 ++++++++++++++++++++++++ mediagoblin/submit/views.py | 23 ++--------------------- 2 files changed, 26 insertions(+), 21 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 57069e84..f174d4ea 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -17,12 +17,36 @@ import urllib import urllib2 import logging +from celery import registry from mediagoblin import mg_globals +from mediagoblin.processing import mark_entry_failed +from mediagoblin.processing.task import ProcessMedia + _log = logging.getLogger(__name__) +def run_process_media(entry): + process_media = registry.tasks[ProcessMedia.name] + try: + process_media.apply_async( + [unicode(entry.id)], {}, + task_id=entry.queued_task_id) + except BaseException as exc: + # The purpose of this section is because when running in "lazy" + # or always-eager-with-exceptions-propagated celery mode that + # the failure handling won't happen on Celery end. Since we + # expect a lot of users to run things in this way we have to + # capture stuff here. + # + # ... not completely the diaper pattern because the + # exception is re-raised :) + mark_entry_failed(entry.id, exc) + # re-raise the exception + raise + + def handle_push_urls(request): if mg_globals.app_config["push_urls"]: feed_url = request.urlgen( diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 6d4c8be3..ad9fedae 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -19,7 +19,6 @@ import mediagoblin.mg_globals as mg_globals import uuid from os.path import splitext -from celery import registry import logging _log = logging.getLogger(__name__) @@ -32,12 +31,10 @@ from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.response import render_to_response, redirect from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms -from mediagoblin.processing import mark_entry_failed -from mediagoblin.processing.task import ProcessMedia from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import sniff_media, \ InvalidFileType, FileTypeNotSupported -from mediagoblin.submit.lib import handle_push_urls +from mediagoblin.submit.lib import handle_push_urls, run_process_media @require_active_login @@ -115,23 +112,7 @@ def submit_start(request): # # (... don't change entry after this point to avoid race # conditions with changes to the document via processing code) - process_media = registry.tasks[ProcessMedia.name] - try: - process_media.apply_async( - [unicode(entry.id)], {}, - task_id=task_id) - except BaseException as exc: - # The purpose of this section is because when running in "lazy" - # or always-eager-with-exceptions-propagated celery mode that - # the failure handling won't happen on Celery end. Since we - # expect a lot of users to run things in this way we have to - # capture stuff here. - # - # ... not completely the diaper pattern because the - # exception is re-raised :) - mark_entry_failed(entry.id, exc) - # re-raise the exception - raise + run_process_media(entry) handle_push_urls(request) -- cgit v1.2.3 From 8eb47d02d922fa90abd56729c6c6898f43cf7413 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 17 Dec 2012 20:05:37 +0100 Subject: Processing: Factor out prepare_entry. prepare_entry handles the task_id setup and generating a queue filename and file. it returns the queue file. --- mediagoblin/submit/lib.py | 28 ++++++++++++++++++++++++++++ mediagoblin/submit/views.py | 28 +++------------------------- 2 files changed, 31 insertions(+), 25 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index f174d4ea..6660eb53 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -17,7 +17,9 @@ import urllib import urllib2 import logging +import uuid from celery import registry +from werkzeug.utils import secure_filename from mediagoblin import mg_globals from mediagoblin.processing import mark_entry_failed @@ -27,6 +29,32 @@ from mediagoblin.processing.task import ProcessMedia _log = logging.getLogger(__name__) +def prepare_entry(request, entry, filename): + # We generate this ourselves so we know what the taks id is for + # retrieval later. + + # (If we got it off the task's auto-generation, there'd be + # a risk of a race condition when we'd save after sending + # off the task) + task_id = unicode(uuid.uuid4()) + entry.queued_task_id = task_id + + # Now store generate the queueing related filename + queue_filepath = request.app.queue_store.get_unique_filepath( + ['media_entries', + task_id, + secure_filename(filename)]) + + # queue appropriately + queue_file = request.app.queue_store.get_file( + queue_filepath, 'wb') + + # Add queued filename to the entry + entry.queued_media_file = queue_filepath + + return queue_file + + def run_process_media(entry): process_media = registry.tasks[ProcessMedia.name] try: diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index ad9fedae..d36f5f5d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -16,14 +16,12 @@ from mediagoblin import messages import mediagoblin.mg_globals as mg_globals -import uuid from os.path import splitext import logging _log = logging.getLogger(__name__) -from werkzeug.utils import secure_filename from werkzeug.datastructures import FileStorage from mediagoblin.tools.text import convert_to_tag_list_of_dicts @@ -34,7 +32,8 @@ from mediagoblin.submit import forms as submit_forms from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import sniff_media, \ InvalidFileType, FileTypeNotSupported -from mediagoblin.submit.lib import handle_push_urls, run_process_media +from mediagoblin.submit.lib import handle_push_urls, run_process_media, \ + prepare_entry @require_active_login @@ -79,32 +78,11 @@ def submit_start(request): # Generate a slug from the title entry.generate_slug() - # We generate this ourselves so we know what the taks id is for - # retrieval later. - - # (If we got it off the task's auto-generation, there'd be - # a risk of a race condition when we'd save after sending - # off the task) - task_id = unicode(uuid.uuid4()) - - # Now store generate the queueing related filename - queue_filepath = request.app.queue_store.get_unique_filepath( - ['media_entries', - task_id, - secure_filename(filename)]) - - # queue appropriately - queue_file = request.app.queue_store.get_file( - queue_filepath, 'wb') + queue_file = prepare_entry(request, entry, filename) with queue_file: queue_file.write(request.files['file'].stream.read()) - # Add queued filename to the entry - entry.queued_media_file = queue_filepath - - entry.queued_task_id = task_id - # Save now so we have this data before kicking off processing entry.save() -- cgit v1.2.3 From b228d89715558281d9573543dd0d6c74836d42ca Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 26 Dec 2012 23:40:42 +0100 Subject: prepare_queue_task: Take app not request. First rename prepare_entry to prepare_queue_task, because this is really more like what this thing does. Thanks to Velmont for noting that we do not need a request in here, but an "app" is good enough. Which means, that this stuff can be called from tool scripts too. --- mediagoblin/submit/lib.py | 9 ++++++--- mediagoblin/submit/views.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 6660eb53..db5dfe53 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -29,7 +29,10 @@ from mediagoblin.processing.task import ProcessMedia _log = logging.getLogger(__name__) -def prepare_entry(request, entry, filename): +def prepare_queue_task(app, entry, filename): + """ + Prepare a MediaEntry for the processing queue and get a queue file + """ # We generate this ourselves so we know what the taks id is for # retrieval later. @@ -40,13 +43,13 @@ def prepare_entry(request, entry, filename): entry.queued_task_id = task_id # Now store generate the queueing related filename - queue_filepath = request.app.queue_store.get_unique_filepath( + queue_filepath = app.queue_store.get_unique_filepath( ['media_entries', task_id, secure_filename(filename)]) # queue appropriately - queue_file = request.app.queue_store.get_file( + queue_file = app.queue_store.get_file( queue_filepath, 'wb') # Add queued filename to the entry diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index d36f5f5d..2d609b31 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -33,7 +33,7 @@ from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import sniff_media, \ InvalidFileType, FileTypeNotSupported from mediagoblin.submit.lib import handle_push_urls, run_process_media, \ - prepare_entry + prepare_queue_task @require_active_login @@ -78,7 +78,7 @@ def submit_start(request): # Generate a slug from the title entry.generate_slug() - queue_file = prepare_entry(request, entry, filename) + queue_file = prepare_queue_task(request.app, entry, filename) with queue_file: queue_file.write(request.files['file'].stream.read()) -- cgit v1.2.3 From 2cfffd5ed8c054bb60c27ede4e69667f97d12b09 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 15 Jan 2013 14:41:30 +0100 Subject: Make PuSHing the Pubhubsubbub server an async task (#436, #585) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notifying the PuSH servers had 3 problems.  1) it was done immediately after sending of the processing task to celery. So if celery was run in a separate process we would notify the PuSH servers before the new media was processed/ visible. (#436) 2) Notification code was called in submit/views.py, so submitting via the API never resulted in notifications. (#585) 3) If Notifying the PuSH server failed, we would never retry. The solution was to make the PuSH notification an asynchronous subtask. This way: 1) it will only be called once async processing has finished, 2) it is in the main processing code path, so even API calls will result in notifications, and 3) We retry 3 times in case of failure before giving up. If the server is in a separate process, we will wait 3x 2 minutes before retrying the notification. The only downside is that the celery server needs to have access to the internet to ping the PuSH server. If that is a problem, we need to make the task belong to a special group of celery servers that has access to the internet. As a side effect, I believe I removed the limitation that prevented us from upgrading celery. Signed-off-by: Sebastian Spaeth --- mediagoblin/submit/lib.py | 41 ++++++----------------------------------- mediagoblin/submit/views.py | 8 ++------ 2 files changed, 8 insertions(+), 41 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index db5dfe53..ba07c6fa 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -14,16 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import urllib -import urllib2 import logging import uuid -from celery import registry from werkzeug.utils import secure_filename -from mediagoblin import mg_globals from mediagoblin.processing import mark_entry_failed -from mediagoblin.processing.task import ProcessMedia +from mediagoblin.processing.task import process_media _log = logging.getLogger(__name__) @@ -58,11 +54,13 @@ def prepare_queue_task(app, entry, filename): return queue_file -def run_process_media(entry): - process_media = registry.tasks[ProcessMedia.name] +def run_process_media(entry, request): + feed_url = request.urlgen( + 'mediagoblin.user_pages.atom_feed', + qualified=True, user=request.user.username) try: process_media.apply_async( - [unicode(entry.id)], {}, + [entry.id, feed_url], {}, task_id=entry.queued_task_id) except BaseException as exc: # The purpose of this section is because when running in "lazy" @@ -76,30 +74,3 @@ def run_process_media(entry): mark_entry_failed(entry.id, exc) # re-raise the exception raise - - -def handle_push_urls(request): - if mg_globals.app_config["push_urls"]: - feed_url = request.urlgen( - 'mediagoblin.user_pages.atom_feed', - qualified=True, - user=request.user.username) - hubparameters = { - 'hub.mode': 'publish', - 'hub.url': feed_url} - hubdata = urllib.urlencode(hubparameters) - hubheaders = { - "Content-type": "application/x-www-form-urlencoded", - "Connection": "close"} - for huburl in mg_globals.app_config["push_urls"]: - hubrequest = urllib2.Request(huburl, hubdata, hubheaders) - try: - hubresponse = urllib2.urlopen(hubrequest) - except urllib2.HTTPError as exc: - # This is not a big issue, the item will be fetched - # by the PuSH server next time we hit it - _log.warning( - "push url %r gave error %r", huburl, exc.code) - except urllib2.URLError as exc: - _log.warning( - "push url %r is unreachable %r", huburl, exc.reason) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 2d609b31..145b9f5e 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -32,8 +32,7 @@ from mediagoblin.submit import forms as submit_forms from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import sniff_media, \ InvalidFileType, FileTypeNotSupported -from mediagoblin.submit.lib import handle_push_urls, run_process_media, \ - prepare_queue_task +from mediagoblin.submit.lib import run_process_media, prepare_queue_task @require_active_login @@ -90,10 +89,7 @@ def submit_start(request): # # (... don't change entry after this point to avoid race # conditions with changes to the document via processing code) - run_process_media(entry) - - handle_push_urls(request) - + run_process_media(entry, request) add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", -- cgit v1.2.3 From c7b3d070b65a84e3bfa9d8e3e6f52aac6552910f Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 15 Jan 2013 15:03:00 +0100 Subject: Don't pass request into run_process_media People(tm) want to start run_process_media from the CLI and might not have a request object handy. So pass in the feed_url into run_process_media rather than the request object and allow the feed url to be empty (resulting in no PuSH notification at all then). Signed-off-by: Sebastian Spaeth --- mediagoblin/submit/lib.py | 12 ++++++++---- mediagoblin/submit/views.py | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index ba07c6fa..679fc543 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -54,10 +54,14 @@ def prepare_queue_task(app, entry, filename): return queue_file -def run_process_media(entry, request): - feed_url = request.urlgen( - 'mediagoblin.user_pages.atom_feed', - qualified=True, user=request.user.username) +def run_process_media(entry, feed_url=None): + """Process the media asynchronously + + :param entry: MediaEntry() instance to be processed. + :param feed_url: A string indicating the feed_url that the PuSH servers + should be notified of. This will be sth like: `request.urlgen( + 'mediagoblin.user_pages.atom_feed',qualified=True, + user=request.user.username)`""" try: process_media.apply_async( [entry.id, feed_url], {}, diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 145b9f5e..49ab4230 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -89,7 +89,10 @@ def submit_start(request): # # (... don't change entry after this point to avoid race # conditions with changes to the document via processing code) - run_process_media(entry, request) + feed_url = request.urlgen( + 'mediagoblin.user_pages.atom_feed', + qualified=True, user=request.user.username) + run_process_media(entry, feed_url) add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", -- cgit v1.2.3 From dc4dfbde350fdd9eac50448e42f2c8b209dd6ea8 Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Sat, 10 Nov 2012 16:59:37 -0800 Subject: Add a license preference field This feature is absolutely necessary. Now a user can simply define their default license and quickly go through a form, as opposed to stopping to click on the select and choosing the same option over and over again. Also added DB migration for the field, so that's working now, too. Rebased by Sebastian and made the default value to be unicode. Reviewed-by: Sebastian Spaeth --- mediagoblin/submit/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 2d609b31..38adf85f 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -41,7 +41,8 @@ def submit_start(request): """ First view for submitting a file. """ - submit_form = submit_forms.SubmitStartForm(request.form) + submit_form = submit_forms.SubmitStartForm(request.form, + license=request.user.get('license_preference')) if request.method == 'POST' and submit_form.validate(): if not ('file' in request.files -- cgit v1.2.3 From 066d49b2c1c8319a5b7805b4a68a8ee2b1c59ad1 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 22 Jan 2013 22:18:08 +0100 Subject: user.get('moo') -> user.moo User fields are always existent, so there is no need to .get() them, just use them directly. Signed-off-by: Sebastian Spaeth --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 4055d394..def7e839 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -41,7 +41,7 @@ def submit_start(request): First view for submitting a file. """ submit_form = submit_forms.SubmitStartForm(request.form, - license=request.user.get('license_preference')) + license=request.user.license_preference) if request.method == 'POST' and submit_form.validate(): if not ('file' in request.files -- cgit v1.2.3 From c5673a1300d2497a4b8fdd72bfa93b026bccfd6e Mon Sep 17 00:00:00 2001 From: Hans Lo Date: Wed, 27 Mar 2013 23:56:33 -0400 Subject: Use WTForms data field in submit/views.py --- mediagoblin/submit/views.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index def7e839..21aa8195 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -62,18 +62,18 @@ def submit_start(request): entry = request.db.MediaEntry() entry.media_type = unicode(media_type) entry.title = ( - unicode(request.form['title']) + unicode(submit_form.title.data) or unicode(splitext(filename)[0])) - entry.description = unicode(request.form.get('description')) + entry.description = unicode(submit_form.description.data) - entry.license = unicode(request.form.get('license', "")) or None + entry.license = unicode(submit_form.license.data) or None entry.uploader = request.user.id # Process the user's folksonomy "tags" entry.tags = convert_to_tag_list_of_dicts( - request.form.get('tags')) + submit_form.tags.data) # Generate a slug from the title entry.generate_slug() @@ -127,8 +127,8 @@ def add_collection(request, media=None): try: collection = request.db.Collection() - collection.title = unicode(request.form['title']) - collection.description = unicode(request.form.get('description')) + collection.title = unicode(submit_form.title.data) + collection.description = unicode(submit_form.description.data) collection.creator = request.user.id collection.generate_slug() -- cgit v1.2.3 From 2ef2f46e73845dcd55666cad49c5a17908bf5b46 Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 22 Mar 2013 15:45:21 +0100 Subject: Refactor file field checking. When uploading, the file field needs some checks, it seems. So refactor them into check_file_field and use around. --- mediagoblin/submit/lib.py | 11 +++++++++++ mediagoblin/submit/views.py | 8 +++----- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 679fc543..a5483471 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -17,6 +17,7 @@ import logging import uuid from werkzeug.utils import secure_filename +from werkzeug.datastructures import FileStorage from mediagoblin.processing import mark_entry_failed from mediagoblin.processing.task import process_media @@ -25,6 +26,16 @@ from mediagoblin.processing.task import process_media _log = logging.getLogger(__name__) +def check_file_field(request, field_name): + """Check if a file field meets minimal criteria""" + retval = (field_name in request.files + and isinstance(request.files[field_name], FileStorage) + and request.files[field_name].stream) + if not retval: + _log.debug("Form did not contain proper file field %s", field_name) + return retval + + def prepare_queue_task(app, entry, filename): """ Prepare a MediaEntry for the processing queue and get a queue file diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index def7e839..1e47d259 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -22,7 +22,6 @@ import logging _log = logging.getLogger(__name__) -from werkzeug.datastructures import FileStorage from mediagoblin.tools.text import convert_to_tag_list_of_dicts from mediagoblin.tools.translate import pass_to_ugettext as _ @@ -32,7 +31,8 @@ from mediagoblin.submit import forms as submit_forms from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import sniff_media, \ InvalidFileType, FileTypeNotSupported -from mediagoblin.submit.lib import run_process_media, prepare_queue_task +from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \ + run_process_media @require_active_login @@ -44,9 +44,7 @@ def submit_start(request): license=request.user.license_preference) if request.method == 'POST' and submit_form.validate(): - if not ('file' in request.files - and isinstance(request.files['file'], FileStorage) - and request.files['file'].stream): + if not check_file_field(request, 'file'): submit_form.file.errors.append( _(u'You must provide a file.')) else: -- cgit v1.2.3 From cec9648c11d851baa8add4f49cdcdbc5416386a9 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Tue, 23 Apr 2013 09:39:51 +0300 Subject: mediagoblin/submit/lib.py: fix typo Signed-off-by: Alon Levy --- mediagoblin/submit/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index a5483471..7c3b8ab3 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -40,7 +40,7 @@ def prepare_queue_task(app, entry, filename): """ Prepare a MediaEntry for the processing queue and get a queue file """ - # We generate this ourselves so we know what the taks id is for + # We generate this ourselves so we know what the task id is for # retrieval later. # (If we got it off the task's auto-generation, there'd be -- cgit v1.2.3 From 665b9c420aa1a7c768e44a8639b6fc185823e202 Mon Sep 17 00:00:00 2001 From: Aditi Mittal Date: Mon, 22 Apr 2013 19:18:45 +0530 Subject: Fix-bug-667-Use-lazy_pass_to_ugettext-for-forms. --- mediagoblin/submit/forms.py | 2 +- mediagoblin/submit/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index bd1e904f..e9bd93fd 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -18,7 +18,7 @@ import wtforms from mediagoblin.tools.text import tag_length_validator -from mediagoblin.tools.translate import fake_ugettext_passthrough as _ +from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ from mediagoblin.tools.licenses import licenses_as_choices diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 9d31c844..1a7c0ced 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -24,7 +24,7 @@ _log = logging.getLogger(__name__) from mediagoblin.tools.text import convert_to_tag_list_of_dicts -from mediagoblin.tools.translate import pass_to_ugettext as _ +from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ from mediagoblin.tools.response import render_to_response, redirect from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms -- cgit v1.2.3 From a789b713f534156d923cf6cc9070559ac8b6c616 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 24 Apr 2013 14:39:16 -0500 Subject: Switching non-forms back to using normal pass_to_ugettext --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1a7c0ced..9d31c844 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -24,7 +24,7 @@ _log = logging.getLogger(__name__) from mediagoblin.tools.text import convert_to_tag_list_of_dicts -from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ +from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.response import render_to_response, redirect from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms -- cgit v1.2.3 From 2041ceae1ffd29630988c47fc766a1b9dcf9bbf7 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 27 Apr 2013 14:52:08 +0200 Subject: Fix translations for collections and drop useless try. Don't do: _("With some value: %s" % value) Please do: _("WIth some value: %s") % value Fixed for collection messages. Also removed a try: some_code. except Exception as e: raise No point in doing that. Fixing the indentation of some_code comes in an extra commit, because changing indentation is annoying enough alone, so don't mix it with other changes. --- mediagoblin/submit/views.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 9d31c844..c9735fd3 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -114,6 +114,7 @@ def submit_start(request): {'submit_form': submit_form, 'app_config': mg_globals.app_config}) + @require_active_login def add_collection(request, media=None): """ @@ -122,7 +123,6 @@ def add_collection(request, media=None): submit_form = submit_forms.AddCollectionForm(request.form) if request.method == 'POST' and submit_form.validate(): - try: collection = request.db.Collection() collection.title = unicode(submit_form.title.data) @@ -136,19 +136,18 @@ def add_collection(request, media=None): 'title':collection.title}) if existing_collection: - messages.add_message( - request, messages.ERROR, _('You already have a collection called "%s"!' % collection.title)) + add_message(request, messages.ERROR, + _('You already have a collection called "%s"!') \ + % collection.title) else: collection.save() - add_message(request, SUCCESS, _('Collection "%s" added!' % collection.title)) + add_message(request, SUCCESS, + _('Collection "%s" added!') % collection.title) return redirect(request, "mediagoblin.user_pages.user_home", user=request.user.username) - except Exception as e: - raise - return render_to_response( request, 'mediagoblin/submit/collection.html', -- cgit v1.2.3 From adf53036a5c10d9f32e2505d23b72b3bd89728c9 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 27 Apr 2013 15:04:56 +0200 Subject: Remove extra indentation left over from previous commit. This only removes an unneeded extra indentation, left over from the previous removal of code around. Extra commit so it is easy to check that it only changes indentation. --- mediagoblin/submit/views.py | 48 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index c9735fd3..e964ec12 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -123,30 +123,30 @@ def add_collection(request, media=None): submit_form = submit_forms.AddCollectionForm(request.form) if request.method == 'POST' and submit_form.validate(): - collection = request.db.Collection() - - collection.title = unicode(submit_form.title.data) - collection.description = unicode(submit_form.description.data) - collection.creator = request.user.id - collection.generate_slug() - - # Make sure this user isn't duplicating an existing collection - existing_collection = request.db.Collection.find_one({ - 'creator': request.user.id, - 'title':collection.title}) - - if existing_collection: - add_message(request, messages.ERROR, - _('You already have a collection called "%s"!') \ - % collection.title) - else: - collection.save() - - add_message(request, SUCCESS, - _('Collection "%s" added!') % collection.title) - - return redirect(request, "mediagoblin.user_pages.user_home", - user=request.user.username) + collection = request.db.Collection() + + collection.title = unicode(submit_form.title.data) + collection.description = unicode(submit_form.description.data) + collection.creator = request.user.id + collection.generate_slug() + + # Make sure this user isn't duplicating an existing collection + existing_collection = request.db.Collection.find_one({ + 'creator': request.user.id, + 'title':collection.title}) + + if existing_collection: + add_message(request, messages.ERROR, + _('You already have a collection called "%s"!') \ + % collection.title) + else: + collection.save() + + add_message(request, SUCCESS, + _('Collection "%s" added!') % collection.title) + + return redirect(request, "mediagoblin.user_pages.user_home", + user=request.user.username) return render_to_response( request, -- cgit v1.2.3 From 6c1467d570a4da68ef8b4edac9aecdb9c87a61de Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 21 May 2013 00:28:37 +0200 Subject: Refactor submit util new_upload_entry This tool creates an initial media entry for a given user. No magic. It just prefills the license with the user's default license and adds the user as uploader. --- mediagoblin/submit/lib.py | 11 +++++++++++ mediagoblin/submit/views.py | 6 ++---- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 7c3b8ab3..7e85696b 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -19,6 +19,7 @@ import uuid from werkzeug.utils import secure_filename from werkzeug.datastructures import FileStorage +from mediagoblin.db.models import MediaEntry from mediagoblin.processing import mark_entry_failed from mediagoblin.processing.task import process_media @@ -36,6 +37,16 @@ def check_file_field(request, field_name): return retval +def new_upload_entry(user): + """ + Create a new MediaEntry for uploading + """ + entry = MediaEntry() + entry.uploader = user.id + entry.license = user.license_preference + return entry + + def prepare_queue_task(app, entry, filename): """ Prepare a MediaEntry for the processing queue and get a queue file diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index e964ec12..a70c89b4 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -32,7 +32,7 @@ from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import sniff_media, \ InvalidFileType, FileTypeNotSupported from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \ - run_process_media + run_process_media, new_upload_entry @require_active_login @@ -57,7 +57,7 @@ def submit_start(request): request.files['file']) # create entry and save in database - entry = request.db.MediaEntry() + entry = new_upload_entry(request.user) entry.media_type = unicode(media_type) entry.title = ( unicode(submit_form.title.data) @@ -67,8 +67,6 @@ def submit_start(request): entry.license = unicode(submit_form.license.data) or None - entry.uploader = request.user.id - # Process the user's folksonomy "tags" entry.tags = convert_to_tag_list_of_dicts( submit_form.tags.data) -- cgit v1.2.3