add VersionView as view

This commit is contained in:
Cayo Puigdefabregas 2020-09-15 17:44:12 +02:00
parent f8e6020be6
commit 5cb0dad77d

View file

@ -1,10 +1,18 @@
import flask import flask
import json
import teal.marshmallow import teal.marshmallow
import ereuse_utils import ereuse_utils
from typing import Callable, Iterable, Tuple from typing import Callable, Iterable, Tuple
from flask import make_response, g from flask import make_response, g
from teal.resource import Resource from teal.resource import Resource, View
class VersionView(View):
def get(self, *args, **kwargs):
"""Get version."""
v = "{}".format(ereuse_utils.version('ereuse-devicehub'))
return json.dumps({'devicehub': v})
class VersionDef(Resource): class VersionDef(Resource):
@ -15,21 +23,19 @@ class VersionDef(Resource):
def __init__(self, app, def __init__(self, app,
import_name=__name__, import_name=__name__,
static_folder='static',
static_url_path=None, static_url_path=None,
template_folder='templates',
url_prefix=None, url_prefix=None,
subdomain=None, subdomain=None,
url_defaults=None, url_defaults=None,
root_path=None, root_path=None,
cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()):
super().__init__(app, import_name, static_folder, static_url_path, template_folder,
super().__init__(app, import_name, static_url_path,
url_prefix, subdomain, url_defaults, root_path, cli_commands) url_prefix, subdomain, url_defaults, root_path, cli_commands)
d = {'id': None}
d = {'devicehub': '0.1.0a'}
get = {'GET'} get = {'GET'}
self.add_url_rule('/', defaults=d, view_func=self.view, methods=get) version_view = VersionView.as_view('stockDocumentView', definition=self)
self.add_url_rule('/', defaults=d, view_func=version_view, methods=get)
def view(self):
#import pdb; pdb.set_trace()
v = "{}".format(ereuse_utils.version('ereuse-devicehub'))
return {'devicehub': v}