Skip to content

Commit

Permalink
refactor frontend structure, needs blueprint paths fixes for routes
Browse files Browse the repository at this point in the history
Signed-off-by: miigotu <miigotu@gmail.com>
  • Loading branch information
miigotu committed Sep 30, 2023
1 parent fb17381 commit 34d7545
Show file tree
Hide file tree
Showing 31 changed files with 223 additions and 219 deletions.
48 changes: 46 additions & 2 deletions frontend/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
"""
This is the global flask application under which all web interfaces for sickchill media types run on
"""

import threading

from flask import Flask

from .views.shows import shows_blueprint
from .config import config_blueprint
from .shows import shows_blueprint
from .movies import movies_blueprint

from .utils import logger


class FlaskServer(threading.Thread):
"""Flask application class to set up the sickchill flask webserver interface"""

def __init__(self, host, port):
super().__init__(name="FLASK")
self.host = host
Expand All @@ -14,11 +24,45 @@ def __init__(self, host, port):
self.alive = True

def run(self):
"""Run the flask server"""
self.app = Flask("SickFlask", template_folder="frontend/templates", static_folder="frontend/static", static_url_path="/static")
self.app.config.from_object("frontend.configurations.DevelopmentConfig")
self.app.config.from_object("frontend.app.DevelopmentConfig")

self.app.register_blueprint(config_blueprint)
self.app.register_blueprint(shows_blueprint)
self.app.register_blueprint(movies_blueprint)
routes = "\n\t\t".join(f"{rule}" for rule in self.app.url_map.iter_rules())
logger.debug(f"{self.app.name} Route:\n\t\t{routes}")

self.app.run(host=self.host, port=self.port, use_reloader=False)

def stop(self):
"""Stop the flask server"""
self.alive = False
del self.app


class BaseConfig:
"""
Base config class
"""

DEBUG = True
TESTING = False


class ProductionConfig(BaseConfig):
"""
Production specific config
"""

DEBUG = False


class DevelopmentConfig(BaseConfig):
"""
Development environment specific configuration
"""

DEBUG = True
TESTING = True
7 changes: 7 additions & 0 deletions frontend/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
This module implements the web interface for the sickchill configurationt
"""

from frontend.utils import build_blueprint

config_blueprint = build_blueprint(__file__, __name__)
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions frontend/config/views/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import render_template

from sickchill import logger, settings

from .. import config_blueprint


@config_blueprint.route("/")
def config():
logger.info("Loading config page")
return render_template("/config.html")
24 changes: 0 additions & 24 deletions frontend/configurations.py

This file was deleted.

7 changes: 7 additions & 0 deletions frontend/movies/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
This module implements the web interface for the sickchill movies media type
"""

from frontend.utils import build_blueprint

movies_blueprint = build_blueprint(__file__, __name__)
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
18 changes: 18 additions & 0 deletions frontend/movies/views/movies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from flask import render_template

from sickchill import logger, settings

# from sickchill.movies import movie

from .. import movies_blueprint


@movies_blueprint.route("/")
def movies():
logger.info("Loading movies page")
movies_blueprint.logger.info("Loaded movies page")

logger.debug(f"movies: {settings.showList}")
movies_blueprint.logger.debug(f"movies: {settings.movie_list}")

return render_template("movies.html", movies=settings.movie_list)
7 changes: 7 additions & 0 deletions frontend/shows/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
This module implements the web interface for the sickchill shows media type
"""

from frontend.utils import build_blueprint

shows_blueprint = build_blueprint(__file__, __name__)
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
Empty file.
14 changes: 10 additions & 4 deletions frontend/views/shows.py → frontend/shows/views/shows.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
from flask import Blueprint, render_template
from flask import render_template

from sickchill import logger, settings

# from sickchill.tv import TVEpisode, TVShow

shows_blueprint = Blueprint("shows", __name__)
from .. import shows_blueprint


@shows_blueprint.route("/")
@shows_blueprint.route("/shows")
def index():
def shows():
logger.info("Loading shows page")
logger.debug(f"Shows: {settings.showList}")
return render_template("shows.html", shows=settings.showList)


@shows_blueprint.route("/show/")
def show():
logger.info("Loading show details page")
logger.debug(f"Shows: {settings.showList}")
return render_template("show.html", show=None)
32 changes: 0 additions & 32 deletions frontend/static/show.js

This file was deleted.

9 changes: 0 additions & 9 deletions frontend/static/shows.css

This file was deleted.

79 changes: 0 additions & 79 deletions frontend/static/shows.js

This file was deleted.

24 changes: 24 additions & 0 deletions frontend/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from pathlib import Path
from flask import Blueprint
import logging

logging.basicConfig(format="{asctime} {levelname} :: {threadName} :: {message}", style="{")
logger = logging.getLogger(__package__)
logger.setLevel(logging.DEBUG)


def build_blueprint(module_location: Path, module_import: str) -> Blueprint:
"""Generate a blueprint for a frontend module"""

module_name = Path(module_location).parent.name
module_path = Path(module_location).parent.resolve()
frontend_path = module_path.parent.resolve()

templates_path = module_path.joinpath("templates")
static_path = frontend_path.joinpath("static").joinpath(module_name)

blueprint = Blueprint(module_name, module_import, static_folder=static_path, template_folder=templates_path)
logger.debug(
f"Paths for {blueprint.name}\n\ttemplates: {blueprint.template_folder}\n\tstatic: {blueprint.static_folder}\n\turl_prefix: {blueprint.url_prefix}"
)
return blueprint
Loading

0 comments on commit 34d7545

Please sign in to comment.