From 808533fabdf08256ab62c90734d7d6a9f0f0245e Mon Sep 17 00:00:00 2001 From: Mart van Santen <mart@greenhost.nl> Date: Tue, 4 Oct 2022 18:51:04 +0800 Subject: [PATCH] Merged two functions, improved comments --- areas/apps/models.py | 2 +- cliapp/cliapp/cli.py | 38 ++++++++------------------------------ 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/areas/apps/models.py b/areas/apps/models.py index 851c8108..9cc24848 100644 --- a/areas/apps/models.py +++ b/areas/apps/models.py @@ -174,7 +174,7 @@ class App(db.Model): def to_dict(self): """ - represent this object as a json object. Return JSON object + represent this object as a dict, compatible for JSON output """ return {"id": self.id, diff --git a/cliapp/cliapp/cli.py b/cliapp/cliapp/cli.py index 09565f85..8b148405 100644 --- a/cliapp/cliapp/cli.py +++ b/cliapp/cliapp/cli.py @@ -50,12 +50,15 @@ app_cli = AppGroup("app") @app_cli.command("create") @click.argument("slug") @click.argument("name") -def create_app(slug, name): +@click.argument("external-url", required=False) +def create_app(slug, name, external_url = None): """Adds an app into the database :param slug: str short name of the app :param name: str name of the application + :param extenal-url: if set, it marks this as an external app and + configures the url """ - current_app.logger.info(f"Creating app definition: {name} ({slug})") + current_app.logger.info(f"Creating app definition: {name} ({slug}") obj = App() obj.name = name @@ -67,40 +70,15 @@ def create_app(slug, name): current_app.logger.info(f"App definition: {name} ({slug}) already exists in database") return - db.session.add(obj) - db.session.commit() - current_app.logger.info(f"App definition: {name} ({slug}) created") - -@app_cli.command("create-external") -@click.argument("slug") -@click.argument("name") -@click.argument("url") -def create_external_app(slug, name, url): - """Create an app for external access - :param slug: str short name of the app - :param name: str name of the application - :param url: str URL of application - """ - - obj = App() - obj.name = name - obj.slug = slug - obj.external = True - obj.url = url - - app_obj = App.query.filter_by(slug=slug).first() - - if app_obj: - current_app.logger.info(f"App definition: {name} ({slug}) already exists in database") - return + if (external_url): + obj.external = True + obj.url = external_url db.session.add(obj) db.session.commit() current_app.logger.info(f"App definition: {name} ({slug}) created") - - @app_cli.command("list") def list_app(): """List all apps found in the database""" -- GitLab