Skip to content

Commit

Permalink
Merge pull request #80 from PenseNisso/feature/verificar_sugestoes
Browse files Browse the repository at this point in the history
Feature/verificar_sugestoes
  • Loading branch information
ra247362 authored Dec 13, 2023
2 parents 030a4eb + b09fb64 commit 295c7d2
Show file tree
Hide file tree
Showing 11 changed files with 400 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.5 on 2023-12-12 21:25

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


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('company', '0004_merge_0003_companysuggestionmodel_0003_rate'),
]

operations = [
migrations.AlterField(
model_name='rate',
name='company',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_ratings', to='company.company'),
),
migrations.AlterField(
model_name='rate',
name='score',
field=models.IntegerField(),
),
migrations.AlterField(
model_name='rate',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rated_companies', to=settings.AUTH_USER_MODEL),
),
]
18 changes: 18 additions & 0 deletions company/migrations/0006_companysuggestionmodel_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2023-12-12 23:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('company', '0005_alter_rate_company_alter_rate_score_alter_rate_user'),
]

operations = [
migrations.AddField(
model_name='companysuggestionmodel',
name='status',
field=models.CharField(choices=[('RE', 'Recusado'), ('NV', 'Não verificado'), ('AP', 'Aprovado')], default='NV', max_length=20),
),
]
11 changes: 8 additions & 3 deletions company/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def compute_score(self) -> float:
score = 5 - min(sub_score, 5)

return round(score, 2)

def compute_score_users(self) -> "float | str":
rates = self.user_ratings.all()
if len(rates) == 0:
Expand All @@ -32,7 +32,7 @@ def compute_score_users(self) -> "float | str":
sub_score_users = 0
for rate in rates:
sub_score_users += rate.score
score_users = round(sub_score_users/len(rates), 2)
score_users = round(sub_score_users / len(rates), 2)
return score_users

class Meta:
Expand All @@ -52,8 +52,13 @@ class CompanySuggestionModel(models.Model):
blank=True,
related_name="suggestions_sent",
)
status = models.CharField(
max_length=20,
choices=[("RE", "Recusado"), ("NV", "Não verificado"), ("AP", "Aprovado")],
default="NV",
)



class Rate(models.Model):
company = models.ForeignKey(
"company.Company", on_delete=models.CASCADE, related_name="user_ratings"
Expand Down
5 changes: 3 additions & 2 deletions user/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ def ready(self) -> None:
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType

from company.models import Company
from infos.models import Report

moderator_group, created = Group.objects.get_or_create(name="Moderator")
content_type = ContentType.objects.get_for_model(Report)
permissions = Permission.objects.filter(content_type=content_type)
content_types = ContentType.objects.get_for_models(Report, Company).values()
permissions = Permission.objects.filter(content_type__in=content_types)
for perm in permissions:
moderator_group.permissions.add(perm)
except OperationalError:
Expand Down
20 changes: 20 additions & 0 deletions user/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,23 @@ class ValidateReportForm(forms.Form):

class Meta:
fields = ("gravity", "action", "feedback")


class ValidateSuggestionForm(forms.Form):
action = forms.ChoiceField(
choices=(("1", "Aprovar"), ("0", "Recusar")),
label="Ação:",
widget=forms.RadioSelect,
)
name = forms.CharField(label="Nome da Empresa (se aprovada):", max_length=100)
description = forms.CharField(
label="Descrição da Empresa (se aprovada):",
widget=forms.Textarea(attrs={"cols": "45", "rows": "8"}),
)
logo = forms.ImageField(
label="Logo da Empresa (se aprovada):",
initial="company/logo_not_found.png",
)

class Meta:
fields = ("action", "name", "description", "logo")
25 changes: 25 additions & 0 deletions user/templates/company_validation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "global/base.html" %}
{% load info_extras %}
{% load crispy_forms_tags %}

{% block title %}
- Moderação
{% endblock %}

{% block content %}
<div class="w-full text-justify space-y-1 mt-4">
<h2 class="text-2xl font-bold">{{ object.name }}</h2>
<p><strong>Área de atuação: </strong>{{ object.field_of_operation }}</p>
<p><strong>Site da empresa: </strong>{{ object.link|urlize|url_fix }}</p>
<p><strong>Descrição: </strong>{{ object.description }}</p>
</div>

