From db95e91cd38514cee197c50bda779df36ca9ec02 Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Wed, 14 Aug 2019 15:52:55 +0100 Subject: [PATCH 1/2] trim list of parameters --- src/models/identifier.py | 4 ++-- src/models/operations.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/models/identifier.py b/src/models/identifier.py index 0cade29..3b0b1e5 100644 --- a/src/models/identifier.py +++ b/src/models/identifier.py @@ -8,8 +8,8 @@ class Identifier(): - def __init__(self, uri_scheme, uri_value, canonical, score, work={}): - self.URI_parts = {'scheme': uri_scheme, 'value': uri_value} + def __init__(self, uri, canonical, score, work={}): + self.URI_parts = uri self.canonical = canonical self.score = score self.URI = self.full_uri() diff --git a/src/models/operations.py b/src/models/operations.py index 61dd4d6..8730901 100644 --- a/src/models/operations.py +++ b/src/models/operations.py @@ -14,10 +14,11 @@ def results_to_identifiers(results): def result_to_identifier(result): from .identifier import Identifier + uri = dict(scheme=result.get('uri_scheme'), value=result.get('uri_value')) work = dict(work_id=result.get('work_id'), work_type=result.get('work_type')) - return Identifier(result.get('uri_scheme'), result.get('uri_value'), - result.get('canonical'), result.get('score', 0), work) + return Identifier(uri, result.get('canonical'), result.get('score', 0), + work) def result_to_work(result): From 72c48082ef6dde87a7009e7104c281a98a8ee93c Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Wed, 14 Aug 2019 16:01:06 +0100 Subject: [PATCH 2/2] remove redundant methods --- src/aux.py | 5 +++++ src/models/work.py | 23 ----------------------- src/worksctrl.py | 5 +++-- 3 files changed, 8 insertions(+), 25 deletions(-) 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