-
-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor frontend structure into flask blueprints #8569
Conversation
34d7545
to
278f377
Compare
Warning Rate Limit Exceeded@miigotu has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 11 minutes and 55 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per repository. WalkthroughThe changes in this update focus on enhancing the SickChill Flask web server interface. Several new modules and blueprints are added to handle different media types (shows, movies, and configuration). The Flask application is now organized using a Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Files selected for processing (9)
- frontend/app.py (2 hunks)
- frontend/config/init.py (1 hunks)
- frontend/config/views/config.py (1 hunks)
- frontend/movies/init.py (1 hunks)
- frontend/movies/views/movies.py (1 hunks)
- frontend/shows/init.py (1 hunks)
- frontend/shows/views/shows.py (1 hunks)
- frontend/utils.py (1 hunks)
- webpack.config.js (1 hunks)
Files skipped from review due to trivial changes (1)
- frontend/config/views/config.py
Additional comments (Suppressed): 19
webpack.config.js (6)
6-6: The
WorkboxWebpackPlugin
has been replaced withGenerateSW
from the same package. This change is in line with the PR summary and should improve the modularity of the webpack configuration.55-66: The configuration for the 'config' module has been added. The entry point, output path, and public path have been updated to match the new module structure. This change is in line with the PR summary and should improve the modularity of the webpack configuration.
67-79: The configuration for the 'shows' module has been updated. The entry points, output path, and public path have been updated to match the new module structure. This change is in line with the PR summary and should improve the modularity of the webpack configuration.
81-93: The configuration for the 'movies' module has been added. The entry point, output path, and public path have been updated to match the new module structure. This change is in line with the PR summary and should improve the modularity of the webpack configuration.
95-105: The exported function has been updated to return an array of configurations for each module. The
GenerateSW
plugin is added to each configuration if the mode is "production". This change is in line with the PR summary and should improve the modularity of the webpack configuration.98-102: The
GenerateSW
plugin is added to the plugins array of each configuration if the mode is "production". This is a change from the old hunk where theWorkboxWebpackPlugin.GenerateSW()
was added to the plugins array of the main configuration. This change should improve the modularity of the webpack configuration and ensure that a service worker is generated for each module in production mode.frontend/movies/__init__.py (1)
- 1-7: The
build_blueprint
utility function is used to create a Flask blueprint for the movies module. This is a good practice as it improves the modularity of the application. However, ensure that thebuild_blueprint
function is thoroughly tested and handles potential errors gracefully.frontend/shows/__init__.py (1)
- 1-7: The
build_blueprint
utility function is used to create a Flask blueprint for the shows module. This is a good practice as it enhances modularity and organization of the code. However, ensure that thebuild_blueprint
function is thoroughly tested and handles potential errors gracefully.frontend/utils.py (1)
- 10-24: The
build_blueprint
function seems to be well implemented. It creates a Flask blueprint for a frontend module, using the module's location and import name. The function also sets up the paths for the templates and static files for the module, and logs these paths for debugging purposes. However, it's important to ensure that themodule_location
andmodule_import
parameters are always valid and exist in the file system before they are used to create the blueprint. This can prevent potential runtime errors.frontend/app.py (5)
1-21: The new hunk introduces additional blueprints for different parts of the application:
config_blueprint
,shows_blueprint
, andmovies_blueprint
. This is a good practice as it modularizes the application, making it easier to manage and extend. However, ensure that these blueprints are correctly defined and that their routes do not conflict with each other.29-29: The configuration import path has been updated. Make sure that the new path is correct and that the
DevelopmentConfig
class exists at this location. If different configurations are used for different environments, consider dynamically selecting the configuration class based on the environment.- self.app.config.from_object("frontend.app.DevelopmentConfig") + config_class = f"frontend.app.{os.getenv('FLASK_ENV', 'Development')}Config" + self.app.config.from_object(config_class)
31-33: The application now registers multiple blueprints. Ensure that the order of registration does not cause any route conflicts. Flask uses the first matching route it finds, so if a blueprint with a catch-all route is registered first, it may overshadow routes in other blueprints.
34-35: Logging of registered routes is a good practice for traceability and debugging. However, be aware that this could potentially expose sensitive route information in the logs. Consider logging this information only in development mode.
45-68: The new hunk introduces different configuration classes for different environments. This is a good practice as it allows for environment-specific settings. However, ensure that these classes are used correctly throughout the application, and that sensitive information such as secret keys is not hard-coded but loaded from environment variables or secure storage.
frontend/config/__init__.py (1)
- 1-7: The
build_blueprint
utility function is used to create a Flask blueprint for the configuration module. This is a good practice as it improves the modularity of the application. However, ensure that thebuild_blueprint
function correctly handles the__file__
and__name__
parameters and that it is thoroughly tested, as any issues could impact the routing of the application.frontend/movies/views/movies.py (2)
15-16: The debug log message refers to
settings.showList
andsettings.movie_list
. Ensure thatsettings.showList
is not a typo and that bothsettings.showList
andsettings.movie_list
are defined and contain the expected data.18-18: Ensure that the "movies.html" template exists and is located in the correct directory. Also, verify that it can handle the
movies
variable being passed to it.frontend/shows/views/shows.py (2)
- 10-14: The route function
shows
is now only mapped to the root ("/") of theshows_blueprint
. In the old hunk, it was also mapped to "/shows". If this change is intentional, ensure that all references to the "/shows" route in the codebase have been updated to use the root ("/") instead. If this is not intentional, consider adding the "/shows" route back.- @shows_blueprint.route("/") + @shows_blueprint.route("/") + @shows_blueprint.route("/shows")
- 17-21: The new route function
show
is mapped to "/show/" and returns a template withshow=None
. If this is a placeholder for future implementation, consider adding a comment to indicate this. If not, ensure that the template "show.html" can handle a None value forshow
without causing errors.
4a7ac36
to
2e292cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 9
Files selected for processing (9)
- frontend/app.py (2 hunks)
- frontend/config/init.py (1 hunks)
- frontend/config/views/config.py (1 hunks)
- frontend/movies/init.py (1 hunks)
- frontend/movies/views/movies.py (1 hunks)
- frontend/shows/init.py (1 hunks)
- frontend/shows/views/shows.py (1 hunks)
- frontend/utils.py (1 hunks)
- webpack.config.js (1 hunks)
Files not summarized due to errors (1)
- frontend/config/views/config.py: Error: Server error
Additional comments (Suppressed): 9
frontend/config/__init__.py (1)
- 1-7: The
build_blueprint
utility function is used to generate a Flask blueprint for the configuration module. This is a good practice as it improves modularity and organization of the code. However, ensure that thebuild_blueprint
function is thoroughly tested and handles all edge cases, as it is a critical part of the application's routing mechanism.frontend/shows/__init__.py (1)
- 1-7: The new hunk introduces a blueprint for the shows media type using the
build_blueprint
utility function. This is a good practice as it improves the modularity and organization of the code. However, ensure that thebuild_blueprint
function is thoroughly tested and handles all edge cases, as it is now a critical part of the application structure.frontend/movies/__init__.py (1)
- 1-7: The
build_blueprint
utility function is used to generate a Flask blueprint for the movies module. This is a good practice as it enhances modularity and organization of the code. However, ensure that thebuild_blueprint
function correctly handles the__file__
and__name__
parameters and that the generated blueprint is correctly registered in the Flask application.frontend/app.py (2)
9-11: The new code imports blueprints for
config
,shows
, andmovies
. Ensure that these blueprints are correctly defined and that their routes do not conflict with each other.26-37: The
run
method has been updated to register the new blueprints and log the routes. Ensure that the logging does not expose sensitive information. Also, verify that theDevelopmentConfig
is the intended configuration for this context. If this code is meant for production, you should useProductionConfig
instead.frontend/shows/views/shows.py (2)
10-14: The route handler
shows()
is correctly refactored from the oldindex()
function. It logs the loading of the shows page and the list of shows, then renders the "shows.html" template with the list of shows. This change is consistent with the PR's goal of improving modularity and organization.17-21: The new route handler
show()
is introduced to load the show details page. However, it currently returns the "show.html" template withshow=None
. This might be a placeholder for future implementation. If so, consider adding a comment to indicate this. If not, ensure that the appropriate show details are passed to the template.frontend/config/views/config.py (1)
- 8-11: The route handler
config()
logs a message and renders a template. However, the template path seems to be absolute (/config.html
). In Flask, template paths are usually relative to the templates directory. If/config.html
is not in the root of the templates directory, this could cause an error. Please verify the location ofconfig.html
and adjust the path accordingly.- return render_template("/config.html") + return render_template("config.html")webpack.config.js (1)
- 55-93: The
context
,entry
,output
, andname
properties are set for each module configuration. This is a good practice as it allows for separate configurations for different modules, improving modularity and maintainability. However, ensure that the paths specified forcontext
,entry
, andoutput
are correct and that the files and directories they refer to exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (9)
- frontend/app.py (2 hunks)
- frontend/config/init.py (1 hunks)
- frontend/config/views/config.py (1 hunks)
- frontend/movies/init.py (1 hunks)
- frontend/movies/views/movies.py (1 hunks)
- frontend/shows/init.py (1 hunks)
- frontend/shows/views/shows.py (1 hunks)
- frontend/utils.py (1 hunks)
- webpack.config.js (1 hunks)
Files skipped from review due to trivial changes (6)
- frontend/config/init.py
- frontend/config/views/config.py
- frontend/movies/init.py
- frontend/movies/views/movies.py
- frontend/shows/init.py
- frontend/shows/views/shows.py
Additional comments: 8
frontend/app.py (2)
16-18: The class
FlaskServer
now extendsthreading.Thread
and is initialized with a host and port. This is a good practice as it allows the Flask server to run in its own thread, which can improve performance and responsiveness.27-37: The
run
method has been updated to register additional blueprints (config_blueprint
andmovies_blueprint
) and log all routes. This is a good practice as it improves modularity and provides useful debugging information. However, ensure that the logging of routes does not expose sensitive information in a production environment.webpack.config.js (4)
3-6: The commented out plugins
CopyPlugin
andHtmlWebpackPlugin
are still not used in the new configuration. If these plugins are not planned to be used in the future, consider removing these lines to improve code cleanliness.10-11: The
mode
is still set to either the value ofNODE_ENV
or 'development' ifNODE_ENV
is not set. This could lead to unexpected behavior ifNODE_ENV
is set to a value other than 'production' or 'development'. Consider explicitly checking ifNODE_ENV
is set to 'production' and defaulting to 'development' otherwise.81-93: The
Object.assign
method is still used to create copies of theconfig
object for different modules. This is a shallow copy, meaning that changes to nested objects or arrays in the originalconfig
object will affect the copies. If this is not the intended behavior, consider using a deep copy method instead.98-102: The
GenerateSW
plugin is still added to theplugins
array of each configuration if the mode is 'production'. However, this modifies the originalplugins
array in theconfig
object due to the shallow copy issue mentioned above. This means that theGenerateSW
plugin will be added multiple times if the mode is 'production'. Consider creating a newplugins
array for each configuration to avoid this issue.frontend/utils.py (2)
13-15: The previous suggestion to optimize the use of
Path(module_location).parent
has been implemented correctly. This change improves the performance by avoiding redundant operations.18-18: The previous suggestion to simplify the
joinpath
method by passing multiple arguments has been implemented correctly. This change improves the readability of the code.
Signed-off-by: miigotu <miigotu@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…sources Signed-off-by: miigotu <miigotu@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 8
Configuration used: CodeRabbit UI
Files selected for processing (15)
- frontend/app.py (1 hunks)
- frontend/config/init.py (1 hunks)
- frontend/config/static/config.js (1 hunks)
- frontend/config/views.py (1 hunks)
- frontend/movies/init.py (1 hunks)
- frontend/movies/static/movie.js (1 hunks)
- frontend/movies/static/movies.js (1 hunks)
- frontend/movies/views.py (1 hunks)
- frontend/shows/init.py (1 hunks)
- frontend/shows/static/show.js (1 hunks)
- frontend/shows/static/shows.js (3 hunks)
- frontend/shows/templates/shows.html (1 hunks)
- frontend/shows/views.py (1 hunks)
- frontend/utils.py (1 hunks)
- webpack.config.js (1 hunks)
Files skipped from review due to trivial changes (6)
- frontend/config/static/config.js
- frontend/movies/static/movie.js
- frontend/movies/static/movies.js
- frontend/shows/static/show.js
- frontend/shows/static/shows.js
- frontend/shows/views.py
Additional comments: 13
frontend/movies/__init__.py (1)
- 1-5: The module is well-structured and imports the blueprint from the views module correctly. Ensure that the
views
module contains theblueprint
object and it is correctly configured.frontend/shows/__init__.py (1)
- 1-5: The code looks good. It's a simple import of the
blueprint
object from theviews
module. Ensure that theviews
module correctly defines and exports theblueprint
object.frontend/utils.py (1)
- 1-5: The logging functionality is commented out. If this is intentional and you don't want to use logging in this file, consider removing these lines to keep the code clean. If you want to use logging, uncomment these lines.
- # import logging - # - # logging.basicConfig(format="{asctime} {levelname} :: {threadName} :: {message}", style="{") - # logger = logging.getLogger(__package__) - # logger.setLevel(logging.DEBUG) + import logging + + logging.basicConfig(format="{asctime} {levelname} :: {threadName} :: {message}", style="{") + logger = logging.getLogger(__package__) + logger.setLevel(logging.DEBUG)frontend/config/views.py (2)
1-5: The blueprint is correctly defined with a unique name, module, template folder, static folder, and URL prefix. Ensure that the template "config.html" exists in the specified template folder and that the static files are in the specified static folder.
8-11: The route is correctly defined and mapped to the function
config()
. The function logs a message and then renders the template. Ensure that the logger is correctly configured and that the log message will not flood the logs if the config page is frequently accessed.frontend/app.py (2)
1-85: The changes in this hunk are generally good, improving the structure and modularity of the Flask application. However, there are a few points that need to be addressed.
48-50: The blueprints are registered with the Flask app. Ensure that the blueprints are correctly defined in their respective modules and that the routes do not conflict.
frontend/movies/views.py (1)
- 15-16: The debug log message refers to
settings.showList
which seems to be a typo as the context variable for the template issettings.movie_list
. Please verify this.- logger.debug(f"movies: {settings.showList}") + logger.debug(f"movies: {settings.movie_list}")frontend/shows/templates/shows.html (2)
- 1-4: The title block is empty. Consider providing a default title or ensure that the title is being set in the parent template or view function.
- <title>{% block title %}{% endblock title %}</title> + <title>{% block title %}SickChill Shows{% endblock title %}</title>2, 20:
Ensure that the static filesshows.css
andshows.js
exist and are correctly served from the/static/
route.
- 6-17: The template assumes that
shows
is a list of objects with propertiesname
,startyear
,indexerid
, andimdb_id
. Ensure that the view function provides this data in the correct format.webpack.config.js (3)
1-6: The commented out plugins
CopyPlugin
andHtmlWebpackPlugin
are not used in the new configuration. If these plugins are not planned to be used in the future, consider removing these lines to improve code cleanliness.10-11: The
mode
is set to either the value ofNODE_ENV
or 'development' ifNODE_ENV
is not set. This could lead to unexpected behavior ifNODE_ENV
is set to a value other than 'production' or 'development'. Consider explicitly checking ifNODE_ENV
is set to 'production' and defaulting to 'development' otherwise.98-102: The
GenerateSW
plugin is added to theplugins
array of each configuration if the mode is 'production'. However, this modifies the originalplugins
array in theconfig
object due to the shallow copy issue mentioned above. This means that theGenerateSW
plugin will be added multiple times if the mode is 'production'. Consider creating a newplugins
array for each configuration to avoid this issue.
{% for show in shows %} | ||
<div class="col-3"> | ||
<p>{{ show.name }} ({{ show.startyear }})</p> | ||
<p>tvdb: {{ show.indexerid }}</p> | ||
<p>imdb: {{ show.imdb_id }}</p> | ||
</div> | ||
{% endfor %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template does not handle the case where shows
is empty. Consider adding a message to inform the user when there are no shows to display.
+ {% if shows %}
{% for show in shows %}
<div class="col-3">
<p>{{ show.name }} ({{ show.startyear }})</p>
<p>tvdb: {{ show.indexerid }}</p>
<p>imdb: {{ show.imdb_id }}</p>
</div>
{% endfor %}
+ {% else %}
+ <p>No shows to display.</p>
+ {% endif %}
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.
{% for show in shows %} | |
<div class="col-3"> | |
<p>{{ show.name }} ({{ show.startyear }})</p> | |
<p>tvdb: {{ show.indexerid }}</p> | |
<p>imdb: {{ show.imdb_id }}</p> | |
</div> | |
{% endfor %} | |
{% if shows %} | |
{% for show in shows %} | |
<div class="col-3"> | |
<p>{{ show.name }} ({{ show.startyear }})</p> | |
<p>tvdb: {{ show.indexerid }}</p> | |
<p>imdb: {{ show.imdb_id }}</p> | |
</div> | |
{% endfor %} | |
{% else %} | |
<p>No shows to display.</p> | |
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: miigotu <miigotu@gmail.com>
Signed-off-by: miigotu <miigotu@gmail.com>
Signed-off-by: miigotu <miigotu@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 6
Configuration used: CodeRabbit UI
Files selected for processing (3)
- frontend/app.py (1 hunks)
- package.json (1 hunks)
- webpack.config.js (1 hunks)
Files skipped from review due to trivial changes (1)
- package.json
Signed-off-by: miigotu <miigotu@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (2)
- frontend/movies/views.py (1 hunks)
- webpack.config.js (1 hunks)
Additional comments: 5
frontend/movies/views.py (1)
- 10-15: The function
movies
logs theshowList
fromsettings
but it passesmovie_list
to the template. Ensure that the correct data is being logged and passed to the template.webpack.config.js (4)
1-5: The import statements have been updated to use single quotes instead of double quotes. This is a minor stylistic change and does not affect the functionality of the code. However, it's important to maintain consistency in code style throughout the project. If the project uses ESLint or another linter, ensure that it's configured to enforce the chosen style.
5-5: The
GenerateSW
import from theworkbox-webpack-plugin
package has been added. This plugin will generate a service worker file using Workbox that will take care of caching and runtime responses. Make sure that theworkbox-webpack-plugin
package is installed in the project.54-94: The
config
object has been updated to include aname
property for each configuration, and thecontext
,entry
, andoutput
properties have been updated to point to the respective source directories, entry files, and output directories. This is a good practice as it makes the configuration more modular and easier to manage.96-107: A check for the
mode
property has been added to conditionally add theGenerateSW
plugin for production mode. This is a good practice as it ensures that the service worker is only generated for production builds, which can improve build times during development.- const outputs = [configurations, shows, movies]; + const outputs = [configurations, shows, movies].map(config => { + if (config.mode === 'production') { + const serviceWorker = new GenerateSW(); + config.plugins.push(serviceWorker); + } + return config; + });
Signed-off-by: miigotu <miigotu@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Structure is coming together, but I need to fix a bug with blueprints and paths and then make that work with webpack.
Holding the forms and models and stuff back for now.
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Documentation