<div class="divider"></div>

<form enctype="multipart/form-data" method="post" class="flex flex-col mb-6">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Avaliar Sugestão"
class="bg-blue-700 bg-opacity-30 w-full py-1.5 px-3 font-semibold rounded-md cursor-pointer hover:scale-[1.035] mt-2">
</form>
{% endblock %}
42 changes: 24 additions & 18 deletions user/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ <h1 class="text-2xl font-bold">Perfil de Usuário</h1>

<div class="w-full md:w-60 flex flex-col space-y-6 justify-center md:justify-start mb-5">
<a href="{% url 'user:editprofile' request.user.id %}">
<button
class="bg-blue-700 bg-opacity-30 w-full py-1.5 px-3 font-semibold rounded-md cursor-pointer hover:scale-[1.035]
<button class="bg-blue-700 bg-opacity-30 w-full py-1.5 px-3 font-semibold rounded-md cursor-pointer hover:scale-[1.035]
flex flex-row items-center justify-center gap-1">
<ion-icon name="pencil"></ion-icon> Editar Perfil
</button>
</a>
<a href="{% url 'user:logout' %}">
<button
class="bg-red-700 bg-opacity-30 w-full py-1.5 px-3 font-semibold rounded-md cursor-pointer hover:scale-[1.035]
<button class="bg-red-700 bg-opacity-30 w-full py-1.5 px-3 font-semibold rounded-md cursor-pointer hover:scale-[1.035]
flex flex-row items-center justify-center gap-1">
<ion-icon name="log-out"></ion-icon> Sair da Conta
</button>
Expand All @@ -41,20 +39,28 @@ <h2 class="text-xl font-bold mb-1.5">Informações do Usuário</h2>
</ul>
</div>

{% if request.user|has_group:"Moderator" %}
<div>
<h2 class="text-xl font-bold mb-3">Área de Moderador</h2>
<ul>
<li>
<a href="{% url 'user:pendingreports' %}">
<button
class="bg-blue-700 bg-opacity-30 py-3 w-fit py-1.5 px-3 font-semibold rounded-md cursor-pointer hover:scale-[1.035]">
Denúncias Não Verificadas
</button>
</a>
</li>
</ul>
</div>
{% if request.user|has_group:"Moderator" %}
<div>
<h2 class="text-xl font-bold mb-3">Área de Moderador</h2>
<ul class="w-full flex flex-col max-xl:space-y-6 xl:flex-row xl:justify-between">
<li>
<a href="{% url 'user:pendingreports' %}">
<button
class="bg-blue-700 bg-opacity-30 py-3 w-fit py-1.5 px-3 font-semibold rounded-md cursor-pointer hover:scale-[1.035]">
Denúncias Não Verificadas
</button>
</a>
</li>
<li>
<a href="{% url 'user:pendingsuggestions' %}">
<button
class="bg-blue-700 bg-opacity-30 py-3 w-fit py-1.5 px-3 font-semibold rounded-md cursor-pointer hover:scale-[1.035]">
Sugestões de Empresas Não Verificadas
</button>
</a>
</li>
</ul>
</div>
{% endif %}

<div>
Expand Down
24 changes: 24 additions & 0 deletions user/templates/suggestion_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "global/base.html" %}

{% block title %}
- Moderação
{% endblock %}

{% block content %}
<!-- Page Title -->
<div class="bg-blue-600 text-white w-full text-center my-6 py-1.5">
<h1 class="text-2xl font-bold">Sugestões de Empresas Não Verificadas</h1>
</div>

<div class="w-11/12 space-y-5">
{% for suggestion in suggestion_list %}
<div class="bg-indigo-100 rounded-xl pt-2 pb-3 px-4 cursor-pointer hover:scale-[1.035]"
onclick="window.location.href='{% url 'user:suggestionvalidation' suggestion.id %}'">
<h2 class="text-lg font-bold">{{ suggestion.name }}</h2>
<div class="flex flex-row justify-between">
<p>{{ suggestion.field_of_operation }}</p>
</div>
</div>
{% endfor %}
</div>
{% endblock %}
Loading

0 comments on commit 295c7d2

Please sign in to comment.