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__)
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
add_comment_subscription(user, entry)
+ return entry
+
def prepare_queue_task(app, entry, filename):
"""
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
"""
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'):
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