aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/submit
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/submit')
-rw-r--r--mediagoblin/submit/forms.py2
-rw-r--r--mediagoblin/submit/lib.py35
-rwxr-xr-xmediagoblin/submit/task.py38
3 files changed, 73 insertions, 2 deletions
diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py
index e2264645..6c0e8e9c 100644
--- a/mediagoblin/submit/forms.py
+++ b/mediagoblin/submit/forms.py
@@ -59,7 +59,7 @@ def get_submit_start_form(form, **kwargs):
class AddCollectionForm(wtforms.Form):
title = wtforms.TextField(
_('Title'),
- [wtforms.validators.Length(min=0, max=500), wtforms.validators.Required()])
+ [wtforms.validators.Length(min=0, max=500), wtforms.validators.InputRequired()])
description = wtforms.TextAreaField(
_('Description of this collection'),
description=_("""You can use
diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py
index 61d5067f..637d5038 100644
--- a/mediagoblin/submit/lib.py
+++ b/mediagoblin/submit/lib.py
@@ -24,6 +24,7 @@ from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
from mediagoblin import mg_globals
+from mediagoblin.tools.response import json_response
from mediagoblin.tools.text import convert_to_tag_list_of_dicts
from mediagoblin.db.models import MediaEntry, ProcessingMetaData
from mediagoblin.processing import mark_entry_failed
@@ -100,7 +101,7 @@ class UserPastUploadLimit(UploadLimitError):
def submit_media(mg_app, user, submitted_file, filename,
title=None, description=None,
- license=None, tags_string=u"",
+ license=None, metadata=None, tags_string=u"",
upload_limit=None, max_file_size=None,
callback_url=None,
# If provided we'll do the feed_url update, otherwise ignore
@@ -144,6 +145,8 @@ def submit_media(mg_app, user, submitted_file, filename,
entry.license = license or None
+ entry.media_metadata = metadata or {}
+
# Process the user's folksonomy "tags"
entry.tags = convert_to_tag_list_of_dicts(tags_string)
@@ -259,3 +262,33 @@ def run_process_media(entry, feed_url=None,
mark_entry_failed(entry.id, exc)
# re-raise the exception
raise
+
+
+def api_upload_request(request, file_data, entry):
+ """ This handles a image upload request """
+ # Use the same kind of method from mediagoblin/submit/views:submit_start
+ entry.title = file_data.filename
+
+ # This will be set later but currently we just don't have enough information
+ entry.slug = None
+
+ queue_file = prepare_queue_task(request.app, entry, file_data.filename)
+ with queue_file:
+ queue_file.write(request.data)
+
+ entry.save()
+ return json_response(entry.serialize(request))
+
+def api_add_to_feed(request, entry):
+ """ Add media to Feed """
+ if entry.title:
+ entry.generate_slug()
+
+ feed_url = request.urlgen(
+ 'mediagoblin.user_pages.atom_feed',
+ qualified=True, user=request.user.username
+ )
+
+ run_process_media(entry, feed_url)
+ add_comment_subscription(request.user, entry)
+ return json_response(entry.serialize(request))
diff --git a/mediagoblin/submit/task.py b/mediagoblin/submit/task.py
new file mode 100755
index 00000000..4ebde502
--- /dev/null
+++ b/mediagoblin/submit/task.py
@@ -0,0 +1,38 @@
+# 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 <http://www.gnu.org/licenses/>.
+
+import celery
+import datetime
+import pytz
+
+from mediagoblin.db.models import MediaEntry
+
+@celery.task()
+def collect_garbage():
+ """
+ Garbage collection to clean up media
+
+ This will look for all critera on models to clean
+ up. This is primerally written to clean up media that's
+ entered a erroneous state.
+ """
+ cuttoff = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=1)
+
+ garbage = MediaEntry.query.filter(MediaEntry.created < cuttoff)
+ garbage = garbage.filter(MediaEntry.state == "unprocessed")
+
+ for entry in garbage.all():
+ entry.delete()