-
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.
Implement method tag for creating input hidden with PUT or DELETE val…
…ue (#48) * fix(__init__.py): import HTMLMiddleware and add method to inject hidden input fields for PUT and DELETE HTTP methods feat(html.py): add HTMLMiddleware class to generate hidden input fields for PUT and DELETE HTTP methods fix(edit.html): replace hidden input field with method('PUT') to inject hidden input field for PUT HTTP method fix(show.html): replace hidden input field with method('DELETE') to inject hidden input field for DELETE HTTP method fix(conftest.py): add message creation and commit to test_client and browser fixtures fix(messages_direct_request_test.py): remove unnecessary expected variable and assert message title directly fix(messages_direct_request_test.py): remove unnecessary message creation and commit, query message by title instead fix(messages_form_test.py): add test to check for presence of hidden input field for PUT HTTP method in edit page fix(messages_form_test.py): add test to check for presence of hidden input field for DELETE HTTP method in show page fix(messages_form_test.py): remove unnecessary message creation and commit, query message by title instead fix(messages_form_test.py): fix test name duplication and update message title in update test fix(messages_form_test.py): fix test name duplication and update message title in delete test * chore: bump version from 2.7.2 to 2.8.1 in __version__.py, pyproject.toml, and version_test.py The version number in the `__version__.py` file, `pyproject.toml` file, and `version_test.py` test case has been updated from 2.7.2 to 2.8.1. This change is made to reflect the new version of the `mvc-flask` package. * refactor(html.py): improve code readability and add docstrings for HTMLMiddleware class and its methods feat(html.py): add method to handle the generation of appropriate HTML based on a given string
- Loading branch information
Showing
10 changed files
with
109 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "2.7.2" | ||
__version__ = "2.8.1" |
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,62 @@ | ||
import markupsafe | ||
|
||
|
||
class HTMLMiddleware: | ||
""" | ||
A middleware class for handling HTML-related operations, specifically for creating hidden input fields | ||
with specific methods (like PUT and DELETE) that are not natively supported by HTML forms. | ||
Methods: | ||
- _input_html: Private method to generate HTML input element. | ||
- _put: Private method to generate a hidden input field for the PUT method. | ||
- _delete: Private method to generate a hidden input field for the DELETE method. | ||
- method: Public method to handle the generation of appropriate HTML based on a given string. | ||
""" | ||
|
||
def _input_html(self, input_method): | ||
""" | ||
Generates a hidden HTML input element. | ||
Args: | ||
- input_method (str): The HTTP method to be used (e.g., 'put', 'delete'). | ||
Returns: | ||
- str: An HTML string for a hidden input element with the specified method. | ||
""" | ||
return f"<input type='hidden' name='_method' value={input_method.upper()}>" | ||
|
||
def _put(self): | ||
""" | ||
Generates a hidden input field for the PUT method. | ||
Returns: | ||
- str: An HTML string for a hidden input element for the PUT method. | ||
""" | ||
return self._input_html("put") | ||
|
||
def _delete(self): | ||
""" | ||
Generates a hidden input field for the DELETE method. | ||
Returns: | ||
- str: An HTML string for a hidden input element for the DELETE method. | ||
""" | ||
return self._input_html("delete") | ||
|
||
def method(self, string): | ||
""" | ||
Determines the appropriate HTML string to return based on the given method string. | ||
Args: | ||
- string (str): The method string (e.g., 'put', 'delete'). | ||
Returns: | ||
- Markup: A markupsafe.Markup object containing the appropriate HTML string. | ||
This object is safe to render directly in templates. | ||
""" | ||
result = { | ||
"put": self._put(), | ||
"delete": self._delete(), | ||
}[string.lower()] | ||
|
||
return markupsafe.Markup(result) |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "mvc-flask" | ||
version = "2.7.2" | ||
version = "2.8.1" | ||
description = "turn standard Flask into mvc" | ||
authors = ["Marcus Pereira <[email protected]>"] | ||
|
||
|
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
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
def test_mvc_flask_currently_version(): | ||
__version__ == "2.7.2" | ||
__version__ == "2.8.1" |