componentsDjangoType 2.0.6__tar.gz → 2.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {componentsdjangotype-2.0.6/componentsDjangoType.egg-info → componentsdjangotype-2.0.7}/PKG-INFO +1 -1
  2. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7/componentsDjangoType.egg-info}/PKG-INFO +1 -1
  3. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/componentsDjangoType.egg-info/SOURCES.txt +5 -1
  4. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/componentsDjangoType.egg-info/top_level.txt +1 -0
  5. componentsdjangotype-2.0.7/services/__init__.py +0 -0
  6. componentsdjangotype-2.0.7/services/authentication/__init__.py +0 -0
  7. componentsdjangotype-2.0.7/services/authentication/auth.py +75 -0
  8. componentsdjangotype-2.0.7/services/authenticator_configurator.py +167 -0
  9. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/setup.py +1 -1
  10. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/LICENSE +0 -0
  11. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/MANIFEST.in +0 -0
  12. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/README.md +0 -0
  13. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/componentsDjangoType/__init__.py +0 -0
  14. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/componentsDjangoType/management/__init__.py +0 -0
  15. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/componentsDjangoType/management/commands/__init__.py +0 -0
  16. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/componentsDjangoType/management/commands/createApp.py +0 -0
  17. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/componentsDjangoType/management/commands/createcomponent.py +0 -0
  18. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/componentsDjangoType.egg-info/dependency_links.txt +0 -0
  19. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/componentsDjangoType.egg-info/requires.txt +0 -0
  20. {componentsdjangotype-2.0.6 → componentsdjangotype-2.0.7}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: componentsDjangoType
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: Comandos para crear archivos html, css y js
5
5
  Home-page: https://github.com/jose-CR/componentsDjangoType
6
6
  Author: Alejandro
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: componentsDjangoType
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: Comandos para crear archivos html, css y js
5
5
  Home-page: https://github.com/jose-CR/componentsDjangoType
6
6
  Author: Alejandro
@@ -11,4 +11,8 @@ componentsDjangoType.egg-info/top_level.txt
11
11
  componentsDjangoType/management/__init__.py
12
12
  componentsDjangoType/management/commands/__init__.py
13
13
  componentsDjangoType/management/commands/createApp.py
