max file size
This commit is contained in:
parent
2f74de492e
commit
ecb4512822
@ -78,6 +78,9 @@ plugin_linked_assets_dir = string(default="%(here)s/user_dev/plugin_static/")
|
||||
# Default user upload limit (in Mb)
|
||||
upload_limit = integer(default=None)
|
||||
|
||||
# Max file size (in Mb)
|
||||
max_file_size = integer(default=5000)
|
||||
|
||||
[jinja2]
|
||||
# Jinja2 supports more directives than the minimum required by mediagoblin.
|
||||
# This setting allows users creating custom templates to specify a list of
|
||||
|
@ -17,30 +17,41 @@
|
||||
|
||||
import wtforms
|
||||
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin.tools.text import tag_length_validator
|
||||
from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
|
||||
from mediagoblin.tools.licenses import licenses_as_choices
|
||||
|
||||
|
||||
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'),
|
||||
description=_("""You can use
|
||||
<a href="http://daringfireball.net/projects/markdown/basics">
|
||||
Markdown</a> for formatting."""))
|
||||
tags = wtforms.TextField(
|
||||
_('Tags'),
|
||||
[tag_length_validator],
|
||||
description=_(
|
||||
"Separate tags by commas."))
|
||||
license = wtforms.SelectField(
|
||||
_('License'),
|
||||
[wtforms.validators.Optional(),],
|
||||
choices=licenses_as_choices())
|
||||
def get_submit_start_form(form, **kwargs):
|
||||
max_file_size = mg_globals.app_config.get('max_file_size', None)
|
||||
desc = None
|
||||
if max_file_size:
|
||||
desc = _('Max file size: {0} mb'.format(max_file_size))
|
||||
|
||||
class SubmitStartForm(wtforms.Form):
|
||||
file = wtforms.FileField(
|
||||
_('File'),
|
||||
description=desc)
|
||||
title = wtforms.TextField(
|
||||
_('Title'),
|
||||
[wtforms.validators.Length(min=0, max=500)])
|
||||
description = wtforms.TextAreaField(
|
||||
_('Description of this work'),
|
||||
description=_("""You can use
|
||||
<a href="http://daringfireball.net/projects/markdown/basics">
|
||||
Markdown</a> for formatting."""))
|
||||
tags = wtforms.TextField(
|
||||
_('Tags'),
|
||||
[tag_length_validator],
|
||||
description=_(
|
||||
"Separate tags by commas."))
|
||||
license = wtforms.SelectField(
|
||||
_('License'),
|
||||
[wtforms.validators.Optional(),],
|
||||
choices=licenses_as_choices())
|
||||
|
||||
return SubmitStartForm(form, **kwargs)
|
||||
|
||||
class AddCollectionForm(wtforms.Form):
|
||||
title = wtforms.TextField(
|
||||
|
@ -57,7 +57,7 @@ def submit_start(request):
|
||||
return redirect(request, "mediagoblin.user_pages.user_home",
|
||||
user=request.user.username)
|
||||
|
||||
submit_form = submit_forms.SubmitStartForm(request.form,
|
||||
submit_form = submit_forms.get_submit_start_form(request.form,
|
||||
license=request.user.license_preference)
|
||||
|
||||
if request.method == 'POST' and submit_form.validate():
|
||||
@ -105,32 +105,40 @@ def submit_start(request):
|
||||
entry.queued_media_file) / (1024.0 * 1024)
|
||||
file_size = float('{0:.2f}'.format(file_size))
|
||||
|
||||
error = False
|
||||
|
||||
# Check if file size is over the limit
|
||||
max_file_size = mg_globals.app_config.get('max_file_size', None)
|
||||
if max_file_size and file_size >= max_file_size:
|
||||
submit_form.file.errors.append(
|
||||
_(u'Sorry, the file size is too big.'))
|
||||
error = True
|
||||
|
||||
# Check if user is over upload limit
|
||||
if upload_limit and (user.uploaded + file_size) >= upload_limit:
|
||||
submit_form.file.errors.append(
|
||||
_('Sorry, uploading this file will put you over your'
|
||||
' upload limit.'))
|
||||
return redirect(request, "mediagoblin.submit.start",
|
||||
user=user.username)
|
||||
error = True
|
||||
|
||||
user.uploaded = user.uploaded + file_size
|
||||
user.save()
|
||||
if not error:
|
||||
user.uploaded = user.uploaded + file_size
|
||||
user.save()
|
||||
|
||||
entry.file_size = file_size
|
||||
entry.file_size = file_size
|
||||
|
||||
# Save now so we have this data before kicking off processing
|
||||
entry.save()
|
||||
# Save now so we have this data before kicking off processing
|
||||
entry.save()
|
||||
|
||||
# Pass off to async processing
|
||||
#
|
||||
# (... don't change entry after this point to avoid race
|
||||
# conditions with changes to the document via processing code)
|
||||
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!'))
|
||||
# Pass off to processing
|
||||
#
|
||||
# (... don't change entry after this point to avoid race
|
||||
# conditions with changes to the document via processing code)
|
||||
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!'))
|
||||
|
||||
add_comment_subscription(request.user, entry)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user