|
1 | 1 | import os |
2 | | -from pyechonext.utils.exceptions import MethodNotAllow |
| 2 | + |
| 3 | +from pyechonext.apidoc_ui import APIDocUI, APIDocumentation |
3 | 4 | from pyechonext.app import ApplicationType, EchoNext |
4 | | -from pyechonext.views import View |
5 | | -from pyechonext.urls import URL, IndexView |
6 | | -from pyechonext.config import SettingsLoader, SettingsConfigType |
7 | | -from pyechonext.response import Response |
8 | | -from pyechonext.template_engine.jinja import render_template |
| 5 | +from pyechonext.config import SettingsConfigType, SettingsLoader |
9 | 6 | from pyechonext.middleware import middlewares |
10 | | -from pyechonext.apidoc_ui import APIDocumentation, APIDocUI |
| 7 | +from pyechonext.response import Response |
11 | 8 | from pyechonext.static import StaticFile |
| 9 | +from pyechonext.template_engine.jinja import render_template |
| 10 | +from pyechonext.urls import URL, IndexView |
| 11 | +from pyechonext.utils.exceptions import MethodNotAllow |
| 12 | +from pyechonext.views import View |
12 | 13 |
|
13 | 14 |
|
14 | 15 | class UsersView(View): |
15 | | - def get(self, request, response, **kwargs): |
16 | | - return render_template( |
17 | | - request, |
18 | | - "index.html", |
19 | | - user_name="User", |
20 | | - session_id=request.session_id, |
21 | | - friends=["Bob", "Anna", "John"], |
22 | | - ) |
| 16 | + def get(self, request, response, **kwargs): |
| 17 | + return render_template( |
| 18 | + request, |
| 19 | + "index.html", |
| 20 | + user_name="User", |
| 21 | + session_id=request.session_id, |
| 22 | + friends=["Bob", "Anna", "John"], |
| 23 | + ) |
23 | 24 |
|
24 | | - def post(self, request, response, **kwargs): |
25 | | - raise MethodNotAllow(f"Request {request.path}: method not allow") |
| 25 | + def post(self, request, response, **kwargs): |
| 26 | + raise MethodNotAllow(f"Request {request.path}: method not allow") |
26 | 27 |
|
27 | 28 |
|
28 | 29 | url_patterns = [URL(url="/", view=IndexView), URL(url="/users", view=UsersView)] |
29 | | -config_loader = SettingsLoader(SettingsConfigType.PYMODULE, 'el_config.py') |
| 30 | +config_loader = SettingsLoader(SettingsConfigType.PYMODULE, "el_config.py") |
30 | 31 | settings = config_loader.get_settings() |
31 | | -static_files = [StaticFile(settings, 'styles.css')] |
| 32 | +static_files = [StaticFile(settings, "styles.css")] |
32 | 33 | echonext = EchoNext( |
33 | | - __name__, |
34 | | - settings, |
35 | | - middlewares, |
36 | | - urls=url_patterns, |
37 | | - application_type=ApplicationType.HTML, |
38 | | - static_files=static_files |
| 34 | + __name__, |
| 35 | + settings, |
| 36 | + middlewares, |
| 37 | + urls=url_patterns, |
| 38 | + application_type=ApplicationType.HTML, |
| 39 | + static_files=static_files, |
39 | 40 | ) |
40 | 41 | apidoc = APIDocumentation(echonext) |
41 | 42 |
|
42 | 43 |
|
43 | | -@echonext.route_page('/api-docs') |
| 44 | +@echonext.route_page("/api-docs") |
44 | 45 | def api_docs(request, response): |
45 | | - ui = APIDocUI(apidoc.generate_spec()) |
46 | | - return ui.generate_html_page() |
| 46 | + ui = APIDocUI(apidoc.generate_spec()) |
| 47 | + return ui.generate_html_page() |
47 | 48 |
|
48 | 49 |
|
49 | 50 | @echonext.route_page("/book") |
50 | 51 | class BooksResource(View): |
51 | | - """ |
52 | | - This class describes a books resource. |
53 | | - """ |
54 | | - |
55 | | - def get(self, request, response, **kwargs): |
56 | | - """ |
57 | | - get queries |
58 | | -
|
59 | | - :param request: The request |
60 | | - :type request: Request |
61 | | - :param response: The response |
62 | | - :type response: Response |
63 | | - :param kwargs: The keywords arguments |
64 | | - :type kwargs: dictionary |
65 | | -
|
66 | | - :returns: result |
67 | | - :rtype: str |
68 | | - """ |
69 | | - return echonext.i18n_loader.get_string('title %{name}', name=str(request.GET)) |
70 | | - |
71 | | - def post(self, request, response, **kwargs): |
72 | | - """ |
73 | | - post queries |
74 | | -
|
75 | | - :param request: The request |
76 | | - :type request: Request |
77 | | - :param response: The response |
78 | | - :type response: Response |
79 | | - :param kwargs: The keywords arguments |
80 | | - :type kwargs: dictionary |
81 | | -
|
82 | | - :returns: result |
83 | | - :rtype: str |
84 | | - """ |
85 | | - return echonext.l10n_loader.format_currency(1305.50) |
| 52 | + """ |
| 53 | + This class describes a books resource. |
| 54 | + """ |
| 55 | + |
| 56 | + def get(self, request, response, **kwargs): |
| 57 | + """ |
| 58 | + get queries |
| 59 | +
|
| 60 | + :param request: The request |
| 61 | + :type request: Request |
| 62 | + :param response: The response |
| 63 | + :type response: Response |
| 64 | + :param kwargs: The keywords arguments |
| 65 | + :type kwargs: dictionary |
| 66 | +
|
| 67 | + :returns: result |
| 68 | + :rtype: str |
| 69 | + """ |
| 70 | + return echonext.i18n_loader.get_string("title %{name}", name=str(request.GET)) |
| 71 | + |
| 72 | + def post(self, request, response, **kwargs): |
| 73 | + """ |
| 74 | + post queries |
| 75 | +
|
| 76 | + :param request: The request |
| 77 | + :type request: Request |
| 78 | + :param response: The response |
| 79 | + :type response: Response |
| 80 | + :param kwargs: The keywords arguments |
| 81 | + :type kwargs: dictionary |
| 82 | +
|
| 83 | + :returns: result |
| 84 | + :rtype: str |
| 85 | + """ |
| 86 | + return echonext.l10n_loader.format_currency(1305.50) |
0 commit comments