-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(pyproject.toml): add flask-sqlalchemy as a development dependen…
…cy to enable SQLAlchemy integration with Flask chore(plugins): remove unused plugins The plugins `__init__.py` and `form.py` were removed as they were no longer being used in the project. These plugins were responsible for registering and creating a form plugin for working with PUT and DELETE HTTP methods. However, they were not being utilized and were therefore removed to improve code cleanliness and reduce unnecessary dependencies. chore(tests): remove unused test data The file `storage.py` in the `tests/app/db` directory was removed as it contained unused test data. The data variable `[1, 2, 3]` was no longer needed for testing purposes and was therefore removed to improve code cleanliness and reduce unnecessary files. feat(app): add support for SQLite database using SQLAlchemy feat(messages_controller): add functionality to retrieve and display a message from the database feat(messages_controller): add functionality to update a message in the database feat(message.py): create Message model with id and title columns feat(messages/edit.html): update form method to POST and add hidden input for PUT method override feat(messages/index.html): create template to display message title feat(fixtures.py): create and drop database tables before and after each test fix(request_test.py): update test to use Message model and assert updated message title fix(__init__.py): remove unused imports and variables to improve code cleanliness and readability feat(__init__.py): add support for custom request class and spoofer middleware to handle spoofed HTTP methods feat(spoofing.py): add middleware for spoofing HTTP methods and custom request class to handle spoofed form data fix(format): change objects from single quotes to double quotes for consistency docs(README.md): update
- Loading branch information
Showing
15 changed files
with
300 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from flask import Request | ||
from werkzeug.formparser import parse_form_data | ||
|
||
|
||
class HTTPMethodOverrideMiddleware: | ||
def __init__(self, app, input_name="_method"): | ||
self.app = app | ||
self.input_name = input_name | ||
|
||
def __call__(self, environ, start_response): | ||
if environ["REQUEST_METHOD"].upper() == "POST": | ||
stream, form, files = parse_form_data(environ) | ||
|
||
method = form.get(self.input_name) | ||
if method: | ||
environ["wsgi._post_form"] = form | ||
environ["wsgi._post_files"] = files | ||
environ["REQUEST_METHOD"] = method | ||
return self.app(environ, start_response) | ||
|
||
|
||
class CustomRequest(Request): | ||
@property | ||
def form(self): | ||
if "wsgi._post_form" in self.environ: | ||
return self.environ["wsgi._post_form"] | ||
return super().form | ||
|
||
@property | ||
def files(self): | ||
if "wsgi._post_files" in self.environ: | ||
return self.environ["wsgi._post_files"] | ||
return super().files |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.