diff --git a/cosiap_api/administracion/admin.py b/cosiap_api/administracion/admin.py index b8f0384fea0630494a959212d55d94d047ac3484..c96937d883a4d45d6214f59ef71d154dbf500f1b 100644 --- a/cosiap_api/administracion/admin.py +++ b/cosiap_api/administracion/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin -from .models import Convocatoria +from .models import Convocatoria, ConfiguracionColores admin.site.register(Convocatoria) +admin.site.register(ConfiguracionColores) \ No newline at end of file diff --git a/cosiap_api/administracion/migrations/0003_crear_modelo_configuracion_diseno.py b/cosiap_api/administracion/migrations/0003_crear_modelo_configuracion_diseno.py deleted file mode 100644 index 776342d795f980282b3159fcf96fd9fea436f7d2..0000000000000000000000000000000000000000 --- a/cosiap_api/administracion/migrations/0003_crear_modelo_configuracion_diseno.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 5.0.8 on 2024-09-10 02:15 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('administracion', '0002_eliminar_columna_nombre'), - ] - - operations = [ - migrations.CreateModel( - name='ConfiguracionEstilo', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('logo', models.ImageField(blank=True, null=True, upload_to='logos/')), - ('color_primario', models.CharField(help_text='Formato HEX, ej. #FFFFFF', max_length=7)), - ('color_secundario', models.CharField(help_text='Formato HEX, ej. #000000', max_length=7)), - ('color_fondo', models.CharField(help_text='Formato HEX, ej. #F0F0F0', max_length=7)), - ], - ), - ] diff --git a/cosiap_api/administracion/migrations/0003_modelo_configuracion_colores.py b/cosiap_api/administracion/migrations/0003_modelo_configuracion_colores.py new file mode 100644 index 0000000000000000000000000000000000000000..78a71b249884a5379aef6efad664fa04eace3c79 --- /dev/null +++ b/cosiap_api/administracion/migrations/0003_modelo_configuracion_colores.py @@ -0,0 +1,120 @@ +# Generated by Django 5.0.8 on 2024-09-13 17:37 + +from django.db import migrations, models + + +def create_default_configuration(apps, schema_editor): + ConfiguracionEstilo = apps.get_model('administracion', 'ConfiguracionColores') + ConfiguracionEstilo.objects.create( + logo=None, # Ajusta esto si quieres un logo por defecto + principal_mc='rgb(252, 226, 228)', + principal_c='rgb(245, 173, 171)', + principal='rgb(226, 116, 110)', + principal_f='rgb(187, 68, 51)', + principal_mf='rgb(120, 16, 5)', + secundario_mc='#e0e0e0', + secundario_c='#c0c0c0', + secundario='#a0a0a0', + secundario_f='#808080', + secundario_mf='#606060', + exito_f='#8abc94', + exito='#b9e2c1', + exito_c='#d5f5e2', + exito_btn='#527f18', + error_f='#c7564a', + error='#e4756f', + error_c='#e1b2af', + precaucion_f='#d4bf47', + precaucion='#e4d26f', + precaucion_c='#f1e7a8', + cancelar_f='#b8a9a8', + cancelar='#dccbca', + cancelar_c='#e9dedd', + informacion_f='#5b9bd5', + informacion='#85c1e9', + informacion_c='#cfe2f3', + neutral_f='#6c757d', + neutral='#adb5bd', + neutral_c='#dee2e6', + gris_principal='#b9b4b4', + gris_0='#f8f8f8', + gris_1='#efefef', + gris_2='#e0e0e0', + gris_3='#c0c0c0', + gris_4='#a0a0a0', + gris_5='#808080', + gris_6='#606060', + gris_7='#404040', + gris_8='#202020', + blanco='#ffffff', + negro='#000000', + pagina_fondo='#eee5e5', + texto_general='#676767', + es_default=True + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ('administracion', '0002_eliminar_columna_nombre'), + ] + + operations = [ + migrations.CreateModel( + name='ConfiguracionColores', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('logo', models.ImageField(blank=True, null=True, upload_to='logos/')), + ('principal_mc', models.CharField(default='rgb(252, 226, 228)', max_length=20)), + ('principal_c', models.CharField(default='rgb(245, 173, 171)', max_length=20)), + ('principal', models.CharField(default='rgb(226, 116, 110)', max_length=20)), + ('principal_f', models.CharField(default='rgb(187, 68, 51)', max_length=20)), + ('principal_mf', models.CharField(default='rgb(120, 16, 5)', max_length=20)), + ('secundario_mc', models.CharField(default='#e0e0e0', max_length=7)), + ('secundario_c', models.CharField(default='#c0c0c0', max_length=7)), + ('secundario', models.CharField(default='#a0a0a0', max_length=7)), + ('secundario_f', models.CharField(default='#808080', max_length=7)), + ('secundario_mf', models.CharField(default='#606060', max_length=7)), + ('exito_f', models.CharField(default='#8abc94', max_length=7)), + ('exito', models.CharField(default='#b9e2c1', max_length=7)), + ('exito_c', models.CharField(default='#d5f5e2', max_length=7)), + ('exito_btn', models.CharField(default='#527f18', max_length=7)), + ('error_f', models.CharField(default='#c7564a', max_length=7)), + ('error', models.CharField(default='#e4756f', max_length=7)), + ('error_c', models.CharField(default='#e1b2af', max_length=7)), + ('precaucion_f', models.CharField(default='#d4bf47', max_length=7)), + ('precaucion', models.CharField(default='#e4d26f', max_length=7)), + ('precaucion_c', models.CharField(default='#f1e7a8', max_length=7)), + ('cancelar_f', models.CharField(default='#b8a9a8', max_length=7)), + ('cancelar', models.CharField(default='#dccbca', max_length=7)), + ('cancelar_c', models.CharField(default='#e9dedd', max_length=7)), + ('informacion_f', models.CharField(default='#5b9bd5', max_length=7)), + ('informacion', models.CharField(default='#85c1e9', max_length=7)), + ('informacion_c', models.CharField(default='#cfe2f3', max_length=7)), + ('neutral_f', models.CharField(default='#6c757d', max_length=7)), + ('neutral', models.CharField(default='#adb5bd', max_length=7)), + ('neutral_c', models.CharField(default='#dee2e6', max_length=7)), + ('gris_principal', models.CharField(default='#b9b4b4', max_length=7)), + ('gris_0', models.CharField(default='#f8f8f8', max_length=7)), + ('gris_1', models.CharField(default='#efefef', max_length=7)), + ('gris_2', models.CharField(default='#e0e0e0', max_length=7)), + ('gris_3', models.CharField(default='#c0c0c0', max_length=7)), + ('gris_4', models.CharField(default='#a0a0a0', max_length=7)), + ('gris_5', models.CharField(default='#808080', max_length=7)), + ('gris_6', models.CharField(default='#606060', max_length=7)), + ('gris_7', models.CharField(default='#404040', max_length=7)), + ('gris_8', models.CharField(default='#202020', max_length=7)), + ('blanco', models.CharField(default='#ffffff', max_length=7)), + ('negro', models.CharField(default='#000000', max_length=7)), + ('pagina_fondo', models.CharField(default='#eee5e5', max_length=7)), + ('texto_general', models.CharField(default='#676767', max_length=7)), + ('es_default', models.BooleanField(default=False)), + ], + options={ + 'verbose_name': 'Configuración de Estilo', + 'verbose_name_plural': 'Configuraciones de Estilo', + }, + ), + migrations.RunPython(create_default_configuration), + ] diff --git a/cosiap_api/administracion/models.py b/cosiap_api/administracion/models.py index 85b2a16166f57d075630790369bbe3fddc693899..1bd5cc63f5cd372bc1c6632afba7df56e9c936c4 100644 --- a/cosiap_api/administracion/models.py +++ b/cosiap_api/administracion/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.core.exceptions import ValidationError class Convocatoria(models.Model): ''' @@ -7,11 +8,80 @@ class Convocatoria(models.Model): abierta = models.BooleanField(default=False) -class ConfiguracionEstilo(models.Model): +class ConfiguracionColores(models.Model): logo = models.ImageField(upload_to='logos/', blank=True, null=True) - color_primario = models.CharField(max_length=7, help_text='Formato HEX, ej. #FFFFFF') - color_secundario = models.CharField(max_length=7, help_text='Formato HEX, ej. #000000') - color_fondo = models.CharField(max_length=7, help_text='Formato HEX, ej. #F0F0F0') + + # Colores principales + principal_mc = models.CharField(max_length=20, default='rgb(252, 226, 228)') + principal_c = models.CharField(max_length=20, default='rgb(245, 173, 171)') + principal = models.CharField(max_length=20, default='rgb(226, 116, 110)') + principal_f = models.CharField(max_length=20, default='rgb(187, 68, 51)') + principal_mf = models.CharField(max_length=20, default='rgb(120, 16, 5)') + + # Colores secundarios + secundario_mc = models.CharField(max_length=7, default='#e0e0e0') + secundario_c = models.CharField(max_length=7, default='#c0c0c0') + secundario = models.CharField(max_length=7, default='#a0a0a0') + secundario_f = models.CharField(max_length=7, default='#808080') + secundario_mf = models.CharField(max_length=7, default='#606060') + + # Colores de éxito, error, precaución, información, etc. + exito_f = models.CharField(max_length=7, default='#8abc94') + exito = models.CharField(max_length=7, default='#b9e2c1') + exito_c = models.CharField(max_length=7, default='#d5f5e2') + exito_btn = models.CharField(max_length=7, default='#527f18') + + error_f = models.CharField(max_length=7, default='#c7564a') + error = models.CharField(max_length=7, default='#e4756f') + error_c = models.CharField(max_length=7, default='#e1b2af') + + precaucion_f = models.CharField(max_length=7, default='#d4bf47') + precaucion = models.CharField(max_length=7, default='#e4d26f') + precaucion_c = models.CharField(max_length=7, default='#f1e7a8') + + cancelar_f = models.CharField(max_length=7, default='#b8a9a8') + cancelar = models.CharField(max_length=7, default='#dccbca') + cancelar_c = models.CharField(max_length=7, default='#e9dedd') + + informacion_f = models.CharField(max_length=7, default='#5b9bd5') + informacion = models.CharField(max_length=7, default='#85c1e9') + informacion_c = models.CharField(max_length=7, default='#cfe2f3') + + # Colores neutros y grises + neutral_f = models.CharField(max_length=7, default='#6c757d') + neutral = models.CharField(max_length=7, default='#adb5bd') + neutral_c = models.CharField(max_length=7, default='#dee2e6') + + gris_principal = models.CharField(max_length=7, default='#b9b4b4') + gris_0 = models.CharField(max_length=7, default='#f8f8f8') + gris_1 = models.CharField(max_length=7, default='#efefef') + gris_2 = models.CharField(max_length=7, default='#e0e0e0') + gris_3 = models.CharField(max_length=7, default='#c0c0c0') + gris_4 = models.CharField(max_length=7, default='#a0a0a0') + gris_5 = models.CharField(max_length=7, default='#808080') + gris_6 = models.CharField(max_length=7, default='#606060') + gris_7 = models.CharField(max_length=7, default='#404040') + gris_8 = models.CharField(max_length=7, default='#202020') + + blanco = models.CharField(max_length=7, default='#ffffff') + negro = models.CharField(max_length=7, default='#000000') + + # Colores generales + pagina_fondo = models.CharField(max_length=7, default='#eee5e5') + texto_general = models.CharField(max_length=7, default='#676767') + + es_default = models.BooleanField(default=False) + + def clean(self): + """ + Asegurar que solo haya una configuración por defecto. + """ + if self.es_default and ConfiguracionEstilo.objects.filter(es_default=True).exclude(id=self.id).exists(): + raise ValidationError('Solo puede haber una configuración predeterminada.') def __str__(self): - return f"Configuración de diseño - ID: {self.id}" \ No newline at end of file + return f"Configuración de diseño - ID: {self.id}" + + class Meta: + verbose_name = "Configuración de Estilo" + verbose_name_plural = "Configuraciones de Estilo" \ No newline at end of file diff --git a/cosiap_api/administracion/serializers.py b/cosiap_api/administracion/serializers.py new file mode 100644 index 0000000000000000000000000000000000000000..84d83f26ed3cdfdbb16a97104dba91b6c7573e43 --- /dev/null +++ b/cosiap_api/administracion/serializers.py @@ -0,0 +1,7 @@ +from rest_framework import serializers +from .models import ConfiguracionColores + +class ConfiguracionEstiloSerializer(serializers.ModelSerializer): + class Meta: + model = ConfiguracionColores + fields = '__all__' diff --git a/cosiap_api/administracion/urls.py b/cosiap_api/administracion/urls.py index 60733c22221b2524ed7a203539049baa0e7d07af..cf8d81eca515b6fad9338cdc838277eb80e65f91 100644 --- a/cosiap_api/administracion/urls.py +++ b/cosiap_api/administracion/urls.py @@ -6,4 +6,5 @@ from django.contrib.auth import views as auth_views app_name = 'administracion' urlpatterns = [ path('convocatoria/', views.AbrirCerrarConvocatoria.as_view(), name='convocatoria'), + path('estilos/', views.ConfiguracionEstiloAPIView.as_view(), name='configuracion-default'), ] \ No newline at end of file diff --git a/cosiap_api/administracion/views.py b/cosiap_api/administracion/views.py index af693e003620bd17ef78cd619af13731315feafd..92d87567395de02e1834babf2db436edfec94b60 100644 --- a/cosiap_api/administracion/views.py +++ b/cosiap_api/administracion/views.py @@ -1,11 +1,12 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from common.views import BasePermissionAPIView from rest_framework.permissions import IsAuthenticated from users.permisos import es_admin from rest_framework import status -from .models import Convocatoria +from .models import Convocatoria, ConfiguracionColores from rest_framework.response import Response from notificaciones.mensajes import Mensaje +from .serializers import ConfiguracionEstiloSerializer class AbrirCerrarConvocatoria(BasePermissionAPIView): ''' @@ -58,8 +59,26 @@ class AbrirCerrarConvocatoria(BasePermissionAPIView): Mensaje.success(data, str(e)) return Response (data, status = status.HTTP_400_BAD_REQUEST) - - +class ConfiguracionEstiloAPIView(BasePermissionAPIView): + ''' + Clase para manjear la recuperación y edición de la configuración default + ''' - + permission_classes_list = [IsAuthenticated, es_admin] + permission_classes_update = [IsAuthenticated, es_admin] + + def get(self, request): + """Recupera la configuración por defecto (es_default=True).""" + configuracion = get_object_or_404(ConfiguracionColores, es_default=True) + serializer = ConfiguracionEstiloSerializer(configuracion) + return Response(serializer.data, status=status.HTTP_200_OK) + + def put(self, request): + """Edita la configuración por defecto (es_default=True).""" + configuracion = get_object_or_404(ConfiguracionColores, es_default=True) + serializer = ConfiguracionEstiloSerializer(configuracion, data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=status.HTTP_200_OK) + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file