Skip to content

Commit

Permalink
Carousel images almost in production
Browse files Browse the repository at this point in the history
  • Loading branch information
Heibert committed Sep 19, 2024
1 parent e109748 commit 05be574
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 280 deletions.
7 changes: 0 additions & 7 deletions INSIGHTSAPI/api_token/cookie_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,3 @@ def authenticate(self, request):
return None
validated_token = self.get_validated_token(raw_token)
return self.get_user(validated_token), validated_token


def always_true(user):
"""This function always return True"""
if user:
return True
return False
18 changes: 18 additions & 0 deletions INSIGHTSAPI/carousel_image/migrations/0002_banner_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-09-19 11:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('carousel_image', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='banner',
name='order',
field=models.IntegerField(default=0),
),
]
18 changes: 18 additions & 0 deletions INSIGHTSAPI/carousel_image/migrations/0003_alter_banner_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-09-19 12:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('carousel_image', '0002_banner_order'),
]

operations = [
migrations.AlterField(
model_name='banner',
name='order',
field=models.IntegerField(),
),
]
9 changes: 8 additions & 1 deletion INSIGHTSAPI/carousel_image/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@


class Banner(models.Model):
order = models.IntegerField()
title = models.CharField(max_length=100)
link = models.URLField(blank=True, null=True)
active = models.BooleanField(default=True)
image = models.ImageField(upload_to="carousel_images/banners/")
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.title

def save(self, *args, **kwargs):
if not self.pk: # only if the object is new
Banner.objects.filter(order__gte=self.order).update(
order=models.F("order") + 1
)
super().save(*args, **kwargs)
1 change: 1 addition & 0 deletions INSIGHTSAPI/carousel_image/serializer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from attr import fields
from rest_framework import serializers
from .models import Banner

Expand Down
42 changes: 33 additions & 9 deletions INSIGHTSAPI/carousel_image/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ def setUp(self):
self.banner = Banner.objects.create(
title="Test Banner",
link="https://www.google.com",
active=True,
image="carousel_images/banners/test.jpg",
order=1,
)
with open("static/test/Logo_cyc.png", "rb") as image_data:
self.image = SimpleUploadedFile(
"test3.jpg", image_data.read(), content_type="image/jpg"
)

def test_get_banner(self):
Banner.objects.create(
title="Test Banner 2",
link="https://www.google.com",
active=True,
image="carousel_images/banners/test2.jpg",
order=2,
)
response = self.client.get(reverse("banners-list"))
self.assertEqual(response.status_code, 200, response.data)
Expand All @@ -35,28 +39,48 @@ def test_get_only_active_banner(self):
link="https://www.google.com",
active=False,
image="carousel_images/banners/test2.jpg",
order=2,
)
response = self.client.get(reverse("banners-list"))
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(len(response.data), 1)

def test_create_banner(self):
with open("static/test/Logo_cyc.png", "rb") as image_data:
image = SimpleUploadedFile(
"test3.jpg", image_data.read(), content_type="image/jpg"
)
data = {
"title": "Test Banner 3",
"link": "https://www.google.com",
"active": True,
"image": image,
"image": self.image,
"order": 2,
}
print("Create")
response = self.client.post(reverse("banners-list"), data)
print("aqui",response.data.get("active"))
self.assertEqual(response.status_code, 201, response.data)
self.assertEqual(Banner.objects.count(), 2)
get_banners = self.client.get(reverse("banners-list"))
self.assertEqual(len(get_banners.data), 2)

def test_delete_banner(self):
response = self.client.delete(reverse("banners-detail", args=[self.banner.id]))
self.assertEqual(response.status_code, 204, response.data)
self.assertEqual(Banner.objects.count(), 1)
self.assertEqual(Banner.objects.filter(active=True).count(), 0)

def test_update_banner_order(self):
banner2 = Banner.objects.create(
title="Test Banner 2",
link="https://www.google.com",
image="carousel_images/banners/test2.jpg",
order=2,
)
response = self.client.post(
reverse("banners-list"),
{
"title": "Test Banner 3",
"link": "https://www.google.com",
"image": self.image,
"order": 2,
},
)
self.assertEqual(response.status_code, 201, response.data)
self.assertEqual(Banner.objects.count(), 3)
self.assertEqual(Banner.objects.get(id=banner2.id).order, 3)
10 changes: 10 additions & 0 deletions INSIGHTSAPI/carousel_image/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ class BannerViewSet(viewsets.ModelViewSet):
queryset = Banner.objects.filter(active=True)
serializer_class = BannerSerializer

