aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdestroy_environment.py22
-rw-r--r--docs/hackinghowto.rst50
-rw-r--r--mediagoblin/models.py9
-rw-r--r--mediagoblin/process_media/__init__.py25
-rw-r--r--mediagoblin/submit/views.py7
-rw-r--r--mediagoblin/templates/mediagoblin/root.html14
-rw-r--r--mediagoblin/views.py6
7 files changed, 104 insertions, 29 deletions
diff --git a/destroy_environment.py b/destroy_environment.py
new file mode 100755
index 00000000..bbdeffe9
--- /dev/null
+++ b/destroy_environment.py
@@ -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"
diff --git a/docs/hackinghowto.rst b/docs/hackinghowto.rst
index fe2411bb..fdb53a25 100644
--- a/docs/hackinghowto.rst
+++ b/docs/hackinghowto.rst
@@ -95,6 +95,34 @@ changed. To do that, run::
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
-----------------------------------------
@@ -117,25 +145,9 @@ Delete the following directories:
.. YouCanHelp::
- If you're familiar with MongoDB and bash, we'd love to get a bash
- script that removes all the GNU MediaGoblin data from an existing
- MongoDB instance. Let us know!
-
-
-Running the server
-==================
-
-Run::
-
- ./bin/paster serve mediagoblin.ini --reload
-
-
-Running the test suite
-======================
-
-Run::
-
- ./bin/nosetests
+ If you're familiar with MongoDB, we'd love to get a `script that
+ removes all the GNU MediaGoblin data from an existing instance
+ <http://bugs.foocorp.net/issues/296>`_. Let us know!
Quickstart for Django programmers
diff --git a/mediagoblin/models.py b/mediagoblin/models.py
index e1198187..69b1f4f0 100644
--- a/mediagoblin/models.py
+++ b/mediagoblin/models.py
@@ -74,11 +74,16 @@ class MediaEntry(Document):
'tags': [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
# record form
- 'media_files': list,
'attachment_files': list,
- 'queue_files': list,
# This one should just be a single file record
'thumbnail_file': [unicode]}
diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py
index 0d02a13f..3c4d0ca1 100644
--- a/mediagoblin/process_media/__init__.py
+++ b/mediagoblin/process_media/__init__.py
@@ -29,11 +29,11 @@ def process_media_initial(media_id):
entry = database.MediaEntry.one(
{'_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')
with queued_file:
- thumb = Image(queued_file)
+ thumb = Image.open(queued_file)
thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
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:
thumb.save(thumb_file, "JPEG")
- queue_store.delete(queued_filepath)
- entry.setdefault('media_files', []).append(thumb_filepath)
- entry.state = 'processed'
+ # we have to re-read because unlike PIL, not everything reads
+ # 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'] = u'processed'
entry.save()
diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py
index 926c7011..9c4eb3a4 100644
--- a/mediagoblin/submit/views.py
+++ b/mediagoblin/submit/views.py
@@ -22,6 +22,7 @@ from werkzeug.utils import secure_filename
from mediagoblin.decorators import require_active_login
from mediagoblin.submit import forms as submit_forms
+from mediagoblin.process_media import process_media_initial
@require_active_login
@@ -52,7 +53,6 @@ def submit_start(request):
# Now store generate the queueing related filename
queue_filepath = request.app.queue_store.get_unique_filepath(
['media_entries',
- unicode(request.user['_id']),
unicode(entry['_id']),
secure_filename(request.POST['file'].filename)])
@@ -64,9 +64,12 @@ def submit_start(request):
queue_file.write(request.POST['file'].file.read())
# Add queued filename to the entry
- entry.setdefault('queue_files', []).append(queue_filepath)
+ entry['queued_media_file'] = queue_filepath
entry.save(validate=True)
+ # queue it for processing
+ process_media_initial.delay(unicode(entry['_id']))
+
# redirect
return exc.HTTPFound(
location=request.urlgen("mediagoblin.submit.success"))
diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html
index d6fffb8e..06a89f3f 100644
--- a/mediagoblin/templates/mediagoblin/root.html
+++ b/mediagoblin/templates/mediagoblin/root.html
@@ -36,4 +36,18 @@
</p>
{% 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 %}
diff --git a/mediagoblin/views.py b/mediagoblin/views.py
index 1081ce29..3728d4aa 100644
--- a/mediagoblin/views.py
+++ b/mediagoblin/views.py
@@ -22,11 +22,15 @@ import wtforms
from mediagoblin import models
def root_view(request):
+ media_entries = request.db.MediaEntry.find(
+ {u'state': u'processed'})
+
template = request.template_env.get_template(
'mediagoblin/root.html')
return Response(
template.render(
- {'request': request}))
+ {'request': request,
+ 'media_entries': media_entries}))
class ImageSubmitForm(wtforms.Form):