Process media! Successfully!
This commit is contained in:
parent
1dddd4e913
commit
fa7f9c6184
@ -73,11 +73,16 @@ class MediaEntry(Document):
|
|||||||
'tags': [unicode],
|
'tags': [unicode],
|
||||||
'state': unicode,
|
'state': unicode,
|
||||||
|
|
||||||
|
# For now let's assume there can only be one main file queued
|
||||||
|
# at a time
|
||||||
|
'queued_media_file': [unicode],
|
||||||
|
|
||||||
|
# A dictionary of logical names to filepaths
|
||||||
|
'media_files': dict,
|
||||||
|
|
||||||
# The following should be lists of lists, in appropriate file
|
# The following should be lists of lists, in appropriate file
|
||||||
# record form
|
# record form
|
||||||
'media_files': list,
|
|
||||||
'attachment_files': list,
|
'attachment_files': list,
|
||||||
'queue_files': list,
|
|
||||||
|
|
||||||
# This one should just be a single file record
|
# This one should just be a single file record
|
||||||
'thumbnail_file': [unicode]}
|
'thumbnail_file': [unicode]}
|
||||||
|
@ -29,11 +29,11 @@ def process_media_initial(media_id):
|
|||||||
entry = database.MediaEntry.one(
|
entry = database.MediaEntry.one(
|
||||||
{'_id': mongokit.ObjectId(media_id)})
|
{'_id': mongokit.ObjectId(media_id)})
|
||||||
|
|
||||||
queued_filepath = entry['queue_files'].pop()
|
queued_filepath = entry['queued_media_file']
|
||||||
queued_file = queue_store.get_file(queued_filepath, 'r')
|
queued_file = queue_store.get_file(queued_filepath, 'r')
|
||||||
|
|
||||||
with queued_file:
|
with queued_file:
|
||||||
thumb = Image(queued_file)
|
thumb = Image.open(queued_file)
|
||||||
thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
|
thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
|
||||||
|
|
||||||
thumb_filepath = public_store.get_unique_filepath(
|
thumb_filepath = public_store.get_unique_filepath(
|
||||||
@ -44,7 +44,22 @@ def process_media_initial(media_id):
|
|||||||
with public_store.get_file(thumb_filepath, 'w') as thumb_file:
|
with public_store.get_file(thumb_filepath, 'w') as thumb_file:
|
||||||
thumb.save(thumb_file, "JPEG")
|
thumb.save(thumb_file, "JPEG")
|
||||||
|
|
||||||
queue_store.delete(queued_filepath)
|
# we have to re-read because unlike PIL, not everything reads
|
||||||
entry.setdefault('media_files', []).append(thumb_filepath)
|
# things in string representation :)
|
||||||
|
queued_file = queue_store.get_file(queued_filepath, 'rb')
|
||||||
|
|
||||||
|
with queued_file:
|
||||||
|
main_filepath = public_store.get_unique_filepath(
|
||||||
|
['media_entries',
|
||||||
|
unicode(entry['_id']),
|
||||||
|
queued_filepath[-1]])
|
||||||
|
|
||||||
|
with public_store.get_file(main_filepath, 'wb') as main_file:
|
||||||
|
main_file.write(queued_file.read())
|
||||||
|
|
||||||
|
queue_store.delete_file(queued_filepath)
|
||||||
|
media_files_dict = entry.setdefault('media_files', {})
|
||||||
|
media_files_dict['thumb'] = thumb_filepath
|
||||||
|
media_files_dict['main'] = main_filepath
|
||||||
entry.state = 'processed'
|
entry.state = 'processed'
|
||||||
entry.save()
|
entry.save(validate=False)
|
||||||
|
@ -22,6 +22,7 @@ from werkzeug.utils import secure_filename
|
|||||||
|
|
||||||
from mediagoblin.decorators import require_active_login
|
from mediagoblin.decorators import require_active_login
|
||||||
from mediagoblin.submit import forms as submit_forms
|
from mediagoblin.submit import forms as submit_forms
|
||||||
|
from mediagoblin.process_media import process_media_initial
|
||||||
|
|
||||||
|
|
||||||
@require_active_login
|
@require_active_login
|
||||||
@ -52,7 +53,6 @@ def submit_start(request):
|
|||||||
# Now store generate the queueing related filename
|
# Now store generate the queueing related filename
|
||||||
queue_filepath = request.app.queue_store.get_unique_filepath(
|
queue_filepath = request.app.queue_store.get_unique_filepath(
|
||||||
['media_entries',
|
['media_entries',
|
||||||
unicode(request.user['_id']),
|
|
||||||
unicode(entry['_id']),
|
unicode(entry['_id']),
|
||||||
secure_filename(request.POST['file'].filename)])
|
secure_filename(request.POST['file'].filename)])
|
||||||
|
|
||||||
@ -64,9 +64,12 @@ def submit_start(request):
|
|||||||
queue_file.write(request.POST['file'].file.read())
|
queue_file.write(request.POST['file'].file.read())
|
||||||
|
|
||||||
# Add queued filename to the entry
|
# Add queued filename to the entry
|
||||||
entry.setdefault('queue_files', []).append(queue_filepath)
|
entry['queued_media_file'] = queue_filepath
|
||||||
entry.save(validate=True)
|
entry.save(validate=True)
|
||||||
|
|
||||||
|
# queue it for processing
|
||||||
|
process_media_initial.delay(unicode(entry['_id']))
|
||||||
|
|
||||||
# redirect
|
# redirect
|
||||||
return exc.HTTPFound(
|
return exc.HTTPFound(
|
||||||
location=request.urlgen("mediagoblin.submit.success"))
|
location=request.urlgen("mediagoblin.submit.success"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user