def create(self, request, *args, **kwargs):
print("Create2")
print("request:", request.data)
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
print("serializer:", serializer.validated_data)
response = super().create(request, *args, **kwargs)
print(response.data)
return response

def destroy(self, request, *args, **kwargs):
instance = self.get_object()
instance.active = False
Expand Down
12 changes: 8 additions & 4 deletions INSIGHTSAPI/hierarchy/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
"""Customize the queryset for the manager field."""
if db_field.name == "manager":
# Customizing the queryset to show only users with a rank >= 4 or have the manage_area permission
kwargs["queryset"] = User.objects.filter(
Q(job_position__rank__gte=4)
| Q(user_permissions__codename="manage_area")
).order_by("first_name")
kwargs["queryset"] = (
User.objects.filter(
Q(job_position__rank__gte=4)
| Q(user_permissions__codename="manage_area")
)
.distinct()
.order_by("first_name")
)
return super().formfield_for_foreignkey(db_field, request, **kwargs)


Expand Down
197 changes: 99 additions & 98 deletions INSIGHTSAPI/hierarchy/db_upload.py
Original file line number Diff line number Diff line change
@@ -1,104 +1,105 @@
import django
# ! Need be deleted
# import django

django.setup()
# django.setup()

from django.db import connections
from hierarchy.models import JobPosition
from users.models import User
# from django.db import connections
# from hierarchy.models import JobPosition
# from users.models import User


