diff --git a/src/aux.py b/src/aux.py index 18e6243..1da7b07 100644 --- a/src/aux.py +++ b/src/aux.py @@ -4,6 +4,7 @@ import os import re import web +import uuid import logging @@ -38,3 +39,7 @@ def is_get_request(): def get_input(): return web.input() if is_get_request() else web.data().decode('utf-8') + + +def generate_uuid(): + return str(uuid.uuid4()) diff --git a/src/models/work.py b/src/models/work.py index 3031a7f..7174171 100644 --- a/src/models/work.py +++ b/src/models/work.py @@ -1,5 +1,4 @@ import web -import uuid import psycopg2 from aux import logger_instance, debug_mode, strtolist from api import db @@ -176,28 +175,6 @@ def delete(self): q = '''DELETE FROM work WHERE work_id = $work_id''' db.query(q, dict(work_id=self.UUID)) - @staticmethod - def generate_uuid(): - return str(uuid.uuid4()) - - @staticmethod - def is_uuid(input_uuid): - try: - uuid.UUID(input_uuid) - return True - except ValueError: - return False - - @staticmethod - def uuid_exists(work_id): - try: - options = dict(work_id=work_id) - result = db.select('work', options, what="work_id", - where="work_id = $work_id") - return result.first()["work_id"] == work_id - except BaseException: - return False - @staticmethod def get_from_work_id(work_id): params = dict(uuid=work_id) diff --git a/src/worksctrl.py b/src/worksctrl.py index c4b8773..0605069 100644 --- a/src/worksctrl.py +++ b/src/worksctrl.py @@ -1,5 +1,6 @@ import web -from aux import logger_instance, debug_mode, sort_alphabetically, strtolist +from aux import (logger_instance, debug_mode, sort_alphabetically, strtolist, + generate_uuid) from validation import validate_sorting_or_fail, require_params_or_fail from api import json, json_response, api_response, check_token, build_parms from errors import Error, BADPARAMS, NORESULT @@ -81,7 +82,7 @@ def POST(self, name): UriScheme.find_or_fail(scheme) # instantiate a new work with the input data - uuid = Work.generate_uuid() + uuid = generate_uuid() work = Work(uuid, wtype, titles, uris) # check relatives and associate them with the work