Feature #482 - Media attachments -

*   Moved attachment uploading to separate view
*   Support for multiple attachments!
This commit is contained in:
Joar Wandborg
2011-08-22 18:06:28 +02:00
parent 2c4374938f
commit 3a8c3a3855
10 changed files with 164 additions and 79 deletions

View File

@@ -28,6 +28,3 @@ class SubmitStartForm(wtforms.Form):
tags = wtforms.TextField(
'Tags',
[tag_length_validator])
attachment = wtforms.FileField(
'Attachment',
[wtforms.validators.Optional()])

View File

@@ -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',