Skip to content

Commit

Permalink
Stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrovRoman committed Mar 15, 2020
1 parent 67ca110 commit 4e04a81
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Flask_DJ/__project_info__.py
Original file line number Diff line number Diff line change
@@ -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__ = '[email protected]'
__license__ = 'MIT License'
Expand Down
21 changes: 12 additions & 9 deletions Flask_DJ/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
15 changes: 13 additions & 2 deletions Flask_DJ/project_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,25 @@ 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()


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}")
9 changes: 5 additions & 4 deletions Flask_DJ/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ This library was created to help everyone who wants to <br>
create a project with mvc structure.<br>

## Quick start
### Install:
pip install Flask-DJ
### Start project:

```shell script
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}',
Expand Down
6 changes: 3 additions & 3 deletions tests/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"])
Expand Down

0 comments on commit 4e04a81

Please sign in to comment.