Skip to content

Commit

Permalink
Merge pull request #5 from islam-kamel/1.1.5
Browse files Browse the repository at this point in the history
1.1.5
  • Loading branch information
islam-kamel authored Nov 21, 2022
2 parents c9e342d + cfb2848 commit fd69651
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 311 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ pip install django-start-automate
````

````shell
django-start --help

Usage: django-start [OPTIONS] PROJECT_NAME APP_NAME
Usage: main.py [OPTIONS] PROJECT_NAME APP_NAME

Prepare a new Django project quickly and automatically and, more wonderful
things that save you time By django start

Options:
-n, --name <LAMBDA> Custom Environment Name
-v, --virtualenv TEXT Install Environment Is Deprecated
--help Show this message and exit.
-n, --name <LAMBDA> Custom Environment Name
-v, --virtualenv Install Environment Is Deprecated
-u, --url-path TEXT Set Custom URL Path for your App
--help Show this message and exit.

````
**Success Install 🎊**
Expand All @@ -39,6 +38,7 @@ django-start project_name app_name

### Options
- `-n or -name` to set custom environment name
- `-u or --url-path` to set custom view url for your app

---
### django-version Command
Expand All @@ -55,9 +55,11 @@ Options:
```

### New
- `-u or --url-path` set custom view url for your app
- `django-version` Display django-start version
- `django-version --check-update` Check New Update Available
- `django-version --update` update django-start

---
### Welcome to contribute ❤
### [PyPi](https://pypi.org/project/django-start-automate/) 🧑‍💻
105 changes: 0 additions & 105 deletions djstartlib/app_manager.py

This file was deleted.

20 changes: 0 additions & 20 deletions djstartlib/djstart_interface.py

This file was deleted.

23 changes: 14 additions & 9 deletions djstartlib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pathlib

import click
from djstart_interface import DjangoStart
from hellper import create_env

from models import DjangoStart


@click.command()
Expand All @@ -16,7 +16,8 @@
help="Custom Environment Name",
type=lambda p: pathlib.Path(p).absolute(),
)
@click.option("-v", "--virtualenv", help="Install Environment Is Deprecated")
@click.option("-v", "--virtualenv", is_flag=True, help="Install Environment Is Deprecated")
@click.option('-u', '--url-path', help='Set Custom URL Path for your App')
def main(**kwargs):
"""
Prepare a new Django project quickly and automatically and,
Expand All @@ -28,14 +29,18 @@ def main(**kwargs):
fg="white",
bg="red",
)
click.secho("Creating a virtual environment is a best practice!", fg="green")
click.secho("Creating a virtual environment is a best practice!",
fg="green")

create_env(kwargs["name"])
django_start = DjangoStart(
app_name=kwargs["app_name"], core_name=kwargs["project_name"]
app = DjangoStart(
kwargs['name'],
app=kwargs['app_name'],
project=kwargs['project_name']
)
django_start.setup_project()
django_start.setup_app()

app.setup_project()
app.setup_app(app_url=kwargs['url_path'] or '')


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions djstartlib/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
import sys
from models.app_manager import AppManager
from models.project_manager import ProjectManager
from models.djstart_interface import DjangoStart

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
97 changes: 97 additions & 0 deletions djstartlib/models/app_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os

import click

from models.utils import Environment
from models.utils.hellper import (build_view_func, build_views_urls,
executable_python_command, generate_html,
warn_stdout)


class AppManager(Environment):
def __init__(self, *args, **kwargs):
super().__init__(**kwargs)
self.__app_name = kwargs.get('app', None)
self.__workdir = os.path.join(
self.get_workdir(),
f'{self.get_app_name()}'
)
self.__views = os.path.join(self.workdir, 'views.py')
self.__urls = os.path.join(self.workdir, 'urls.py')
self.__templates = os.path.join(self.workdir, 'templates')

@property
def app_name(self) -> str:
return self.__app_name

@property
def workdir(self) -> str:
return self.__workdir

@property
def templates(self) -> str:
return self.__templates

@property
def views(self) -> str:
return self.__views

@property
def urls(self) -> str:
return self.__urls

def create_app(self) -> None:
if self.app_name not in os.listdir(self.get_workdir()):
click.secho(
f"\U00002728 Create '{self.app_name}' App...",
fg="blue"
)
executable_python_command(f"manage.py startapp {self.app_name}")
else:
warn_stdout(f'"{self.app_name}" already exist!')

def update_view(self) -> None:
click.secho(
f"\U0001F304 Create '{self.app_name}' Views...",
fg="blue"
)

self.read_file(self.views)
if "# Create your views here.\n" in self.line_list:
code_of_block = build_view_func().substitute(
app_name=self.app_name,
html_file="index.html"
)
self.replace_line(
self.index("# Create your views here.\n"),
code_of_block
)
self.write(self.views)

else:
warn_stdout('"home" View is Exists!')

def create_urls(self) -> None:
click.secho(
f"\U0001F517 Create {self.app_name} URLs...",
fg="blue"
)

block_of_code = build_views_urls().substitute(view_name="home")
self.write(self.urls, value=block_of_code)

def create_templates(self) -> None:
click.secho(
f"\U0001F389 Generate '{self.app_name}' Index Page...",
fg="blue"
)

index_path = f'{self.templates}{os.sep}{self.app_name}'
if not os.path.exists(self.templates):
os.mkdir(self.templates)

if not os.path.exists(index_path):
os.mkdir(index_path)
self.write(f'{index_path}{os.sep}index.html', value=generate_html())
else:
warn_stdout('Index.html is Already exists.')
23 changes: 23 additions & 0 deletions djstartlib/models/djstart_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from models import AppManager, ProjectManager
from models.utils.hellper import create_env


class DjangoStart:
def __init__(self, env_path, **kwargs):
self.project_cls = ProjectManager(**kwargs)
self.app_cls = AppManager(**kwargs)
create_env(env_path)

def setup_project(self):
self.project_cls.upgrade_pip()
self.project_cls.install_dep()
self.project_cls.create_project()
self.project_cls.requirements_extract()

def setup_app(self, app_url: str = ''):
self.app_cls.create_app()
self.project_cls.update_settings()
self.project_cls.update_urls(path=app_url)
self.app_cls.update_view()
self.app_cls.create_templates()
self.app_cls.create_urls()
Loading

0 comments on commit fd69651

Please sign in to comment.