@@ -244,22 +244,19 @@ if __name__ == "__main__":
244244Also see in [ examples] ( ./examples/example_locale.py )
245245
246246``` python
247- import os
248- from pyechonext.utils.exceptions import MethodNotAllow
247+ from pyechonext.apidoc_ui import APIDocUI, APIDocumentation
249248from pyechonext.app import ApplicationType, EchoNext
250- from pyechonext.views import View
251- from pyechonext.urls import URL , IndexView
252- from pyechonext.config import SettingsLoader, SettingsConfigType
253- from pyechonext.response import Response
254- from pyechonext.template_engine.jinja import render_template
249+ from pyechonext.config import SettingsConfigType, SettingsLoader
255250from pyechonext.middleware import middlewares
256- from pyechonext.docsgen import ProjDocumentation
257- from pyechonext.apidoc_ui import APIDocumentation, APIDocUI
251+ from pyechonext.mvc.controllers import PageController
258252from pyechonext.static import StaticFile
253+ from pyechonext.template_engine.jinja import render_template
254+ from pyechonext.urls import URL
255+ from pyechonext.utils.exceptions import MethodNotAllow
259256
260257
261- class UsersView (View ):
262- def get (self , request , response , ** kwargs ):
258+ class UsersView (PageController ):
259+ def get (self , request , response , * args , * *kwargs ):
263260 return render_template(
264261 request,
265262 " index.html" ,
@@ -268,35 +265,33 @@ class UsersView(View):
268265 friends = [" Bob" , " Anna" , " John" ],
269266 )
270267
271- def post (self , request , response , ** kwargs ):
268+ def post (self , request , response , * args , * *kwargs ):
272269 raise MethodNotAllow(f " Request { request.path} : method not allow " )
273270
274271
275- url_patterns = [URL(url = " /" , view = IndexView), URL( url = " / users" , view = UsersView)]
276- config_loader = SettingsLoader(SettingsConfigType.PYMODULE , ' el_config.py' )
272+ url_patterns = [URL(path = " /users" , controller = UsersView)]
273+ config_loader = SettingsLoader(SettingsConfigType.PYMODULE , " el_config.py" )
277274settings = config_loader.get_settings()
278- static_files = [StaticFile(settings, ' styles.css' )]
275+ static_files = [StaticFile(settings, " styles.css" )]
279276echonext = EchoNext(
280277 __name__ ,
281278 settings,
282279 middlewares,
283280 urls = url_patterns,
284281 application_type = ApplicationType.HTML ,
285- static_files = static_files
282+ static_files = static_files,
286283)
287284apidoc = APIDocumentation(echonext)
288- projdoc = ProjDocumentation(echonext)
289285
290286
291- @echonext.route_page (' /api-docs' )
287+ @echonext.route_page (" /api-docs" )
292288def api_docs (request , response ):
293289 ui = APIDocUI(apidoc.generate_spec())
294290 return ui.generate_html_page()
295291
296292
297293@echonext.route_page (" /book" )
298- @projdoc.documentate_route (' /book' , str , {}, [' GET' , ' POST' ])
299- class BooksResource (View ):
294+ class BooksResource (PageController ):
300295 """
301296 This class describes a books resource.
302297 """
@@ -315,7 +310,7 @@ class BooksResource(View):
315310 :returns: result
316311 :rtype: str
317312 """
318- return echonext.i18n_loader.get_string(' title %{name} ' , name = str (request.GET ))
313+ return echonext.i18n_loader.get_string(" title %{name} " , name = str (request.GET ))
319314
320315 def post (self , request , response , ** kwargs ):
321316 """
@@ -333,8 +328,6 @@ class BooksResource(View):
333328 """
334329 return echonext.l10n_loader.format_currency(1305.50 )
335330
336-
337- projdoc.generate_documentation()
338331```
339332
340333Create file ` static/styles.css ` :
@@ -382,96 +375,6 @@ Create file `locales/RU_RU.json`:
382375}
383376```
384377
385- ### App with flask-like and django-like routes
386- Django-line classes with get-post methods and routing pages. And with the built-in template engine!
387-
388- ``` python
389- import os
390- from pyechonext.app import ApplicationType, EchoNext
391- from pyechonext.views import View
392- from pyechonext.urls import URL , IndexView
393- from pyechonext.config import Settings
394- from pyechonext.template_engine.builtin import render_template # built-in (alpha)
395- # OR
396- from pyechonext.template_engine.jinja import render_template
397-
398-
399- class UsersView (View ):
400- def get (self , request , response , ** kwargs ):
401- return render_template(
402- request, " index.html" , user_name = " User" , friends = [" Bob" , " Anna" , " John" ]
403- )
404-
405- def post (self , request , response , ** kwargs ):
406- return Response(body = ' post users' )
407-
408-
409- url_patterns = [URL(url = " /" , view = IndexView), URL(url = " /users" , view = UsersView)]
410- settings = Settings(
411- BASE_DIR = os.path.dirname(os.path.abspath(__file__ )), TEMPLATES_DIR = " templates"
412- )
413- echonext = EchoNext(
414- __name__ , settings, urls = url_patterns, application_type = ApplicationType.HTML
415- )
416-
417-
418- @echonext.route_page (" /book" )
419- class BooksResource (View ):
420- def get (self , request , response , ** kwargs ):
421- return f " GET Params: { request.GET } "
422-
423- def post (self , request , response , ** kwargs ):
424- return f " POST Params: { request.POST } "
425- ```
426-
427- <p align =" right " >(<a href =" #readme-top " >back to top</a >)</p >
428-
429- ### Simple app with database
430- In this example we are using SQLSymphony ORM (our other project, a fast and simple ORM for python)
431-
432- ``` python
433- import os
434- from pyechonext.app import ApplicationType, EchoNext
435- from pyechonext.config import Settings
436- from sqlsymphony_orm.datatypes.fields import IntegerField, RealField, TextField
437- from sqlsymphony_orm.models.session_models import SessionModel
438- from sqlsymphony_orm.models.session_models import SQLiteSession
439-
440-
441- settings = Settings(
442- BASE_DIR = os.path.dirname(os.path.abspath(__file__ )), TEMPLATES_DIR = " templates"
443- )
444- echonext = EchoNext(__name__ , settings, application_type = ApplicationType.HTML )
445- session = SQLiteSession(" echonext.db" )
446-
447-
448- class User (SessionModel ):
449- __tablename__ = " Users"
450-
451- id = IntegerField(primary_key = True )
452- name = TextField(null = False )
453- cash = RealField(null = False , default = 0.0 )
454-
455- def __repr__ (self ):
456- return f " <User { self .pk} > "
457-
458-
459- @echonext.route_page (" /" )
460- def home (request , response ):
461- user = User(name = " John" , cash = 100.0 )
462- session.add(user)
463- session.commit()
464- return " Hello from the HOME page"
465-
466-
467- @echonext.route_page (" /users" )
468- def about (request , response ):
469- users = session.get_all_by_model(User)
470-
471- return f " Users: { [f ' { user.name} : { user.cash} $ ' for user in users]} "
472-
473- ```
474-
475378<p align =" right " >(<a href =" #readme-top " >back to top</a >)</p >
476379
477380## 🔧 Specifications
@@ -747,7 +650,8 @@ Our future goals for pyEchoNext include:
747650- 📚 Improve middlewares
748651- 🚀 Add async support
749652- ✅ Improve logging
750- - 🌍 Add auth
653+ - 🌍 Add authentication, JWT tokens
654+ - 💻 Depedency Injection
751655- 🌐 More stability and scalablity
752656
753657<p align =" right " >(<a href =" #readme-top " >back to top</a >)</p >
0 commit comments