Skip to content

Commit

Permalink
Merge pull request #4 from islam-kamel/1.1.4
Browse files Browse the repository at this point in the history
1.1.4
  • Loading branch information
islam-kamel authored Nov 14, 2022
2 parents 76a79db + a990891 commit c9e342d
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 222 deletions.
4 changes: 2 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions .idea/rest-start.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 39 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,9 @@
<h1 style="
text-align: center;
font-family: Serif;
font-size: 6vh;
">
<span style="
color: darkgoldenrod;
letter-spacing: -6px;
margin-right: -2.2%;"
>Django</span>
<span style="
color: darkgoldenrod;
letter-spacing: -3px;"
>Start</span>
Automate Script ✨
</h1>

<div style="
text-align: center;
background: rgba(131,131,131,0.17);
padding: 10px;
border-radius: 5px;
width: 650px;
margin: 0 auto
">
Django automate start project and create app
This script saves time for you to start a new Django project.
It creates the project and creates the first app
and then updates the project settings file and
also updates the project urls file and then creates a views
and configures the application urls file and
also creates the index.html
</div>
<div style="text-align: center; margin-top: 10px">
<img src="https://img.shields.io/github/stars/islam-kamel/django-start?style=social" alt="Repo Stars">
<img src="https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20MacOs-green" alt="Platform Support">
<img src="https://img.shields.io/badge/Latest%20Version-1.0.4--beta-green" alt="Latest Version">
<img src="https://img.shields.io/github/downloads/islam-kamel/django-start/total", alt="Downloads Count">
<img src="https://img.shields.io/github/release-date-pre/islam-kamel/django-start", alt="GitHub (Pre-)Release Date">
</div>
# Django-Start

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

![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)

---

Expand All @@ -50,32 +16,48 @@ pip install django-start-automate
````shell
django-start --help

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

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

positional arguments:
project_name Write a project name
app_name Write an app name
path select path

options:
-h, --help show this help message and exit
-v, --virtualenv Create virtualenv
-n [], --name [] Set virtualenv name
Options:
-n, --name <LAMBDA> Custom Environment Name
-v, --virtualenv TEXT Install Environment Is Deprecated
--help Show this message and exit.

````
**Success Install 🎊**

### Start First Project with virtualenv
### Deprecated Options
- `-v, --virtualenv` Option is deprecated

### Build First Django Project
```shell
django-start frist_project first_app -v -n my_virtualenv .
django-start project_name app_name
```

### Options
- `-n or -name` to set custom environment name

---
> You can run command without create virrualenv
### django-version Command

```shell
django-start frist_project first_app .
Usage: django-version [OPTIONS]

Display current versio,
check new update and update django-start

Options:
--update / --check-update TEXT
--help Show this message and exit.
```

## Welcome to contribute ❤
### [django-start](https://github.com/islam-kamel/django-start) 🧑‍💻
### New
- `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/) 🧑‍💻
65 changes: 30 additions & 35 deletions djstartlib/app_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import os
import subprocess
from hellper import warn_stdout
from hellper import (
warn_stdout,
executable_python_command,
build_views_urls,
build_view_func,
generate_html,
)

import click


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

@property
Expand All @@ -35,7 +43,6 @@ def line_list(self):
@line_list.setter
def line_list(self, value):
self.__line_list = value
return self.line_list

def index(self, value):
return self.line_list.index(value)
Expand All @@ -56,21 +63,21 @@ def create_app(self):
if self.app_name not in os.listdir(
f"{os.sep}".join(self.workdir.split(os.sep)[:-1])
):
print(f'✨ Create App "{self.app_name}"')
subprocess.call(
f"python manage.py startapp {self.app_name}", shell=True
)
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):
self.read_file(self.views)

if "# Create your views here.\n" in self.line_list:
print(f"🏗️ Create {self.app_name} View")
self.replace_line(
self.index("# Create your views here.\n"),
"def home(request):\n\treturn render(request, 'index.html')\n",
click.secho(f"\U0001F304 Create '{self.app_name}' View...", fg="blue")
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)

with open(self.views, "w") as f:
f.write("".join(self.line_list))
f.close()
Expand All @@ -79,32 +86,20 @@ def update_view(self):

def create_urls(self):
with open(self.urls, "w") as f:
print(f"🔗 Create {self.app_name} Urls")
content = [
"from django.urls import path\n",
"from . import views\n" "\n",
"urlpatterns = [\n",
"\tpath('', views.home)\n" "]\n",
]
f.write("".join(content))
click.secho(f"\U0001F517 Create {self.app_name} URLs...", fg="blue")
block_of_code = build_views_urls().substitute(view_name="home")
f.write(block_of_code)
f.close()

def create_templates(self):
print(f"🌐 Create {self.app_name} index.html")
click.secho(f"\U0001F389 Generate '{self.app_name}' Index Page...", fg="blue")

if not os.path.exists(self.__templates):
os.mkdir(self.__templates)

self.__templates += f"{os.sep}{self.app_name}"
if not os.path.exists(self.__templates):
os.mkdir(self.__templates)
with open(rf"{self.__templates}{os.sep}index.html", "w") as f:
content = [
"<!DOCTYPE html>\n",
'<html lang="en">\n',
"<head>\n",
'\t<meta charset="UTF-8">\n',
"\t<title>Hello, Django-Start</title>\n",
"</head>\n",
"<body>\n",
'\t<h1 style="text-align: center"> Hello, Django-Start</h1>\n',
'\t<a href="https://github.com/islam-kamel/django-start"><h1 style="text-align: center">Project</h1></a>\n', # noqa E501
"</body>\n</html>",
]
f.write("".join(content))
with open(f"{self.__templates}{os.sep}index.html", "w") as f:
f.write(generate_html())
f.close()
12 changes: 0 additions & 12 deletions djstartlib/djstart_interface.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
import sys
import subprocess
from project_manager import ProjectManager


class DjangoStart(ProjectManager):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def upgrade_pip():
print("📦 Upgrade Pip")
subprocess.call(
f"{sys.executable} -m pip install --upgrade pip",
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
shell=True,
)

def setup_project(self):
self.upgrade_pip()
self.install_dep()
Expand Down
Loading

0 comments on commit c9e342d

Please sign in to comment.