Fixed validation in API post_entry.
authorJoar Wandborg <git@wandborg.com>
Mon, 17 Sep 2012 21:54:27 +0000 (23:54 +0200)
committerJoar Wandborg <git@wandborg.com>
Mon, 17 Sep 2012 21:54:27 +0000 (23:54 +0200)
Added state to API get_entry_serializable

mediagoblin/plugins/api/tools.py
mediagoblin/plugins/api/views.py

index e5aca29b08578aad3344e1bc78a514f75f40e5e0..c4630ba7b4f3eef42fc490641ef0e0f2d40aebdd 100644 (file)
@@ -95,6 +95,7 @@ def get_entry_serializable(entry, urlgen):
             'description': entry.description,
             'description_html': entry.description_html,
             'media_type': entry.media_type,
+            'state': entry.state,
             'permalink': entry.url_for_self(urlgen, qualified=True),
             'media_files': get_media_file_paths(entry.media_files, urlgen)}
 
index 2eb9e4147109480e73d21b6a3ed6ffabb712cd82..d537ec6e083416ac9d391dbc2cb2812bf76bc49f 100644 (file)
@@ -20,6 +20,7 @@ import uuid
 
 from os.path import splitext
 from webob import exc, Response
+from cgi import FieldStorage
 from werkzeug.utils import secure_filename
 from celery import registry
 
@@ -43,10 +44,18 @@ _log = logging.getLogger(__name__)
 @require_active_login
 def post_entry(request):
     _log.debug('Posting entry')
+
+    if request.method == 'OPTIONS':
+        return json_response({'status': 200})
+
     if request.method != 'POST':
+        _log.debug('Must POST against post_entry')
         return exc.HTTPBadRequest()
 
-    if not 'file' in request.POST or not hasattr(request.POST['file'], 'file'):
+    if not 'file' in request.POST \
+            or not isinstance(request.POST['file'], FieldStorage) \
+            or not request.POST['file'].file:
+        _log.debug('File field not found')
         return exc.HTTPBadRequest()
 
     media_file = request.POST['file']