14
- componentsDjangoType/management/commands/createcomponent.py
14
+ componentsDjangoType/management/commands/createcomponent.py
15
+ services/__init__.py
16
+ services/authenticator_configurator.py
17
+ services/authentication/__init__.py
18
+ services/authentication/auth.py
File without changes
@@ -0,0 +1,75 @@
1
+ from django.shortcuts import render, redirect
2
+ from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
3
+ from django.contrib.auth.models import User
4
+ from django.contrib.auth import login, logout, authenticate
5
+ from django.db import IntegrityError
6
+ class Authentication:
7
+ @staticmethod
8
+ def get_signup(request):
9
+ if request.method == 'GET':
10
+ return render(request, 'signup.html', {
11
+ 'form': UserCreationForm()
12
+ })
13
+ elif request.method == 'POST':
14
+ if request.POST['password1'] == request.POST['password2']:
15
+ try:
16
+ # Register user\n"
17
+ user = User.objects.create_user(
18
+ username=request.POST['username'], password=request.POST['password2'])
19
+ user.save()
20
+ login(request, user)
21
+ return redirect('logged')
22
+ except IntegrityError:
23
+ return render(request, 'signup.html', {
24
+ 'form': UserCreationForm(),
25
+ 'error': 'User already exists'
26
+ })
27
+ return render(request, 'signup.html', {
28
+ 'form': UserCreationForm(),
29
+ 'error': 'Passwords do not match'
30
+ })
31
+ @staticmethod
32
+ def get_signout(request):
33
+ logout(request)
34
+ return redirect('home')
35
+ @staticmethod
36
+ def get_signing(request):
37
+ if request.method == 'GET':
38
+ return render(request, 'login.html', {
39
+ 'form': AuthenticationForm,
40
+ })
41
+ elif request.method == 'POST':
42
+ try:
43
+ User.objects.get(username=request.POST['username'])
44
+ except User.DoesNotExist:
45
+ return render(request, 'login.html', {
46
+ 'form': AuthenticationForm,
47
+ 'error': 'User does not exist in the database'
48
+ })
49
+ user = authenticate(
50
+ request, username=request.POST['username'], password=request.POST['password'])
51
+ if user is None:
52
+ return render(request, 'login.html', {
53
+ 'form': AuthenticationForm,
54
+ 'error': 'username or password is incorrect'
55
+ })
56
+ else:
57
+ login(request, user)
58
+ return redirect('logged')
59
+ @staticmethod
60
+ def get_logged(request):
61
+ return render(request, 'logged.html')
62
+ def dispatch(self, request, *args, **kwargs):
63
+ match request.path:
64
+ case "/signup":
65
+ return self.get_signup(request)
66
+ case "/login":
67
+ return self.get_signing(request)
68
+ case "/logout":
69
+ return self.get_signout(request)
70
+ case "/logged":
71
+ return self.get_logged(request)
72
+ case "/":
73
+ return self.get(request)
74
+ case _:
75
+ return self.get(request)
@@ -0,0 +1,167 @@
1
+ import os
2
+ import ast
3
+ from django.core.management.base import BaseCommand
4
+ from django.core.management import call_command
5
+
6
+ class DjangoProjectManager:
7
+ def __init__(self, app_name, project_name):
8
+ self.app_name = app_name
9
+ self.project_name = project_name
10
+
11
+ def create_app(self):
12
+ """
13
+ Crea una aplicación de Django con el nombre especificado si no existe.
14
+ """
15
+ app_name = self.app_name
16
+ if not os.path.exists(app_name):
17
+ print(f"Creando la aplicación '{app_name}'...")
18
+ call_command('startapp', app_name)
19
+ if os.path.exists(app_name):
20
+ print(f"La aplicación '{app_name}' fue creada exitosamente.")
21
+ else:
22
+ print(f"Error: No se pudo crear la aplicación '{app_name}'.")
23
+ else:
24
+ print(f"La aplicación '{app_name}' ya existe.")
25
+
26
+ def installed_app(self):
27
+ """
28
+ Agrega la aplicación al archivo settings.py en la lista INSTALLED_APPS
29
+ si no está ya presente. Asegura que se mantenga el formato adecuado.
30
+ """
31
+ settings_path = os.path.join(self.project_name, 'settings.py')
32
+
33
+ # Leer el archivo settings.py
34
+ with open(settings_path, 'r') as file:
35
+ settings_content = file.read()
36
+
37
+ # Comprobar si la aplicación ya está en INSTALLED_APPS
38
+ if f"'{self.app_name}'" not in settings_content:
39
+ # Buscar la línea donde está la lista INSTALLED_APPS
40
+ installed_apps_start = settings_content.find("INSTALLED_APPS = [")
41
+ installed_apps_end = settings_content.find("]", installed_apps_start) + 1
42
+
43
+ # Extraer la lista INSTALLED_APPS
44
+ installed_apps_content = settings_content[installed_apps_start:installed_apps_end]
45
+
46
+ # Comprobar si la aplicación no está ya en INSTALLED_APPS
47
+ if f"'{self.app_name}'" not in installed_apps_content:
48
+ # Insertar la aplicación dentro de la lista
49
+ new_installed_apps = installed_apps_content[:-1] + f",\n '{self.app_name}'\n]"
50
+
51
+ # Reemplazar el bloque INSTALLED_APPS con la nueva lista
52
+ new_settings_content = settings_content[:installed_apps_start] + new_installed_apps + settings_content[installed_apps_end:]
53
+
54
+ # Escribir los cambios de vuelta en settings.py
55
+ with open(settings_path, 'w') as file:
56
+ file.write(new_settings_content)
57
+
58
+ print(f"'{self.app_name}' fue agregado a INSTALLED_APPS.")
59
+ else:
60
+ print(f"'{self.app_name}' ya está en INSTALLED_APPS.")
61
+ else:
62
+ print(f"'{self.app_name}' ya está en INSTALLED_APPS.")
63
+
64
+ def create_urls(self):
65
+ """
66
+ Crea el archivo 'urls.py' si no existe, y si existe, agrega nuevas rutas
67
+ sin sobrescribir el contenido existente.
68
+ """
69
+ urls_path = os.path.join(self.app_name, 'urls.py')
70
+
71
+ if not os.path.exists(urls_path):
72
+ # Si el archivo no existe, lo creamos con un contenido básico
73
+ self.stdout.write(f"Creando el archivo '{urls_path}'...")
74
+ with open(urls_path, 'w') as f:
75
+ f.write("""from django.contrib import admin
76
+ from django.urls import path, include\n\n
77
+
78
+ urlpatterns = [
79
+ path('admin/', admin.site.urls),
80
+ path('', include(Home.urls)),
81
+ # Añade tus rutas aquí
82
+ ]\n""")
83
+ else:
84
+ # Si el archivo ya existe, lo leemos y agregamos nuevas rutas
85
+ self.stdout.write(f"El archivo '{urls_path}' ya existe. Agregando nuevas rutas...")
86
+
87
+ with open(urls_path, 'r') as f:
88
+ urls_content = f.read()
89
+
90
+ # Verificar si ya existe una lista 'urlpatterns'
91
+ if 'urlpatterns = [' in urls_content:
92
+ # Verificar si 'path' ya está en la lista
93
+ if 'path' not in urls_content:
94
+ urls_content = urls_content.replace(
95
+ "urlpatterns = [",
96
+ "urlpatterns = [\n path('admin/', admin.site.urls),"
97
+ )
98
+ # Verificar si 'include' ya está presente en urlpatterns
99
+ if 'include' not in urls_content:
100
+ urls_content = urls_content.replace(
101
+ "]\n",
102
+ " path('', include('home.urls')),\n # Otras rutas aquí\n]"
103
+ )
104
+ else:
105
+ # Si ya contiene 'include', solo agregamos una nueva ruta
106
+ urls_content = urls_content.replace(
107
+ "]\n",
108
+ " path('', include('home.urls')),\n # Otras rutas aquí\n]"
109
+ )
110
+
111
+ # Escribir el contenido actualizado en el archivo
112
+ with open(urls_path, 'w') as f:
113
+ f.write(urls_content)
114
+ self.stdout.write(f"Nuevas rutas fueron agregadas a '{urls_path}'.")
115
+ else:
116
+ self.stdout.write(f"No se encontró la lista 'urlpatterns' en '{urls_path}'.")
117
+
118
+ def creation_auth(self):
119
+ services_dir = os.path.join(self.app_name, 'services')
120
+ authentication_dir = os.path.join(services_dir, 'authentication')
121
+ os.makedirs(authentication_dir, exist_ok=True)
122
+
123
+ authentication_path = os.path.join(authentication_dir, 'auth.py')
124
+
125
+ if not os.path.exists(authentication_path):
126
+ self.stdout.write(f"Creando el archivo '{authentication_path}'...")
127
+
128
+ auth_path = os.path.join(self.app_name, 'services', 'authentication', 'auth.py')
129
+
130
+ # Leer el código del archivo de origen
131
+ with open(auth_path, 'r') as file:
132
+ auth_code = file.read()
133
+
134
+ # Escribir el código en el archivo de destino
135
+ with open(authentication_path, 'w') as file:
136
+ file.write(auth_code)
137
+
138
+ self.stdout.write(f"El archivo '{authentication_path}' fue creado y el código fue escrito.")
139
+ else:
140
+ self.stdout.write(f"El archivo '{authentication_path}' ya existe.")
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='componentsDjangoType',
5
- version='2.0.6',
5
+ version='2.0.7',
6
6
  packages=find_packages(),
7
7
  include_package_data=True,
8
8
  license='MIT',