Skip to content

Commit

Permalink
Merge pull request #9 from JeremiasMartin/darEstadoAEspacio
Browse files Browse the repository at this point in the history
Dar estado a espacio
  • Loading branch information
JeremiasMartin authored Oct 30, 2023
2 parents 1a341a1 + f4f1be1 commit 7be8eb5
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 19 deletions.
84 changes: 84 additions & 0 deletions Proyecto/espacios_obligados/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Generated by Django 4.2.5 on 2023-10-29 22:52

import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('usuarios', '__first__'),
]

operations = [
migrations.CreateModel(
name='DEA',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('aprobacion_ANMAT', models.BooleanField(default=False)),
('marca', models.CharField(max_length=200)),
('modelo', models.CharField(max_length=200)),
('numero_serie', models.CharField(max_length=200)),
('nombre_representativo', models.CharField(max_length=200)),
('estado', models.CharField(choices=[('activo', 'Activo'), ('inactivo', 'Inactivo')], default='activo', max_length=10)),
],
),
migrations.CreateModel(
name='Entidad',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('razon_social', models.CharField(max_length=200)),
('cuit', models.CharField(max_length=200)),
('sector', models.CharField(max_length=200)),
('tipo', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Sede',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nombre', models.CharField(max_length=200)),
('cant_personas_externas', models.IntegerField(default=0)),
('superficie', models.IntegerField(default=0)),
('ubicacion', django.contrib.gis.db.models.fields.PointField(srid=4326)),
('cant_personal', models.IntegerField(default=0)),
('direccion', models.CharField(max_length=200)),
('personal_capacitado', models.BooleanField(default=False)),
('senaletica', models.BooleanField(default=False)),
('protocolo_accion', models.BooleanField(default=False)),
('sistema_emergencia', models.BooleanField(default=False)),
('deas_decreto', models.IntegerField(default=0)),
('deas_registrados', models.ManyToManyField(blank=True, to='espacios_obligados.dea')),
('entidad', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='espacios_obligados.entidad')),
('provincia', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='usuarios.provincias')),
('representantes', models.ManyToManyField(to='usuarios.representante')),
],
),
migrations.CreateModel(
name='HistorialDEA',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('dia', models.DateField()),
('servicio', models.CharField(max_length=200)),
('observaciones', models.CharField(blank=True, max_length=200, null=True)),
('dea', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='espacios_obligados.dea')),
],
),
migrations.CreateModel(
name='EspacioObligado',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('estado', models.CharField(default='EN PROCESO', max_length=100)),
('motivo', models.TextField(blank=True, default='')),
('sede', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='espacios_obligados.sede')),
],
),
migrations.AddField(
model_name='dea',
name='dea_sede',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='espacios_obligados.sede'),
),
]
17 changes: 10 additions & 7 deletions Proyecto/espacios_obligados/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@ class Sede(models.Model):
ubicacion = gis_models.PointField()
cant_personal = models.IntegerField(default=0)
direccion = models.CharField(max_length=200)

# Declaración Jurada

personal_capacitado = models.BooleanField(default=False)
# Declaración Jurada
senaletica = models.BooleanField(default=False)
protocolo_accion = models.BooleanField(default=False)
sistema_emergencia = models.BooleanField(default=False)
deas_registrados = models.ManyToManyField('DEA', blank=True)
deas_decreto = models.IntegerField(default=0)


provincia = models.ForeignKey(Provincias, on_delete=models.CASCADE)
entidad = models.ForeignKey(Entidad, on_delete=models.CASCADE)

def __str__(self):
return self.nombre
return '%s , %s' % (self.nombre, self.provincia)


class EspacioObligado(models.Model):
estado = models.CharField(max_length=100,default='EN PROCESO') # Agregando el campo estado
sede = models.ForeignKey(Sede, on_delete=models.CASCADE)
motivo= models.TextField(blank=True,default='')
def __str__(self):
return f'!nombre sede {self.sede.nombre} y estado{self.estado}'

class DEA(models.Model):
dea_sede = models.ForeignKey(Sede, on_delete=models.CASCADE)
aprobacion_ANMAT = models.BooleanField(default=False)
Expand All @@ -61,4 +64,4 @@ class HistorialDEA(models.Model):
observaciones = models.CharField(max_length=200, blank=True, null=True)

