Skip to content

Commit c9e342d

Browse files
authored
Merge pull request #4 from islam-kamel/1.1.4
1.1.4
2 parents 76a79db + a990891 commit c9e342d

File tree

12 files changed

+387
-222
lines changed

12 files changed

+387
-222
lines changed

.idea/misc.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/rest-start.iml

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,9 @@
1-
<h1 style="
2-
text-align: center;
3-
font-family: Serif;
4-
font-size: 6vh;
5-
">
6-
<span style="
7-
color: darkgoldenrod;
8-
letter-spacing: -6px;
9-
margin-right: -2.2%;"
10-
>Django</span>
11-
<span style="
12-
color: darkgoldenrod;
13-
letter-spacing: -3px;"
14-
>Start</span>
15-
Automate Script ✨
16-
</h1>
17-
18-
<div style="
19-
text-align: center;
20-
background: rgba(131,131,131,0.17);
21-
padding: 10px;
22-
border-radius: 5px;
23-
width: 650px;
24-
margin: 0 auto
25-
">
26-
Django automate start project and create app
27-
This script saves time for you to start a new Django project.
28-
It creates the project and creates the first app
29-
and then updates the project settings file and
30-
also updates the project urls file and then creates a views
31-
and configures the application urls file and
32-
also creates the index.html
33-
</div>
34-
<div style="text-align: center; margin-top: 10px">
35-
<img src="https://img.shields.io/github/stars/islam-kamel/django-start?style=social" alt="Repo Stars">
36-
<img src="https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20MacOs-green" alt="Platform Support">
37-
<img src="https://img.shields.io/badge/Latest%20Version-1.0.4--beta-green" alt="Latest Version">
38-
<img src="https://img.shields.io/github/downloads/islam-kamel/django-start/total", alt="Downloads Count">
39-
<img src="https://img.shields.io/github/release-date-pre/islam-kamel/django-start", alt="GitHub (Pre-)Release Date">
40-
</div>
1+
# Django-Start
2+
3+
---
4+
Prepare a new Django project quickly and automatically and more wonderful things that save you time By django start
5+
6+
![Repo Stars](https://img.shields.io/github/stars/islam-kamel/django-start?style=social) ![Platform Support](https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20MacOs-green) ![Latest Version](https://img.shields.io/badge/Latest%20Version-1.0.4--beta-green) ![Downloads Count](https://img.shields.io/github/downloads/islam-kamel/django-start/total) ![GitHub (Pre-)Release Date](https://img.shields.io/github/release-date-pre/islam-kamel/django-start)
417

428
---
439

@@ -50,32 +16,48 @@ pip install django-start-automate
5016
````shell
5117
django-start --help
5218

53-
usage: django-start [-h] [-v] [-n ] project_name app_name path
19+
Usage: django-start [OPTIONS] PROJECT_NAME APP_NAME
5420

55-
django-start 1.0.4 (Beta) automate start project and create app
21+
Prepare a new Django project quickly and automatically and, more wonderful
22+
things that save you time By django start
5623

57-
positional arguments:
58-
project_name Write a project name
59-
app_name Write an app name
60-
path select path
61-
62-
options:
63-
-h, --help show this help message and exit
64-
-v, --virtualenv Create virtualenv
65-
-n [], --name [] Set virtualenv name
24+
Options:
25+
-n, --name <LAMBDA> Custom Environment Name
26+
-v, --virtualenv TEXT Install Environment Is Deprecated
27+
--help Show this message and exit.
6628

6729
````
6830
**Success Install 🎊**
6931

70-
### Start First Project with virtualenv
32+
### Deprecated Options
33+
- `-v, --virtualenv` Option is deprecated
34+
35+
### Build First Django Project
7136
```shell
72-
django-start frist_project first_app -v -n my_virtualenv .
37+
django-start project_name app_name
7338
```
39+
40+
### Options
41+
- `-n or -name` to set custom environment name
42+
7443
---
75-
> You can run command without create virrualenv
44+
### django-version Command
45+
7646
```shell
77-
django-start frist_project first_app .
47+
Usage: django-version [OPTIONS]
48+
49+
Display current versio,
50+
check new update and update django-start
51+
52+
Options:
53+
--update / --check-update TEXT
54+
--help Show this message and exit.
7855
```
7956

80-
## Welcome to contribute ❤
81-
### [django-start](https://github.com/islam-kamel/django-start) 🧑‍💻
57+
### New
58+
- `django-version` Display django-start version
59+
- `django-version --check-update` Check New Update Available
60+
- `django-version --update` update django-start
61+
---
62+
### Welcome to contribute ❤
63+
### [PyPi](https://pypi.org/project/django-start-automate/) 🧑‍💻

djstartlib/app_manager.py

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import os
2-
import subprocess
3-
from hellper import warn_stdout
2+
from hellper import (
3+
warn_stdout,
4+
executable_python_command,
5+
build_views_urls,
6+
build_view_func,
7+
generate_html,
8+
)
9+
10+
import click
411

512

613
class AppManager:
@@ -9,7 +16,8 @@ def __init__(self, *args, **kwargs):
916
self.__workdir = os.getcwd() + rf"{os.sep}{self.app_name}"
1017
self.__views = self.workdir + rf"{os.sep}views.py"
1118
self.__urls = self.workdir + rf"{os.sep}urls.py"
12-
self.__templates = self.workdir + rf"{os.sep}templates"
19+
self.__templates = self.workdir + f"{os.sep}templates"
20+
self.python = os.environ.get("PYTHONPATH", None)
1321
self.__line_list = []
1422

1523
@property
@@ -35,7 +43,6 @@ def line_list(self):
3543
@line_list.setter
3644
def line_list(self, value):
3745
self.__line_list = value
38-
return self.line_list
3946

4047
def index(self, value):
4148
return self.line_list.index(value)
@@ -56,21 +63,21 @@ def create_app(self):
5663
if self.app_name not in os.listdir(
5764
f"{os.sep}".join(self.workdir.split(os.sep)[:-1])
5865
):
59-
print(f'✨ Create App "{self.app_name}"')
60-
subprocess.call(
61-
f"python manage.py startapp {self.app_name}", shell=True
62-
)
66+
click.secho(f"\U00002728 Create '{self.app_name}' App...", fg="blue")
67+
executable_python_command(f"manage.py startapp {self.app_name}")
6368
else:
6469
warn_stdout(f'"{self.app_name}" already exist!')
6570

6671
def update_view(self):
6772
self.read_file(self.views)
73+
6874
if "# Create your views here.\n" in self.line_list:
69-
print(f"🏗️ Create {self.app_name} View")
70-
self.replace_line(
71-
self.index("# Create your views here.\n"),
72-
"def home(request):\n\treturn render(request, 'index.html')\n",
75+
click.secho(f"\U0001F304 Create '{self.app_name}' View...", fg="blue")
76+
code_of_block = build_view_func().substitute(
77+
app_name=self.app_name, html_file="index.html"
7378
)
79+
self.replace_line(self.index("# Create your views here.\n"), code_of_block)
80+
7481
with open(self.views, "w") as f:
7582
f.write("".join(self.line_list))
7683
f.close()
@@ -79,32 +86,20 @@ def update_view(self):
7986

8087
def create_urls(self):
8188
with open(self.urls, "w") as f:
82-
print(f"🔗 Create {self.app_name} Urls")
83-
content = [
84-
"from django.urls import path\n",
85-
"from . import views\n" "\n",
86-
"urlpatterns = [\n",
87-
"\tpath('', views.home)\n" "]\n",
88-
]
89-
f.write("".join(content))
89+
click.secho(f"\U0001F517 Create {self.app_name} URLs...", fg="blue")
90+
block_of_code = build_views_urls().substitute(view_name="home")
91+
f.write(block_of_code)
9092
f.close()
9193

9294
def create_templates(self):
93-
print(f"🌐 Create {self.app_name} index.html")
95+
click.secho(f"\U0001F389 Generate '{self.app_name}' Index Page...", fg="blue")
96+
97+
if not os.path.exists(self.__templates):
98+
os.mkdir(self.__templates)
99+
100+
self.__templates += f"{os.sep}{self.app_name}"
94101
if not os.path.exists(self.__templates):
95102
os.mkdir(self.__templates)
96-
with open(rf"{self.__templates}{os.sep}index.html", "w") as f:
97-
content = [
98-
"<!DOCTYPE html>\n",
99-
'<html lang="en">\n',
100-
"<head>\n",
101-
'\t<meta charset="UTF-8">\n',
102-
"\t<title>Hello, Django-Start</title>\n",
103-
"</head>\n",
104-
"<body>\n",
105-
'\t<h1 style="text-align: center"> Hello, Django-Start</h1>\n',
106-
'\t<a href="https://github.com/islam-kamel/django-start"><h1 style="text-align: center">Project</h1></a>\n', # noqa E501
107-
"</body>\n</html>",
108-
]
109-
f.write("".join(content))
103+
with open(f"{self.__templates}{os.sep}index.html", "w") as f:
104+
f.write(generate_html())
110105
f.close()

djstartlib/djstart_interface.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
import sys
2-
import subprocess
31
from project_manager import ProjectManager
42

53

64
class DjangoStart(ProjectManager):
75
def __init__(self, *args, **kwargs):
86
super().__init__(*args, **kwargs)
97

10-
@staticmethod
11-
def upgrade_pip():
12-
print("📦 Upgrade Pip")
13-
subprocess.call(
14-
f"{sys.executable} -m pip install --upgrade pip",
15-
stdout=subprocess.DEVNULL,
16-
stderr=subprocess.STDOUT,
17-
shell=True,
18-
)
19-
208
def setup_project(self):
219
self.upgrade_pip()
2210
self.install_dep()

0 commit comments

Comments
 (0)