Merged two functions, improved comments

This commit is contained in:
Mart van Santen 2022-10-04 18:51:04 +08:00
parent 4d94d389cd
commit 808533fabd
2 changed files with 9 additions and 31 deletions

View file

@ -174,7 +174,7 @@ class App(db.Model):
def to_dict(self): 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, return {"id": self.id,

View file

@ -50,12 +50,15 @@ app_cli = AppGroup("app")
@app_cli.command("create") @app_cli.command("create")
@click.argument("slug") @click.argument("slug")
@click.argument("name") @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 """Adds an app into the database
:param slug: str short name of the app :param slug: str short name of the app
:param name: str name of the application :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 = App()
obj.name = name 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") current_app.logger.info(f"App definition: {name} ({slug}) already exists in database")
return return
db.session.add(obj) if (external_url):
db.session.commit() obj.external = True
current_app.logger.info(f"App definition: {name} ({slug}) created") obj.url = external_url
@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
db.session.add(obj) db.session.add(obj)
db.session.commit() db.session.commit()
current_app.logger.info(f"App definition: {name} ({slug}) created") current_app.logger.info(f"App definition: {name} ({slug}) created")
@app_cli.command("list") @app_cli.command("list")
def list_app(): def list_app():
"""List all apps found in the database""" """List all apps found in the database"""