def __str__(self):
return self.dea.nombre_representativo
return self.estado
74 changes: 74 additions & 0 deletions Proyecto/usuarios/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Generated by Django 4.2.5 on 2023-10-29 22:52

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Usuario',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('email', models.EmailField(blank=True, max_length=254, unique=True, verbose_name='Mail')),
('dni', models.PositiveIntegerField(default='', unique=True, verbose_name='DNI')),
('nombre', models.CharField(default='', max_length=20, verbose_name='Nombre')),
('apellido', models.CharField(default='', max_length=20, verbose_name='Apellido')),
('telefono', models.BigIntegerField(default='', verbose_name='Telefono')),
('is_active', models.BooleanField(default=True)),
('tipo_usuario', models.CharField(max_length=20, verbose_name='Tipo de Usuario')),
('is_staff', models.BooleanField(default=False)),
('is_admin', models.BooleanField(default=False)),
],
options={
'verbose_name': 'usuario',
'db_table': 'usuarios',
},
),
migrations.CreateModel(
name='Provincias',
fields=[
('provincia_id', models.AutoField(primary_key=True, serialize=False)),
('nombre', models.CharField(default='', max_length=30, verbose_name='Nombre')),
('validez_certificado', models.PositiveIntegerField(default='', verbose_name='Validez del Certificado')),
],
options={
'verbose_name': 'provincia',
'db_table': 'provincias',
},
),
migrations.CreateModel(
name='Representante',
fields=[
('representante_id', models.AutoField(primary_key=True, serialize=False)),
('fecha_registro', models.DateTimeField(auto_now_add=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'representante',
'db_table': 'representantes',
},
),
migrations.CreateModel(
name='AdminProvincial',
fields=[
('admin_provincial_id', models.AutoField(primary_key=True, serialize=False)),
('fecha_registro', models.DateTimeField(auto_now_add=True)),
('provincias', models.ManyToManyField(related_name='administradores_provinciales', to='usuarios.provincias')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'administrador provincial',
'db_table': 'administradores_provinciales',
},
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,46 @@
<body>
<h1>Bienvenido al Administrador Provincial</h1>
<!-- Agrega el contenido de la página aquí -->
<h2>Admin : {{admin}}</h2>
{% for proyecto in provincias_asociadas %}
<li>{{proyecto}}</li>
<h2>Admin : {{admin}}
<br> Provincias
</h2>
<h4>
{% for provincia in provincias %}
<li>{{provincia}}</li>
{% endfor %}
</h4>
<h2>Espacios nuevos a aprobar</h2>

{% for espacio in espacios %}
<li>
{{ espacio }}
<form action="{% url 'cambiar_estado_espacio' espacio.id %}" method="post" style="display:inline;">
{% csrf_token %}
<input type="hidden" name="action" value="aprobar">
<button type="submit">Aprobar</button>
</form>
<form action="{% url 'cambiar_estado_espacio' espacio.id %}" method="post" style="display:inline;">
{% csrf_token %}
<input type="hidden" name="action" value="rechazar">
<button type="button" onclick="showInputField(this)">Rechazar</button>
<div id="inputField" style="display:none;">
<input type="text" name="reason" placeholder="Escribe la razón aquí...">
<button type="submit">Enviar</button>
</div>
</form>
</li>

{% endfor %}
<h2>Espacios existentes a aprobar</h2>


<script>
function showInputField(button) {
var inputField = button.nextElementSibling;
inputField.style.display = "block";
}
</script>
</body>
</html>
{% endblock %}
{% endblock %}

1 change: 1 addition & 0 deletions Proyecto/usuarios/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
#-- paths para Admin provincial
path('inicioAdminProvincial/',views.inicioAdminProvincial,name='inicioAdminProvincial'),
path('registroAdminProvincial/', views.adminProvincial_signup, name='registroAdminProvincial'),
path('cambiar_estado_espacio/<int:sede_id>/', views.cambiar_estado_espacio, name='cambiar_estado_espacio'),
]
36 changes: 28 additions & 8 deletions Proyecto/usuarios/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect , get_object_or_404
from .forms import AdminProvincialForm, RepresentanteForm,CustomPasswordChangeForm
from .models import Usuario, Representante ,AdminProvincial,Provincias
from .models import Usuario, Representante ,AdminProvincial
from espacios_obligados.models import Sede,EspacioObligado
import random
from django.contrib.auth import authenticate, login, logout as django_logout
from django.contrib import messages
Expand Down Expand Up @@ -161,11 +162,6 @@ def restDone(request):

return render(request, 'usuario/cambio_de_clave/restablecer_contrasenia_enviado.html')

def inicioAdminProvincial(request):
administrador = AdminProvincial.objects.get(user=request.user)
provincias_asociadas = administrador.provincias.all()
return render(request, 'adminProvincial/inicioAdminProvincial.html',{'provincias_asociadas': provincias_asociadas,'admin':administrador})

def adminProvincial_signup(request):
if request.method == 'POST':
form = RepresentanteForm(request.POST)
Expand Down Expand Up @@ -217,4 +213,28 @@ def adminProvincial_signup(request):
return redirect('login')
else:
form = AdminProvincialForm()
return render(request, 'adminProvincial/formAdminProvincial.html', {'form': form})
return render(request, 'adminProvincial/formAdminProvincial.html', {'form': form})

def inicioAdminProvincial(request):

administrador = AdminProvincial.objects.get(user=request.user)
provincias_asociadas = administrador.provincias.all()
sedes_sin_espacio = Sede.objects.filter(espacioobligado__isnull=True).intersection(Sede.objects.filter(provincia__in = provincias_asociadas))
return render(request, 'adminProvincial/inicioAdminProvincial.html',{'admin':administrador,'provincias':provincias_asociadas,'espacios':sedes_sin_espacio})

def cambiar_estado_espacio(request,sede_id):
print(f'ID del Espacio: {sede_id}')
if request.method == 'POST':
sede = Sede.objects.get(id=sede_id)
espacio=EspacioObligado()
espacio.sede=Sede.objects.get(id=sede_id)
if request.POST.get('action') == 'aprobar':
espacio.estado= 'CARDIO ASISTIDO'

elif request.POST.get('action') == 'rechazar':
espacio.estado = 'EN PROCESO'
espacio.motivo = request.POST.get('reason')
print(espacio)
espacio.save()

return redirect('inicioAdminProvincial')

0 comments on commit 7be8eb5

Please sign in to comment.