From 279c87f0278b7d41cde8e2ec9d74f0275be548b7 Mon Sep 17 00:00:00 2001 From: Harouna Diallo Date: Sun, 27 Jun 2021 18:26:47 +0000 Subject: [PATCH 1/2] Fix static file folder with name --- MANIFEST.in | 1 - README.md | 2 ++ docs/features.md | 4 +++- docs/index.md | 2 ++ docs/tutorial/css-style.md | 1 + docs/tutorial/index.md | 1 + docs/tutorial/models.md | 3 +++ docs/tutorial/path-params.md | 1 + docs/tutorial/post-params.md | 1 + docs/tutorial/query-params.md | 1 + examples/awesome_app/app/__init__.py | 0 examples/awesome_app/app/models.py | 1 + examples/awesome_app/app/tests.py | 1 + examples/awesome_app/app/views.py | 10 ++++++++++ examples/awesome_app/mask.py | 19 ++++++++++++++++++ examples/awesome_app/settings.py | 1 + mkdocs.yml | 30 +++------------------------- nimba/commands/createapp.py | 2 +- nimba/core/welcom.py | 2 +- setup.cfg | 2 +- 20 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 docs/tutorial/css-style.md create mode 100644 docs/tutorial/models.md create mode 100644 docs/tutorial/path-params.md create mode 100644 docs/tutorial/post-params.md create mode 100644 docs/tutorial/query-params.md create mode 100644 examples/awesome_app/app/__init__.py create mode 100644 examples/awesome_app/app/models.py create mode 100644 examples/awesome_app/app/tests.py create mode 100644 examples/awesome_app/app/views.py create mode 100644 examples/awesome_app/mask.py create mode 100644 examples/awesome_app/settings.py diff --git a/MANIFEST.in b/MANIFEST.in index acbb5b6..1893d5b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,5 @@ include LICENSE include README.md -recursive-include docs * recursive-include nimba/templates * recursive-include nimba/staticfiles * recursive-include scripts * diff --git a/README.md b/README.md index db5b916..b2a0325 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ Quit the server with CONTROL-C. Open `http://127.0.0.1:8000` in your navigator ![Screenshot](https://github.com/hadpro24/nimba-framework/blob/main/result.png?raw=true) +continue directly with tutorial + ## Licence This project is licensed under the terms of Nimba solution compagny. diff --git a/docs/features.md b/docs/features.md index b226316..ec7aee1 100644 --- a/docs/features.md +++ b/docs/features.md @@ -1 +1,3 @@ -# Features \ No newline at end of file +# Features + +Comming soom... \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index e190ab5..0c5c49b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -65,6 +65,8 @@ Quit the server with CONTROL-C. Open `http://127.0.0.1:8000` in your navigator ![Screenshot](https://github.com/hadpro24/nimba-framework/blob/main/result.png?raw=true) +Continue directly with tutorial + ## Licence This project is licensed under the terms of Nimba solution compagny. diff --git a/docs/tutorial/css-style.md b/docs/tutorial/css-style.md new file mode 100644 index 0000000..50b210a --- /dev/null +++ b/docs/tutorial/css-style.md @@ -0,0 +1 @@ +# Partie 4 - CSS and JavaScript \ No newline at end of file diff --git a/docs/tutorial/index.md b/docs/tutorial/index.md index e69de29..4744e57 100644 --- a/docs/tutorial/index.md +++ b/docs/tutorial/index.md @@ -0,0 +1 @@ +# Parite 1 - Setup \ No newline at end of file diff --git a/docs/tutorial/models.md b/docs/tutorial/models.md new file mode 100644 index 0000000..eedbedc --- /dev/null +++ b/docs/tutorial/models.md @@ -0,0 +1,3 @@ +# Partie 6 - Models + +### comming... \ No newline at end of file diff --git a/docs/tutorial/path-params.md b/docs/tutorial/path-params.md new file mode 100644 index 0000000..0b8def4 --- /dev/null +++ b/docs/tutorial/path-params.md @@ -0,0 +1 @@ +# Partie 2 - Endpoint \ No newline at end of file diff --git a/docs/tutorial/post-params.md b/docs/tutorial/post-params.md new file mode 100644 index 0000000..898cb14 --- /dev/null +++ b/docs/tutorial/post-params.md @@ -0,0 +1 @@ +# Partie 5 - POST data \ No newline at end of file diff --git a/docs/tutorial/query-params.md b/docs/tutorial/query-params.md new file mode 100644 index 0000000..7e77bba --- /dev/null +++ b/docs/tutorial/query-params.md @@ -0,0 +1 @@ +# Partie 3 - Query parameters \ No newline at end of file diff --git a/examples/awesome_app/app/__init__.py b/examples/awesome_app/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/awesome_app/app/models.py b/examples/awesome_app/app/models.py new file mode 100644 index 0000000..6594757 --- /dev/null +++ b/examples/awesome_app/app/models.py @@ -0,0 +1 @@ +#write your models here \ No newline at end of file diff --git a/examples/awesome_app/app/tests.py b/examples/awesome_app/app/tests.py new file mode 100644 index 0000000..759c7bc --- /dev/null +++ b/examples/awesome_app/app/tests.py @@ -0,0 +1 @@ +#write your test here \ No newline at end of file diff --git a/examples/awesome_app/app/views.py b/examples/awesome_app/app/views.py new file mode 100644 index 0000000..719b0e3 --- /dev/null +++ b/examples/awesome_app/app/views.py @@ -0,0 +1,10 @@ +from nimba.http import router, render + +@router('/') +def home(request): + return "Nimba Framework installed succesfuly!" + + +@router('/about') +def about(request): + return "About form

Nimba

" \ No newline at end of file diff --git a/examples/awesome_app/mask.py b/examples/awesome_app/mask.py new file mode 100644 index 0000000..8902563 --- /dev/null +++ b/examples/awesome_app/mask.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import pathlib +import sys + +from app.views import * #import your view + +def main(): + try: + from nimba.commands import mont_nimba + except ImportError as e: + raise ImportError( + "Couldn't import nimba server. Active your environnement" + "or install nimba framework (ex: pip install nimba-framework)" + ) + mont_nimba(sys.argv, pathlib.Path(__file__).parent.absolute()) + +if __name__ == '__main__': + main() diff --git a/examples/awesome_app/settings.py b/examples/awesome_app/settings.py new file mode 100644 index 0000000..78cfcda --- /dev/null +++ b/examples/awesome_app/settings.py @@ -0,0 +1 @@ +#all settings application \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 5a653f9..74cc31e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -35,32 +35,11 @@ nav: - features.md - Tutorial - User Guide: - tutorial/index.md - - tutorial/first-steps.md - tutorial/path-params.md - tutorial/query-params.md - - tutorial/body.md - - Dependencies: - - tutorial/dependencies/index.md - - tutorial/dependencies/classes-as-dependencies.md - - tutorial/dependencies/sub-dependencies.md - - tutorial/dependencies/dependencies-in-path-operation-decorators.md - - tutorial/dependencies/global-dependencies.md - - tutorial/dependencies/dependencies-with-yield.md - - Security: - - tutorial/security/index.md - - tutorial/security/first-steps.md - - tutorial/security/get-current-user.md - - tutorial/security/simple-oauth2.md - - tutorial/security/oauth2-jwt.md - - tutorial/middleware.md - - tutorial/cors.md - - tutorial/sql-databases.md - - tutorial/bigger-applications.md - - tutorial/background-tasks.md - - tutorial/metadata.md - - tutorial/static-files.md - - tutorial/testing.md - - tutorial/debugging.md + - tutorial/css-style.md + - tutorial/post-params.md + - tutorial/models.md - Advanced User Guide: - advanced/index.md - advanced/path-operation-advanced-configuration.md @@ -83,9 +62,6 @@ nav: - deployment/index.md - deployment/versions.md - deployment/https.md - - deployment/deta.md - - deployment/docker.md - - deployment/manually.md - contributing.md - release-notes.md extra: diff --git a/nimba/commands/createapp.py b/nimba/commands/createapp.py index 8521dfd..45fb1e1 100644 --- a/nimba/commands/createapp.py +++ b/nimba/commands/createapp.py @@ -77,7 +77,7 @@ def handle(self): os.makedirs(path_application) os.makedirs(os.path.join(path_application, 'app')) os.makedirs(os.path.join(path_application, 'templates')) - os.makedirs(os.path.join(path_application, 'static')) + os.makedirs(os.path.join(path_application, 'staticfiles')) #init f = open(os.path.join(path_application, 'app', '__init__.py'), 'w+') f.close() diff --git a/nimba/core/welcom.py b/nimba/core/welcom.py index 9944601..de6e569 100644 --- a/nimba/core/welcom.py +++ b/nimba/core/welcom.py @@ -37,7 +37,7 @@


- Thanks Nimba Solution for Licence + Thanks Nimba Solution for Licence

diff --git a/setup.cfg b/setup.cfg index 0d3cf6b..715b122 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = nimba -version = 0.0.3 +version = 0.0.4 description = Nimba Framework is a modern, fast (coding), web framework with Python. long_description = file: README.rst keywords = python, python3, framework, nimba, nimba-solution, web From 9a2f6dc12d081776b1a2c323509055329064f37b Mon Sep 17 00:00:00 2001 From: Harouna Diallo Date: Mon, 28 Jun 2021 22:39:12 +0000 Subject: [PATCH 2/2] import view dynamicly and override home page --- examples/awesome_app/app/views.py | 8 ++-- examples/awesome_app/mask.py | 2 - .../templates/awesome_app/home.html | 42 +++++++++++++++++++ nimba/__main__.py | 4 +- nimba/apps.py | 3 +- nimba/commands/__init__.py | 21 +++++++--- nimba/commands/createapp.py | 15 ++++--- nimba/core/server.py | 8 ++-- nimba/core/welcom.py | 2 +- setup.cfg | 2 +- 10 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 examples/awesome_app/templates/awesome_app/home.html diff --git a/examples/awesome_app/app/views.py b/examples/awesome_app/app/views.py index 719b0e3..bf141c6 100644 --- a/examples/awesome_app/app/views.py +++ b/examples/awesome_app/app/views.py @@ -2,9 +2,9 @@ @router('/') def home(request): - return "Nimba Framework installed succesfuly!" + return render('awesome_app/home.html') -@router('/about') -def about(request): - return "About form

Nimba

" \ No newline at end of file +@router('/articles') +def home(request): + return 'testing

OK

' diff --git a/examples/awesome_app/mask.py b/examples/awesome_app/mask.py index 8902563..8809694 100644 --- a/examples/awesome_app/mask.py +++ b/examples/awesome_app/mask.py @@ -3,8 +3,6 @@ import pathlib import sys -from app.views import * #import your view - def main(): try: from nimba.commands import mont_nimba diff --git a/examples/awesome_app/templates/awesome_app/home.html b/examples/awesome_app/templates/awesome_app/home.html new file mode 100644 index 0000000..b8cb3df --- /dev/null +++ b/examples/awesome_app/templates/awesome_app/home.html @@ -0,0 +1,42 @@ + + + + + + Nimba Framework + + + + +
+

Nimba Framework successfully installed

+

Nimba Framework is a modern, fast (coding), web framework with python

+ +

+ Everything you need to know about Nimba Framework at https://docs.nimbasolution.com +

+
+

+ Thanks Nimba Solution for Licence +

+
+ + diff --git a/nimba/__main__.py b/nimba/__main__.py index 8b809fd..fbc0bfd 100644 --- a/nimba/__main__.py +++ b/nimba/__main__.py @@ -2,5 +2,5 @@ import pathlib if __name__ == '__main__': - from nimba.commands import mont_nimba - mont_nimba(sys.argv, pathlib.Path(__file__).parent.absolute()) + from nimba.apps import mont_nimba + mont_nimba() diff --git a/nimba/apps.py b/nimba/apps.py index 4b28a2e..5269988 100644 --- a/nimba/apps.py +++ b/nimba/apps.py @@ -4,7 +4,8 @@ def mont_nimba(): #create app + from nimba.core.welcom import home_default argv = sys.argv path_app = pathlib.Path(__file__).parent.absolute() utility = CommandUtility(path_app, argv) - utility.execute() \ No newline at end of file + utility.execute(home_default) \ No newline at end of file diff --git a/nimba/commands/__init__.py b/nimba/commands/__init__.py index 77e3b78..d0da10d 100644 --- a/nimba/commands/__init__.py +++ b/nimba/commands/__init__.py @@ -4,9 +4,11 @@ import pathlib import optparse import traceback +import importlib from nimba.commands.createapp import CreateApp from nimba.core.server import Application +from wsgiref.validate import validator class CommandUtility: """ @@ -21,7 +23,7 @@ def __init__(self, path_app, argv=None): except IndexError: self.subcommand = 'help' - def execute(self): + def execute(self, app): """ exectue command """ @@ -51,9 +53,13 @@ def execute(self): #runserver if self.subcommand == 'serve': if options.noreload: - Application(self.path_app).run('--noreload', options) + Application( + self.path_app, validator(app) + ).run('--noreload', options) else: - Application(self.path_app).run('--reload', options) + Application( + self.path_app, validator(app) + ).run('--reload', options) elif self.subcommand == 'create': app = CreateApp(options.app, self.prog_name) try: @@ -69,7 +75,10 @@ def execute(self): def mont_nimba(argv, path_app): #create app - # argv = sys.argv - # path_app = pathlib.Path(__file__).parent.absolute() + from nimba.core.welcom import home_default + view_module = importlib.import_module('app.views') + for attr in dir(view_module): + if hasattr(attr, '__call__'): + locals()[attr] = getattr(view_module, attr) utility = CommandUtility(path_app, argv) - utility.execute() + utility.execute(home_default) diff --git a/nimba/commands/createapp.py b/nimba/commands/createapp.py index 45fb1e1..931d71e 100644 --- a/nimba/commands/createapp.py +++ b/nimba/commands/createapp.py @@ -8,15 +8,13 @@ from nimba.commands.base import Loader from nimba.core.exceptions import AppNameIncorrect, CommandError - +from nimba.core.welcom import DEFAULT_DIRECTORY_INDEX_TEMPLATE manager_file = """#!/usr/bin/env python # -*- coding: utf-8 -*- import pathlib import sys -from app.views import * #import your view - def main(): try: from nimba.commands import mont_nimba @@ -30,11 +28,12 @@ def main(): if __name__ == '__main__': main() """ -import_view = """from nimba.http import router, render + +import_view = f"""from nimba.http import router, render @router('/') def home(request): - return "Nimba Framework installed succesfuly!" + return render('awesome_app/home.html') """ import_test = """#write your test here """ @@ -76,8 +75,12 @@ def handle(self): #create application os.makedirs(path_application) os.makedirs(os.path.join(path_application, 'app')) - os.makedirs(os.path.join(path_application, 'templates')) + os.makedirs(os.path.join(path_application, 'templates/awesome_app')) os.makedirs(os.path.join(path_application, 'staticfiles')) + #template + f = open(os.path.join(path_application, 'templates/awesome_app', 'home.html'), 'w+') + f.write(DEFAULT_DIRECTORY_INDEX_TEMPLATE) + f.close() #init f = open(os.path.join(path_application, 'app', '__init__.py'), 'w+') f.close() diff --git a/nimba/core/server.py b/nimba/core/server.py index 78f27e8..e68acec 100644 --- a/nimba/core/server.py +++ b/nimba/core/server.py @@ -10,7 +10,6 @@ import sys import os import importlib -from wsgiref.validate import validator from wsgiref import simple_server import optparse @@ -21,19 +20,18 @@ from watchdog.events import FileSystemEventHandler from watchdog.events import PatternMatchingEventHandler -from nimba.core.welcom import home_default - LISTEN_QUEUE = 128 can_open_by_fd = not platform.system() == "Windows" and hasattr(socket, "fromfd") class Application: - def __init__(self, path_file): + def __init__(self, path_file, app_view): self.name = '.'.join(str(path_file)[1:].split('/')) self.app_path = path_file self.httpd = None self.server_process = None self.port = 8000 self.host = '127.0.0.1' + self.app_view = app_view os.environ.setdefault('PROJECT_MASK_PATH', str(path_file)) @@ -111,7 +109,7 @@ def log_server_status(self, host, port): def _serve(self, host, port): host, port = host, int(port) srv = simple_server.make_server( - host, port, validator(home_default) + host, port, self.app_view ) print('Starting server in PID %s' % os.getpid()) self.log_server_status(host, port) diff --git a/nimba/core/welcom.py b/nimba/core/welcom.py index de6e569..0c919b4 100644 --- a/nimba/core/welcom.py +++ b/nimba/core/welcom.py @@ -1,4 +1,4 @@ -from nimba.http import router, render +from nimba.http import router DEFAULT_DIRECTORY_INDEX_TEMPLATE = """ diff --git a/setup.cfg b/setup.cfg index 715b122..d68d47b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = nimba -version = 0.0.4 +version = 0.0.5 description = Nimba Framework is a modern, fast (coding), web framework with Python. long_description = file: README.rst keywords = python, python3, framework, nimba, nimba-solution, web