From a02b4bddef9093a07957e63483b0bef8a1ecdc71 Mon Sep 17 00:00:00 2001 From: Wannes Rombouts <wapiflapi@yahoo.fr> Date: Thu, 11 Jul 2013 09:21:32 +0200 Subject: [PATCH] Added automatic store creation on file upload ;) --- src/server.py | 13 ++++++++++--- src/webapp.py | 7 +++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/server.py b/src/server.py index 5a33a3b..05b438e 100755 --- a/src/server.py +++ b/src/server.py @@ -578,10 +578,17 @@ class files(object): raise webapp.NotImplemented() # Now we make sure the store exists. - with webapp.mightNotFound(message="Store {exception} does not exist " - "and automatic creation is not yet suported."): + try: ws.get_store_info(st_type, st_name) - # TODO: Create the store if it does not exist. + except KeyError: + # Create the store if it seems legit and it does not exist. + if st_type == "datastores" or st_type == "coveragestores": + with webapp.mightConflict("dataStore", workspace=ws_name): + ws.create_store(st_type, st_name, {}) + # Finaly check if its OK now. + with webapp.mightNotFound(message="Store {exception} does not exist " + "and it could not be created."): + ws.get_store_info(st_type, st_name) # Then we store the file. ext = web.ctx.env.get('CONTENT_TYPE', '').split("/")[-1] diff --git a/src/webapp.py b/src/webapp.py index 628d765..2fd1a79 100644 --- a/src/webapp.py +++ b/src/webapp.py @@ -435,6 +435,9 @@ class HTTPCompatible(object): def get_data(name=None, mandatory=[], authorized=[], forbidden=[]): data = web.data() + if not data: + raise web.badrequest('You must suply some data. (mandatory: %s, authorized: %s)' % (madatory, authorized)) + if not 'CONTENT_TYPE' in web.ctx.env: raise web.badrequest('You must specify a Content-Type.') @@ -449,8 +452,8 @@ def get_data(name=None, mandatory=[], authorized=[], forbidden=[]): if name: data = data.get(name, None) else: raise web.badrequest('Content-type \'%s\' is not allowed.' % ctype) - except ValueError: - raise web.badrequest('Could not decode input data.' % mandatory) + except (AttributeError, ValueError): + raise web.badrequest('Could not decode input data (%s).' % data) if name and data == None: raise web.badrequest('The object you are sending does not contain a \'%s\' entry.' % name) -- GitLab