componentsDjangoType 0.0.4__tar.gz → 1.0.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {componentsdjangotype-0.0.4/componentsDjangoType.egg-info → componentsDjangoType-1.0.0}/PKG-INFO +2 -3
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/README.md +1 -1
- componentsDjangoType-1.0.0/componentsDjangoType/management/commands/createcomponentApp.py +248 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0/componentsDjangoType.egg-info}/PKG-INFO +2 -3
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType.egg-info/SOURCES.txt +2 -1
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/setup.py +1 -1
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/LICENSE +0 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/MANIFEST.in +0 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType/__init__.py +0 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType/management/__init__.py +0 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType/management/commands/__init__.py +0 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType/management/commands/createcomponent.py +0 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType.egg-info/dependency_links.txt +0 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType.egg-info/requires.txt +0 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType.egg-info/top_level.txt +0 -0
- {componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/setup.cfg +0 -0
{componentsdjangotype-0.0.4/componentsDjangoType.egg-info → componentsDjangoType-1.0.0}/PKG-INFO
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: componentsDjangoType
|
3
|
-
Version: 0.0
|
3
|
+
Version: 1.0.0
|
4
4
|
Summary: A Django app for creating HTML components
|
5
5
|
Home-page: https://github.com/jose-CR/componentsDjangoType
|
6
6
|
Author: Alejandro
|
@@ -17,7 +17,6 @@ Classifier: Programming Language :: Python :: 3.7
|
|
17
17
|
Classifier: Framework :: Django :: 3.2
|
18
18
|
Description-Content-Type: text/markdown
|
19
19
|
License-File: LICENSE
|
20
|
-
Requires-Dist: Django>=3.2
|
21
20
|
|
22
21
|
# componentsDjangotype
|
23
22
|
|
@@ -39,7 +38,7 @@ Este comando de Django te permite crear un componente HTML dentro del directorio
|
|
39
38
|
|
40
39
|
## Uso
|
41
40
|
|
42
|
-
1. Ejecuta el comando en tu terminal: `python manage.py
|
41
|
+
1. Ejecuta el comando en tu terminal: `python manage.py createcomponent <nombre_de_aplicación> <carpeta/archivo> --type=<template|static>`
|
43
42
|
2. Reemplaza `<nombre_de_aplicación>` con el nombre de la aplicación donde deseas crear el componente.
|
44
43
|
3. Reemplaza `<ruta_del_archivo>` con la ruta donde deseas crear el componente dentro del directorio `templates` o `static` de la aplicación.
|
45
44
|
4. La bandera `--type` especifica si deseas crear un componente en el directorio `templates` o `static`. Por defecto, se establece en `template`.
|
@@ -18,7 +18,7 @@ Este comando de Django te permite crear un componente HTML dentro del directorio
|
|
18
18
|
|
19
19
|
## Uso
|
20
20
|
|
21
|
-
1. Ejecuta el comando en tu terminal: `python manage.py
|
21
|
+
1. Ejecuta el comando en tu terminal: `python manage.py createcomponent <nombre_de_aplicación> <carpeta/archivo> --type=<template|static>`
|
22
22
|
2. Reemplaza `<nombre_de_aplicación>` con el nombre de la aplicación donde deseas crear el componente.
|
23
23
|
3. Reemplaza `<ruta_del_archivo>` con la ruta donde deseas crear el componente dentro del directorio `templates` o `static` de la aplicación.
|
24
24
|
4. La bandera `--type` especifica si deseas crear un componente en el directorio `templates` o `static`. Por defecto, se establece en `template`.
|
@@ -0,0 +1,248 @@
|
|
1
|
+
# componentsDjangoType/management/commands/createcomponentApp.py
|
2
|
+
import os
|
3
|
+
from django.core.management.base import BaseCommand
|
4
|
+
from django.core.management import call_command
|
5
|
+
|
6
|
+
|
7
|
+
class Command(BaseCommand):
|
8
|
+
help = 'Crea una aplicación llamada Home, estructura de carpetas y configura urls automáticamente en el proyecto especificado'
|
9
|
+
|
10
|
+
def handle(self, *args, **kwargs):
|
11
|
+
# Nombre de la aplicación a crear
|
12
|
+
app_name = "Home"
|
13
|
+
|
14
|
+
# Paso 1: Solicitar el nombre de la aplicación principal al usuario
|
15
|
+
project_name = input(
|
16
|
+
"Por favor, ingresa el nombre de la aplicación principal del proyecto: ")
|
17
|
+
|
18
|
+
# Paso 2: Crear la aplicación "Home" si no existe
|
19
|
+
if not os.path.exists(app_name):
|
20
|
+
self.stdout.write(f"Creando la aplicación '{app_name}'...")
|
21
|
+
call_command('startapp', app_name)
|
22
|
+
else:
|
23
|
+
self.stdout.write(f"La aplicación '{app_name}' ya existe.")
|
24
|
+
|
25
|
+
# Paso 3: Crear el archivo urls.py en la aplicación "Home" si no existe
|
26
|
+
urls_path = os.path.join(app_name, 'urls.py')
|
27
|
+
if not os.path.exists(urls_path):
|
28
|
+
self.stdout.write(f"Creando el archivo '{urls_path}'...")
|
29
|
+
with open(urls_path, 'w') as f:
|
30
|
+
f.write(
|
31
|
+
"from django.urls import path\n\n"
|
32
|
+
"urlpatterns = [\n"
|
33
|
+
" # Añade tus rutas aquí\n"
|
34
|
+
"]\n"
|
35
|
+
)
|
36
|
+
else:
|
37
|
+
self.stdout.write(f"El archivo '{urls_path}' ya existe.")
|
38
|
+
|
39
|
+
# Paso 4: Modificar el archivo urls.py principal del proyecto
|
40
|
+
project_urls_path = os.path.join(project_name, 'urls.py')
|
41
|
+
if os.path.exists(project_urls_path):
|
42
|
+
with open(project_urls_path, 'r') as f:
|
43
|
+
content = f.read()
|
44
|
+
|
45
|
+
include_statement = "path('', include('Home.urls'))"
|
46
|
+
if include_statement not in content:
|
47
|
+
self.stdout.write(f"Añadiendo la ruta '{
|
48
|
+
include_statement}' al archivo urls.py principal...")
|
49
|
+
with open(project_urls_path, 'a') as f:
|
50
|
+
f.write(
|
51
|
+
"\nfrom django.urls import include, path\n\n"
|
52
|
+
"urlpatterns += [\n"
|
53
|
+
f" {include_statement},\n"
|
54
|
+
"]\n"
|
55
|
+
)
|
56
|
+
else:
|
57
|
+
self.stdout.write(
|
58
|
+
"La ruta ya existe en el archivo urls.py principal.")
|
59
|
+
else:
|
60
|
+
self.stdout.write(f"No se encontró el archivo principal urls.py en '{
|
61
|
+
project_urls_path}'. Asegúrate de que el nombre del proyecto sea correcto.")
|
62
|
+
|
63
|
+
# Paso 5: Crear la carpeta services y el archivo authentication.py en Home
|
64
|
+
services_dir = os.path.join(app_name, 'services')
|
65
|
+
# Crea la carpeta si no existe
|
66
|
+
os.makedirs(services_dir, exist_ok=True)
|
67
|
+
authentication_file_path = os.path.join(
|
68
|
+
services_dir, 'authentication.py')
|
69
|
+
|
70
|
+
if not os.path.exists(authentication_file_path):
|
71
|
+
self.stdout.write(f"Creando el archivo '{
|
72
|
+
authentication_file_path}'...")
|
73
|
+
with open(authentication_file_path, 'w') as f:
|
74
|
+
f.write(
|
75
|
+
"from django.shortcuts import render, redirect\n"
|
76
|
+
"from django.contrib.auth.forms import UserCreationForm, AuthenticationForm\n"
|
77
|
+
"from django.contrib.auth.models import User\n"
|
78
|
+
"from django.contrib.auth import login, logout, authenticate\n"
|
79
|
+
"from django.db import IntegrityError\n\n\n"
|
80
|
+
"class Authentication:\n"
|
81
|
+
" @staticmethod\n"
|
82
|
+
" def get_signup(request):\n"
|
83
|
+
" if request.method == 'GET':\n"
|
84
|
+
" return render(request, 'singup.html', {\n"
|
85
|
+
" 'form': UserCreationForm()\n"
|
86
|
+
" })\n"
|
87
|
+
" elif request.method == 'POST':\n"
|
88
|
+
" if request.POST['password1'] == request.POST['password2']:\n"
|
89
|
+
" try:\n"
|
90
|
+
" # Register user\n"
|
91
|
+
" user = User.objects.create_user(\n"
|
92
|
+
" username=request.POST['username'], password=request.POST['password2'])\n"
|
93
|
+
" user.save()\n"
|
94
|
+
" login(request, user)\n"
|
95
|
+
" return redirect('logged')\n"
|
96
|
+
" except IntegrityError:\n"
|
97
|
+
" return render(request, 'singup.html', {\n"
|
98
|
+
" 'form': UserCreationForm(),\n"
|
99
|
+
" 'error': 'User already exists'\n"
|
100
|
+
" })\n"
|
101
|
+
" return render(request, 'singup.html', {\n"
|
102
|
+
" 'form': UserCreationForm(),\n"
|
103
|
+
" 'error': 'Passwords do not match'\n"
|
104
|
+
" })\n\n"
|
105
|
+
" @staticmethod\n"
|
106
|
+
" def get_signout(request):\n"
|
107
|
+
" logout(request)\n"
|
108
|
+
" return redirect('home')\n\n"
|
109
|
+
" @staticmethod\n"
|
110
|
+
" def get_signing(request):\n"
|
111
|
+
" if request.method == 'GET':\n"
|
112
|
+
" return render(request, 'login.html', {\n"
|
113
|
+
" 'form': AuthenticationForm,\n"
|
114
|
+
" })\n"
|
115
|
+
" elif request.method == 'POST':\n"
|
116
|
+
" try:\n"
|
117
|
+
" User.objects.get(username=request.POST['username'])\n"
|
118
|
+
" except User.DoesNotExist:\n"
|
119
|
+
" return render(request, 'login.html', {\n"
|
120
|
+
" 'form': AuthenticationForm,\n"
|
121
|
+
" 'error': 'User does not exist in the database'\n"
|
122
|
+
" })\n"
|
123
|
+
" user = authenticate(\n"
|
124
|
+
" request, username=request.POST['username'], password=request.POST['password'])\n"
|
125
|
+
" if user is None:\n"
|
126
|
+
" return render(request, 'login.html', {\n"
|
127
|
+
" 'form': AuthenticationForm,\n"
|
128
|
+
" 'error': 'username or password is incorrect'\n"
|
129
|
+
" })\n"
|
130
|
+
" else:\n"
|
131
|
+
" login(request, user)\n"
|
132
|
+
" return redirect('logged')\n\n"
|
133
|
+
" @staticmethod\n"
|
134
|
+
" def get_logged(request):\n"
|
135
|
+
" return render(request, 'logged.html')\n\n"
|
136
|
+
" def dispatch(self, request, *args, **kwargs):\n"
|
137
|
+
" match request.path:\n"
|
138
|
+
" case \"/signup\":\n"
|
139
|
+
" return self.get_signup(request)\n"
|
140
|
+
" case \"/login\":\n"
|
141
|
+
" return self.get_signing(request)\n"
|
142
|
+
" case \"/logout\":\n"
|
143
|
+
" return self.get_signout(request)\n"
|
144
|
+
" case \"/logged\":\n"
|
145
|
+
" return self.get_logged(request)\n"
|
146
|
+
" case \"/\":\n"
|
147
|
+
" return self.get(request)\n"
|
148
|
+
" case _:\n"
|
149
|
+
" return self.get(request)\n"
|
150
|
+
)
|
151
|
+
else:
|
152
|
+
self.stdout.write(
|
153
|
+
f"El archivo '{authentication_file_path}' ya existe.")
|
154
|
+
|
155
|
+
# Paso 6: Crear la carpeta templates y los archivos HTML
|
156
|
+
templates_dir = os.path.join(project_name, 'templates')
|
157
|
+
layouts_dir = os.path.join(templates_dir, 'layouts')
|
158
|
+
static_dir = os.path.join(project_name, 'static')
|
159
|
+
css_dir = os.path.join(static_dir, 'css')
|
160
|
+
js_dir = os.path.join(static_dir, 'js')
|
161
|
+
|
162
|
+
# Crear los directorios necesarios
|
163
|
+
os.makedirs(js_dir, exist_ok=True)
|
164
|
+
os.makedirs(css_dir, exist_ok=True)
|
165
|
+
os.makedirs(layouts_dir, exist_ok=True)
|
166
|
+
os.makedirs(templates_dir, exist_ok=True)
|
167
|
+
os.makedirs(static_dir, exist_ok=True)
|
168
|
+
|
169
|
+
# Rutas de los archivos fuente y destino
|
170
|
+
css_source_path = os.path.join('utils', 'css', 'authentication.css')
|
171
|
+
authentication_css = os.path.join(css_dir, 'authentication.css')
|
172
|
+
js_source_path = os.path.join('utils', 'js', 'alertErrors.js')
|
173
|
+
alertErrors_js = os.path.join(js_dir, 'alertErrors.js')
|
174
|
+
|
175
|
+
# Crear archivos si no existen
|
176
|
+
if not os.path.exists(authentication_css):
|
177
|
+
try:
|
178
|
+
with open(css_source_path, 'r') as source_file:
|
179
|
+
css_content = source_file.read()
|
180
|
+
with open(js_source_path, 'r') as source_file:
|
181
|
+
js_content = source_file.read()
|
182
|
+
|
183
|
+
with open(authentication_css, 'w') as f:
|
184
|
+
f.write(css_content)
|
185
|
+
with open(alertErrors_js, 'w') as f:
|
186
|
+
f.write(js_content)
|
187
|
+
|
188
|
+
print(f"Archivo CSS creado exitosamente en {
|
189
|
+
authentication_css}")
|
190
|
+
print(f"Archivo JS creado exitosamente en {alertErrors_js}")
|
191
|
+
except FileNotFoundError as e:
|
192
|
+
print(f"Archivo fuente no encontrado: {e}")
|
193
|
+
except Exception as e:
|
194
|
+
print(f"Error al crear el archivo: {e}")
|
195
|
+
|
196
|
+
# Crear el archivo de layout (index.html) si no existe
|
197
|
+
index_page_source = os.path.join('utils', 'layouts', 'index.html')
|
198
|
+
layouts_source = os.path.join(layouts_dir, 'index.html')
|
199
|
+
|
200
|
+
if not os.path.exists(layouts_source):
|
201
|
+
try:
|
202
|
+
with open(index_page_source, 'r') as source_file:
|
203
|
+
index_content = source_file.read()
|
204
|
+
|
205
|
+
with open(layouts_source, 'w') as f:
|
206
|
+
f.write(index_content)
|
207
|
+
|
208
|
+
print("Archivo de layout creado exitosamente")
|
209
|
+
except FileNotFoundError as e:
|
210
|
+
print(f"Archivo fuente no encontrado: {e}")
|
211
|
+
except Exception as e:
|
212
|
+
print(f"Error al crear el archivo: {e}")
|
213
|
+
|
214
|
+
# Crear las páginas HTML adicionales (home, signup, login, logged)
|
215
|
+
# Rutas de los archivos fuente
|
216
|
+
home_page = os.path.join('utils', 'pages', 'home.html')
|
217
|
+
signup_page = os.path.join('utils', 'pages', 'signup.html')
|
218
|
+
login_page = os.path.join('utils', 'pages', 'login.html')
|
219
|
+
logged_page = os.path.join('utils', 'pages', 'logged.html')
|
220
|
+
|
221
|
+
# Rutas de los archivos de destino
|
222
|
+
home_dest = os.path.join(templates_dir, 'home.html')
|
223
|
+
signup_dest = os.path.join(templates_dir, 'signup.html')
|
224
|
+
login_dest = os.path.join(templates_dir, 'login.html')
|
225
|
+
logged_dest = os.path.join(templates_dir, 'logged.html')
|
226
|
+
|
227
|
+
# Crear cada archivo HTML si no existe
|
228
|
+
for source_path, dest_path, page_name in [
|
229
|
+
(home_page, home_dest, 'Home'),
|
230
|
+
(signup_page, signup_dest, 'Signup'),
|
231
|
+
(login_page, login_dest, 'Login'),
|
232
|
+
(logged_page, logged_dest, 'Logged')
|
233
|
+
]:
|
234
|
+
if not os.path.exists(dest_path):
|
235
|
+
try:
|
236
|
+
with open(source_path, 'r') as source_file:
|
237
|
+
content = source_file.read()
|
238
|
+
with open(dest_path, 'w') as dest_file:
|
239
|
+
dest_file.write(content)
|
240
|
+
print(f"Archivo {page_name} creado exitosamente en {
|
241
|
+
dest_path}")
|
242
|
+
except FileNotFoundError as e:
|
243
|
+
print(f"Archivo fuente no encontrado: {source_path}")
|
244
|
+
except Exception as e:
|
245
|
+
print(f"Error al crear el archivo {page_name}: {e}")
|
246
|
+
|
247
|
+
self.stdout.write(self.style.SUCCESS(
|
248
|
+
"Comando ejecutado exitosamente."))
|
{componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0/componentsDjangoType.egg-info}/PKG-INFO
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: componentsDjangoType
|
3
|
-
Version: 0.0
|
3
|
+
Version: 1.0.0
|
4
4
|
Summary: A Django app for creating HTML components
|
5
5
|
Home-page: https://github.com/jose-CR/componentsDjangoType
|
6
6
|
Author: Alejandro
|
@@ -17,7 +17,6 @@ Classifier: Programming Language :: Python :: 3.7
|
|
17
17
|
Classifier: Framework :: Django :: 3.2
|
18
18
|
Description-Content-Type: text/markdown
|
19
19
|
License-File: LICENSE
|
20
|
-
Requires-Dist: Django>=3.2
|
21
20
|
|
22
21
|
# componentsDjangotype
|
23
22
|
|
@@ -39,7 +38,7 @@ Este comando de Django te permite crear un componente HTML dentro del directorio
|
|
39
38
|
|
40
39
|
## Uso
|
41
40
|
|
42
|
-
1. Ejecuta el comando en tu terminal: `python manage.py
|
41
|
+
1. Ejecuta el comando en tu terminal: `python manage.py createcomponent <nombre_de_aplicación> <carpeta/archivo> --type=<template|static>`
|
43
42
|
2. Reemplaza `<nombre_de_aplicación>` con el nombre de la aplicación donde deseas crear el componente.
|
44
43
|
3. Reemplaza `<ruta_del_archivo>` con la ruta donde deseas crear el componente dentro del directorio `templates` o `static` de la aplicación.
|
45
44
|
4. La bandera `--type` especifica si deseas crear un componente en el directorio `templates` o `static`. Por defecto, se establece en `template`.
|
{componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType.egg-info/SOURCES.txt
RENAMED
@@ -10,4 +10,5 @@ componentsDjangoType.egg-info/requires.txt
|
|
10
10
|
componentsDjangoType.egg-info/top_level.txt
|
11
11
|
componentsDjangoType/management/__init__.py
|
12
12
|
componentsDjangoType/management/commands/__init__.py
|
13
|
-
componentsDjangoType/management/commands/createcomponent.py
|
13
|
+
componentsDjangoType/management/commands/createcomponent.py
|
14
|
+
componentsDjangoType/management/commands/createcomponentApp.py
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{componentsdjangotype-0.0.4 → componentsDjangoType-1.0.0}/componentsDjangoType.egg-info/requires.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|