diff --git a/areas/apps/apps.py b/areas/apps/apps.py index 5c20c21..ec9bda7 100644 --- a/areas/apps/apps.py +++ b/areas/apps/apps.py @@ -9,6 +9,8 @@ from database import db from areas import api_v1 +from constants import APP_NOT_INSTALLED_STATUS + CONFIG_DATA = [ { "id": "values.yml", @@ -29,7 +31,6 @@ APPS_DATA = [ APP_DATA = {"id": 1, "name": "Nextcloud", "selected": True, "status": "ON for everyone", "config": CONFIG_DATA}, -APP_NOT_INSTALLED_STATUS = "Not installed" @api_v1.route('/apps', methods=['GET']) diff --git a/areas/apps/apps_service.py b/areas/apps/apps_service.py index ff3e5d5..635ac60 100644 --- a/areas/apps/apps_service.py +++ b/areas/apps/apps_service.py @@ -4,12 +4,12 @@ class AppsService: @staticmethod def get_all_apps(): apps = App.query.all() - return [{"id": app.id, "name": app.name, "slug": app.slug, "external": app.external, "url": app.get_url(), "status": app.get_status()} for app in apps] + return [app.to_json() for app in apps] @staticmethod def get_app(slug): app = App.query.filter_by(slug=slug).first() - return {"id": app.id, "name": app.name, "slug": app.slug, "external": app.external, "url": app.get_url(), "status": app.get_status()} + return app.to_json() @staticmethod diff --git a/areas/apps/models.py b/areas/apps/models.py index 4ac4dfd..c2d3617 100644 --- a/areas/apps/models.py +++ b/areas/apps/models.py @@ -8,10 +8,10 @@ from sqlalchemy.orm import relationship from database import db import helpers.kubernetes as k8s -# Circular import, need fixing -#from .apps import APP_NOT_INSTALLED_STATUS +from flask import current_app + +from constants import APP_NOT_INSTALLED_STATUS -APP_NOT_INSTALLED_STATUS = "Not installed" DEFAULT_APP_SUBDOMAINS = { "nextcloud": "files", "wordpress": "www", @@ -138,7 +138,6 @@ class App(db.Model): # Delete all roles first for role in self.roles: db.session.delete(role) - #role.delete() db.session.commit() db.session.delete(self) @@ -228,6 +227,18 @@ class App(db.Model): return condition["status"] == "True", condition["message"] return False, "Condition with type 'Ready' not found" + def to_json(self): + """ + represent this object as a json object. Return JSON object + """ + + return {"id": self.id, + "name": self.name, + "slug": self.slug, + "external": self.external, + "url": self.get_url(), + "status": self.get_status()} + class AppRole(db.Model): # pylint: disable=too-few-public-methods """