From 4e04a81ff022fb6d1852a4d3b2c830c503caf40e Mon Sep 17 00:00:00 2001 From: AlexandrovRoman <56388249+AlexandrovRoman@users.noreply.github.com> Date: Sun, 15 Mar 2020 14:34:57 +0400 Subject: [PATCH] Stable version --- Flask_DJ/__project_info__.py | 2 +- Flask_DJ/manage.py | 21 ++++++++++++--------- Flask_DJ/project_creator.py | 15 +++++++++++++-- Flask_DJ/templates.py | 9 +++++---- README.md | 2 -- docs/conf.py | 2 +- setup.py | 2 +- tests/manage.py | 6 +++--- 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Flask_DJ/__project_info__.py b/Flask_DJ/__project_info__.py index dcb0576..9313941 100644 --- a/Flask_DJ/__project_info__.py +++ b/Flask_DJ/__project_info__.py @@ -1,7 +1,7 @@ __title__ = 'Flask-DJ' __description__ = 'Django (mvc) structure for your Flask project.' __url__ = 'https://github.com/AlexandrovRoman/Flask-DJ' -__version__ = '0.1.7' +__version__ = '1.0.0' __author__ = 'Alexandrov Roman' __author_email__ = 'flask-dj.feedback@yandex.com' __license__ = 'MIT License' diff --git a/Flask_DJ/manage.py b/Flask_DJ/manage.py index c4c3e44..334e26b 100644 --- a/Flask_DJ/manage.py +++ b/Flask_DJ/manage.py @@ -15,39 +15,42 @@ ] -def init_manage(app): +def init_manage_and_app(app): global manager, app_ app_ = app manager = Manager(app) -def init_db(models=[]): +def init_db_commands(models=[]): manager.add_command('db', MigrateCommand) + for file in models: import_module(file) def runserver(host, port): - if app_.debug: - app_.run(host=host, port=port) - else: - serve(app_, host=host, port=port) + app_.run(host=host, port=port) if app_.debug else serve(app_, host=host, port=port) -def startapp(need_templates, need_static, name): +def startapp(templates, static, name): """Create folder containing forms.py, models.py, urls.py, views.py""" valid_folder_name(name) + create_folder(name) create_app_files(name) - if need_templates: + + if templates: create_app_templates(name) - if need_static: + if static: create_app_static(name) + print(f'app {name} created') def create_app_files(app_name): + """Create .py files for your app""" project_name = get_project_name() + create_file(app_name, 'views', views_file) create_file(app_name, 'models', models_file.format(project_name=project_name)) create_file(app_name, 'urls', urls_file.format(functions="relative_path")) diff --git a/Flask_DJ/project_creator.py b/Flask_DJ/project_creator.py index 9de0d83..d291cd0 100644 --- a/Flask_DJ/project_creator.py +++ b/Flask_DJ/project_creator.py @@ -89,6 +89,7 @@ def console_creation(): parser.add_argument("--templates", "-t", action="store_true", default=False) parser.add_argument("--static", "-st", action="store_true", default=False) args = parser.parse_args() + ProjectConstructor(args.project_name, need_templates=args.templates, need_static=args.static).startproject() @@ -96,7 +97,17 @@ def command(): commands = { 'startproject': console_creation } + try: commands[argv[1]]() - except (KeyError, IndexError): - raise ValueError("Invalid command") + except KeyError: + print("Input correct command") + print_commands(commands) + except IndexError: + print("Input command") + print_commands(commands) + + +def print_commands(commands): + for key in commands: + print(f"\t\t{key}") diff --git a/Flask_DJ/templates.py b/Flask_DJ/templates.py index a503e69..8a92200 100644 --- a/Flask_DJ/templates.py +++ b/Flask_DJ/templates.py @@ -55,11 +55,12 @@ class DevelopConfig(BaseConfig): from Flask_DJ.app_init import add_urls from {project_name} import app, config -manage.init_manage(app) -manage.init_db(config.models) +manage.init_manage_and_app(app) +manage.init_db_commands(config.models) -manager.option("--templates", "-t", action="store_true")( - manager.option("--static", "-st", action="store_true")(manager.option("name")(manage.manager.startapp))) +manage.manager.option("--templates", "-t", action="store_true")( + manage.manager.option("--static", "-st", action="store_true")( + manage.manager.option("name")(manage.startapp))) @manage.manager.command diff --git a/README.md b/README.md index f9487fe..549b11c 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,6 @@ This library was created to help everyone who wants to
create a project with mvc structure.
## Quick start - ### Install: - pip install Flask-DJ ### Start project: ```shell script diff --git a/docs/conf.py b/docs/conf.py index 3c5c6f9..9f6ec94 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,7 +23,7 @@ author = 'Alexandrov Roman' # The full version, including alpha/beta/rc tags -release = '0.1.6' +release = '1.0.0' # -- General configuration --------------------------------------------------- diff --git a/setup.py b/setup.py index 50cf8ca..e52fd0e 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ author=__author__, # Optional author_email=__author_email__, # Optional classifiers=[ # Optional - 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Topic :: Software Development :: Build Tools', f'License :: OSI Approved :: {__license__}', diff --git a/tests/manage.py b/tests/manage.py index 4dcae01..f2f4a77 100644 --- a/tests/manage.py +++ b/tests/manage.py @@ -4,13 +4,13 @@ from Flask_DJ.manage import startapp -class TestManage(ProjectCreate): +class TestManageStartapp(ProjectCreate): def setup(self, need_templates=False, need_static=False): super().setup(need_templates, need_static) app_name = 'index' self.app_path = join(self.project_path, app_name) chdir(self.project_path) - startapp(app_name) + startapp(True, True, app_name) def test_startapp_folder(self): assert exists(self.app_path) @@ -19,7 +19,7 @@ def test_startapp_models(self): self._file_test(self.app_path, 'models', [f"from {self.project_name} import db", "# Create your models"]) def test_startapp_urls(self): - self._file_test(self.app_path, 'urls', ["from utils.urls import get_relative_path, add_absolute_path"]) + self._file_test(self.app_path, 'urls', ["from utils.urls import relative_path"]) def test_startapp_forms(self): self._file_test(self.app_path, 'forms', ["from flask_wtf import FlaskForm", "import wtforms"])