-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marcos Mendez Quintero
committed
Jun 29, 2023
1 parent
8130064
commit 1a95502
Showing
11 changed files
with
150 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
from .models import Empresa, Competencia | ||
|
||
admin.site.register(Empresa) | ||
admin.site.register(Competencia) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
class DashboardConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "dashboard" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Generated by Django 4.2.2 on 2023-06-28 19:26 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Empresa", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("nombre", models.CharField(max_length=200)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="Competencia", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"competidor", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="competidor", | ||
to="dashboard.empresa", | ||
), | ||
), | ||
( | ||
"empresa", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="empresa", | ||
to="dashboard.empresa", | ||
), | ||
), | ||
], | ||
options={ | ||
"unique_together": {("empresa", "competidor")}, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.2.2 on 2023-06-28 20:01 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("dashboard", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="empresa", | ||
name="usuarios", | ||
field=models.ManyToManyField(to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
|
||
#This is the model for Companies that are going to be registered even thought they are not clients in the system | ||
class Empresa(models.Model): | ||
nombre = models.CharField(max_length=200) | ||
usuarios = models.ManyToManyField(User) | ||
|
||
def __str__(self): | ||
return self.nombre | ||
|
||
#This is the model for the competitors it is a relation of a Company to another. | ||
class Competencia(models.Model): | ||
empresa = models.ForeignKey(Empresa, related_name='empresa', on_delete=models.CASCADE) | ||
competidor = models.ForeignKey(Empresa, related_name='competidor', on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
unique_together = ('empresa', 'competidor') | ||
|
||
def __str__(self): | ||
return f"{self.empresa.nombre} competidor: {self.competidor.nombre}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.shortcuts import render, redirect | ||
from .models import Empresa | ||
from django.contrib.auth.models import User | ||
|
||
def asignar_usuarios(request, empresa_id): | ||
empresa = Empresa.objects.get(id=empresa_id) | ||
if request.method == 'POST': | ||
usuarios_id = request.POST.getlist('usuarios') | ||
usuarios = User.objects.filter(id__in=usuarios_id) | ||
empresa.usuarios.set(usuarios) | ||
|
||
# obtén la referencia al permiso de "view" para el modelo User | ||
permiso_ver_usuario = Permission.objects.get(codename='view_user') | ||
|
||
# para cada usuario de la empresa, agrega este permiso | ||
for usuario in empresa.usuarios.all(): | ||
usuario.user_permissions.add(permiso_ver_usuario) | ||
|
||
return redirect('dashboard:empresa_detalle', empresa_id=empresa_id) | ||
else: | ||
usuarios = User.objects.all() | ||
return render(request, 'asignar_usuarios.html', {'empresa': empresa, 'usuarios': usuarios}) | ||
|
||
def inicio(request): | ||
return render(request, 'inicio.html') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters