This commit is contained in:
Joar Wandborg 2011-05-07 03:11:36 +02:00
commit 88bcdcd7d2
7 changed files with 104 additions and 29 deletions

22
destroy_environment.py Executable file
View File

@ -0,0 +1,22 @@
#!./bin/python
import pymongo
import sys, os
print "*** WARNING! ***"
print " Running this will destroy your mediagoblin database,"
print " remove all your media files in user_dev/, etc."
drop_it = raw_input(
'Are you SURE you want to destroy your environment? (if so, type "yes")> ')
if not drop_it == 'yes':
sys.exit(1)
conn = pymongo.Connection()
conn.drop_database('mediagoblin')
os.popen('rm -rf user_dev/media')
os.popen('rm -rf user_dev/beaker')
print "removed all your stuff! okay, now re-run ./bin/buildout"

View File

@ -95,6 +95,34 @@ changed. To do that, run::
need to do this when you've made code changes. need to do this when you've made code changes.
Running the server
==================
Run::
./bin/paster serve mediagoblin.ini --reload
Running celeryd
===============
You need to do this if you want your media to process and actually
show up. It's probably a good idea in development to have the web
server (above) running in one terminal and celeryd in another window.
Run::
CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_celery ./bin/celeryd
Running the test suite
======================
Run::
./bin/nosetests
Wiping your environment for a clean-slate Wiping your environment for a clean-slate
----------------------------------------- -----------------------------------------
@ -117,25 +145,9 @@ Delete the following directories:
.. YouCanHelp:: .. YouCanHelp::
If you're familiar with MongoDB and bash, we'd love to get a bash If you're familiar with MongoDB, we'd love to get a `script that
script that removes all the GNU MediaGoblin data from an existing removes all the GNU MediaGoblin data from an existing instance
MongoDB instance. Let us know! <http://bugs.foocorp.net/issues/296>`_. Let us know!
Running the server
==================
Run::
./bin/paster serve mediagoblin.ini --reload
Running the test suite
======================
Run::
./bin/nosetests
Quickstart for Django programmers Quickstart for Django programmers

View File

@ -74,11 +74,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]}

View File

@ -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 :)
entry.state = 'processed' 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'] = u'processed'
entry.save() entry.save()

View File

@ -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"))

View File

@ -36,4 +36,18 @@
</p> </p>
{% endif %} {% endif %}
{# temporarily, an "image gallery" that isn't one really ;) #}
<div>
<ul>
{% for entry in media_entries %}
<li>
<img src="{{ request.app.public_store.file_url(
entry['media_files']['thumb']) }}" />
</li>
{% endfor %}
</ul>
</div>
{% endblock %} {% endblock %}

View File

@ -22,11 +22,15 @@ import wtforms
from mediagoblin import models from mediagoblin import models
def root_view(request): def root_view(request):
media_entries = request.db.MediaEntry.find(
{u'state': u'processed'})
template = request.template_env.get_template( template = request.template_env.get_template(
'mediagoblin/root.html') 'mediagoblin/root.html')
return Response( return Response(
template.render( template.render(
{'request': request})) {'request': request,
'media_entries': media_entries}))
class ImageSubmitForm(wtforms.Form): class ImageSubmitForm(wtforms.Form):