diff --git a/src/server.py b/src/server.py index 5a33a3bfb607459b67b41e92aacae3ed09f35d17..05b438e44fa541a0ce0ffcb523baa4e1c0d1f117 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 628d765ef1a389c22d01eebe96e77737b0292d32..2fd1a799458bbc906e35e1b69e8d4da759b2b687 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)