positions = [
("PRESIDENTE", "8"),
("GERENTE GENERAL", "7"),
("GERENTE DE OPERACIONES", "6"),
("GERENTE DE PLANEACION", "6"),
("GERENTE COMERCIAL Y DE LICITACIONES", "6"),
("GERENTE DE RIESGO Y CONTROL INTERNO", "6"),
("GERENTE DE CONTROL INTERNO", "6"),
("GERENTE DE LEGAL Y DE RIESGO", "6"),
("GERENTE DE CUENTAS", "6"),
("GERENTE DE GESTION HUMANA", "6"),
("GERENTE DE MERCADEO", "6"),
("GERENTE DE CALIDAD", "6"),
("GERENTE DE TECNOLOGIA", "6"),
("GERENTE ADMINISTRATIVA", "6"),
("GERENTE JR INFRAESTRUCTURA Y REDES", "5"),
("GERENTE JR. DE APLICACIONES DE CONTACT CENTER", "5"),
("GERENTE JR. DE MESA DE SERVICIO", "5"),
("GERENTE DE CUENTAS JR", "5"),
("DIRECTOR(A) DE DESARROLLO", "4"),
("DIRECTOR(A) DE CALIDAD", "4"),
("DIRECTOR(A) DE PROYECTO", "4"),
("DIRECTOR(A) DE INVESTIGACIONES", "4"),
(
"DIRECTOR(A) DE SEGURIDAD Y SALUD EN EL TRABAJO, GESTION AMBIENTAL Y BIENESTAR INTEGRAL",
"4",
),
("DIRECTOR(A) DE NOMINA Y ADMINISTRACION DE PERSONAL", "4"),
("DIRECTOR(A) DE CONTROL INTERNO", "4"),
("DIRECTOR(A) JURIDICO", "4"),
("DIRECTOR(A) DE LICITACIONES", "4"),
("DIRECTOR(A) DE RECURSOS FISICOS", "4"),
("JEFE OPERACIONES OPERATIVO", "4"),
("COORDINADOR(A) DE PROYECTO", "3"),
("COORDINADOR DE COMUNICACIONES", "3"),
("COORDINADOR(A) DE FORMACION Y DESARROLLO DEL TALENTO", "3"),
("COORDINADOR(A) DE PLANEACION Y CALIDAD", "3"),
("COORDINADOR(A) BI", "3"),
("COORDINADOR CONTABLE", "3"),
("JEFE OPERACIONES PROCESOS", "3"),
("JEFE OPERACIONES JURIDICO", "3"),
("AUXILIAR OPERATIVO", "2"),
("DATA MARSHALL", "2"),
("FORMADOR", "2"),
("BACK OFFICE", "2"),
("ABOGADO(A) JUNIOR", "2"),
("AGENTE PROFESIONAL ABOGADO", "2"),
("TEAM LIDER", "2"),
("ANALISTA DE APLICACIONES DE CONTACT CENTER", "1"),
("ANALISTA DE SOPORTE", "1"),
("ANALISTA DE INFRAESTRUCTURA Y REDES", "1"),
("ANALISTA DE BD Y APLICACIONES", "1"),
("ANALISTA DE CALIDAD", "1"),
("ANALISTA DE SEGURIDAD Y SALUD EN EL TRABAJO Y MEDIO AMBIENTE", "1"),
("ANALISTA JURIDICO", "1"),
("ANALISTA DE INVESTIGACION", "1"),
("ANALISTA GESTION HUMANA", "1"),
("ANALISTA BI", "1"),
("ASESOR(A) COMERCIAL", "1"),
("ASESOR(A) DE SERVICIO AL CLIENTE", "1"),
("ASESOR(A) SENIOR", "1"),
("ASESOR(A) DE NEGOCIACION", "1"),
("INVESTIGADOR(A) DE CAMPO", "1"),
("GESTOR DE COBRANZA MOVIL Y EN SITIO", "1"),
("OPERADOR LOGISTICO", "1"),
("ASESOR(A) DE NEGOCIACION JR", "1"),
("AGENTE PROFESIONAL MINERO DE DATOS", "1"),
("AGENTE VIDEOLLAMADA Y LENGUAJE DE SEÑAS", "1"),
("AGENTE PROFESIONAL PSICOLOGA", "1"),
("AGENTE BILINGÜE TECNICO", "1"),
("AGENTE TECNICO", "1"),
("AUXILIAR ADMINISTRATIVO", "1"),
("AUXILIAR DE LICITACION", "1"),
("AUXILIAR CONTABLE", "1"),
("AUXILIAR DE CONTROL DE ACCESOS", "1"),
("AUXILIAR DE MANTENIMIENTO", "1"),
("SENA PRODUCTIVA", "1"),
("SENA LECTIVA", "1"),
("SERVICIOS GENERALES", "1"),
("SUPERVISOR(A) DE CALIDAD", "1"),
]
# positions = [
# ("PRESIDENTE", "8"),
# ("GERENTE GENERAL", "7"),
# ("GERENTE DE OPERACIONES", "6"),
# ("GERENTE DE PLANEACION", "6"),
# ("GERENTE COMERCIAL Y DE LICITACIONES", "6"),
# ("GERENTE DE RIESGO Y CONTROL INTERNO", "6"),
# ("GERENTE DE CONTROL INTERNO", "6"),
# ("GERENTE DE LEGAL Y DE RIESGO", "6"),
# ("GERENTE DE CUENTAS", "6"),
# ("GERENTE DE GESTION HUMANA", "6"),
# ("GERENTE DE MERCADEO", "6"),
# ("GERENTE DE CALIDAD", "6"),
# ("GERENTE DE TECNOLOGIA", "6"),
# ("GERENTE ADMINISTRATIVA", "6"),
# ("GERENTE JR INFRAESTRUCTURA Y REDES", "5"),
# ("GERENTE JR. DE APLICACIONES DE CONTACT CENTER", "5"),
# ("GERENTE JR. DE MESA DE SERVICIO", "5"),
# ("GERENTE DE CUENTAS JR", "5"),
# ("DIRECTOR(A) DE DESARROLLO", "4"),
# ("DIRECTOR(A) DE CALIDAD", "4"),
# ("DIRECTOR(A) DE PROYECTO", "4"),
# ("DIRECTOR(A) DE INVESTIGACIONES", "4"),
# (
# "DIRECTOR(A) DE SEGURIDAD Y SALUD EN EL TRABAJO, GESTION AMBIENTAL Y BIENESTAR INTEGRAL",
# "4",
# ),
# ("DIRECTOR(A) DE NOMINA Y ADMINISTRACION DE PERSONAL", "4"),
# ("DIRECTOR(A) DE CONTROL INTERNO", "4"),
# ("DIRECTOR(A) JURIDICO", "4"),
# ("DIRECTOR(A) DE LICITACIONES", "4"),
# ("DIRECTOR(A) DE RECURSOS FISICOS", "4"),
# ("JEFE OPERACIONES OPERATIVO", "4"),
# ("COORDINADOR(A) DE PROYECTO", "3"),
# ("COORDINADOR DE COMUNICACIONES", "3"),
# ("COORDINADOR(A) DE FORMACION Y DESARROLLO DEL TALENTO", "3"),
# ("COORDINADOR(A) DE PLANEACION Y CALIDAD", "3"),
# ("COORDINADOR(A) BI", "3"),
# ("COORDINADOR CONTABLE", "3"),
# ("JEFE OPERACIONES PROCESOS", "3"),
# ("JEFE OPERACIONES JURIDICO", "3"),
# ("AUXILIAR OPERATIVO", "2"),
# ("DATA MARSHALL", "2"),
# ("FORMADOR", "2"),
# ("BACK OFFICE", "2"),
# ("ABOGADO(A) JUNIOR", "2"),
# ("AGENTE PROFESIONAL ABOGADO", "2"),
# ("TEAM LIDER", "2"),
# ("ANALISTA DE APLICACIONES DE CONTACT CENTER", "1"),
# ("ANALISTA DE SOPORTE", "1"),
# ("ANALISTA DE INFRAESTRUCTURA Y REDES", "1"),
# ("ANALISTA DE BD Y APLICACIONES", "1"),
# ("ANALISTA DE CALIDAD", "1"),
# ("ANALISTA DE SEGURIDAD Y SALUD EN EL TRABAJO Y MEDIO AMBIENTE", "1"),
# ("ANALISTA JURIDICO", "1"),
# ("ANALISTA DE INVESTIGACION", "1"),
# ("ANALISTA GESTION HUMANA", "1"),
# ("ANALISTA BI", "1"),
# ("ASESOR(A) COMERCIAL", "1"),
# ("ASESOR(A) DE SERVICIO AL CLIENTE", "1"),
# ("ASESOR(A) SENIOR", "1"),
# ("ASESOR(A) DE NEGOCIACION", "1"),
# ("INVESTIGADOR(A) DE CAMPO", "1"),
# ("GESTOR DE COBRANZA MOVIL Y EN SITIO", "1"),
# ("OPERADOR LOGISTICO", "1"),
# ("ASESOR(A) DE NEGOCIACION JR", "1"),
# ("AGENTE PROFESIONAL MINERO DE DATOS", "1"),
# ("AGENTE VIDEOLLAMADA Y LENGUAJE DE SEÑAS", "1"),
# ("AGENTE PROFESIONAL PSICOLOGA", "1"),
# ("AGENTE BILINGÜE TECNICO", "1"),
# ("AGENTE TECNICO", "1"),
# ("AUXILIAR ADMINISTRATIVO", "1"),
# ("AUXILIAR DE LICITACION", "1"),
# ("AUXILIAR CONTABLE", "1"),
# ("AUXILIAR DE CONTROL DE ACCESOS", "1"),
# ("AUXILIAR DE MANTENIMIENTO", "1"),
# ("SENA PRODUCTIVA", "1"),
# ("SENA LECTIVA", "1"),
# ("SERVICIOS GENERALES", "1"),
# ("SUPERVISOR(A) DE CALIDAD", "1"),
# ]

for name, rank in positions:
JobPosition.objects.get_or_create(name=name, rank=rank)
# for name, rank in positions:
# JobPosition.objects.get_or_create(name=name, rank=rank)

with connections["staffnet"].cursor() as cursor:
cursor.execute("SELECT cargo, cedula FROM employment_information")
for cargo, cedula in cursor.fetchall():
try:
user = User.objects.get(cedula=cedula)
user.job_title = cargo
user.save()
except User.DoesNotExist:
print(f"User with cedula {cedula} not found")
continue
# with connections["staffnet"].cursor() as cursor:
# cursor.execute("SELECT cargo, cedula FROM employment_information")
# for cargo, cedula in cursor.fetchall():
# try:
# user = User.objects.get(cedula=cedula)
# user.job_title = cargo
# user.save()
# except User.DoesNotExist:
# print(f"User with cedula {cedula} not found")
# continue
Empty file.
Empty file.
Loading

0 comments on commit 05be574

Please sign in to comment.