Breaking out get_upload_file_limits into its own utility.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 14 Nov 2013 17:06:10 +0000 (11:06 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 14 Nov 2013 17:06:10 +0000 (11:06 -0600)
This commit sponsored by Mikael Nordfeldth.  Thank you!

mediagoblin/submit/lib.py
mediagoblin/submit/views.py

index 1314df1ebdec142e2d7417f7531c62efafee85af..975d920e69da486a8fd4b101b148253eeec0d6eb 100644 (file)
@@ -21,13 +21,13 @@ from os.path import splitext
 from werkzeug.utils import secure_filename
 from werkzeug.datastructures import FileStorage
 
+from mediagoblin import mg_globals
 from mediagoblin.tools.text import convert_to_tag_list_of_dicts
 from mediagoblin.db.models import MediaEntry
 from mediagoblin.processing import mark_entry_failed
 from mediagoblin.processing.task import ProcessMedia
 from mediagoblin.notifications import add_comment_subscription
-from mediagoblin.media_types import sniff_media, \
-    InvalidFileType, FileTypeNotSupported
+from mediagoblin.media_types import sniff_media
 
 
 _log = logging.getLogger(__name__)
@@ -53,6 +53,20 @@ def new_upload_entry(user):
     return entry
 
 
+def get_upload_file_limits(user):
+    """
+    Get the upload_limit and max_file_size for this user
+    """
+    if user.upload_limit >= 0:
+        upload_limit = user.upload_limit
+    else:
+        upload_limit = mg_globals.app_config.get('upload_limit', None)
+
+    max_file_size = mg_globals.app_config.get('max_file_size', None)
+
+    return upload_limit, max_file_size
+
+
 class UploadLimitError(Exception):
     """
     General exception for when an upload will be over some upload limit
@@ -173,6 +187,8 @@ def submit_media(mg_app, user, submitted_file, filename,
 
     add_comment_subscription(user, entry)
 
+    return entry
+
 
 def prepare_queue_task(app, entry, filename):
     """
index dc618861589cfd7331e705f67ebe97c4e56832de..e2c78638a9e16335506c6aa76c34effde589b74a 100644 (file)
@@ -29,7 +29,8 @@ from mediagoblin.submit import forms as submit_forms
 from mediagoblin.messages import add_message, SUCCESS
 from mediagoblin.media_types import \
     InvalidFileType, FileTypeNotSupported
-from mediagoblin.submit.lib import check_file_field, submit_media, \
+from mediagoblin.submit.lib import \
+    check_file_field, submit_media, get_upload_file_limits, \
     FileUploadLimit, UserUploadLimit, UserPastUploadLimit
 
 
@@ -39,20 +40,14 @@ def submit_start(request):
     """
     First view for submitting a file.
     """
-    user = request.user
-    if user.upload_limit >= 0:
-        upload_limit = user.upload_limit
-    else:
-        upload_limit = mg_globals.app_config.get('upload_limit', None)
-
-    max_file_size = mg_globals.app_config.get('max_file_size', None)
+    upload_limit, max_file_size = get_upload_file_limits(request.user)
 
     submit_form = submit_forms.get_submit_start_form(
         request.form,
         license=request.user.license_preference,
         max_file_size=max_file_size,
         upload_limit=upload_limit,
-        uploaded=user.uploaded)
+        uploaded=request.user.uploaded)
 
     if request.method == 'POST' and submit_form.validate():
         if not check_file_field(request, 'file'):
@@ -72,7 +67,7 @@ def submit_start(request):
                 add_message(request, SUCCESS, _('Woohoo! Submitted!'))
 
                 return redirect(request, "mediagoblin.user_pages.user_home",
-                            user=user.username)
+                            user=request.user.username)
 
 
             # Handle upload limit issues