From d3883669f32c204d9301c626f7d9005c4802d1e9 Mon Sep 17 00:00:00 2001 From: Eberton Kociba Date: Sat, 23 May 2026 19:20:14 -0300 Subject: [PATCH] Entities BaseListView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Criado uma ListView base e utilizada como padrão para exibir os registros cadastrados --- multigranja/apps/core/templates/404.html | 1 + .../apps/core/templates/entity_home.html | 48 ---- .../apps/core/templates/includes/_navbar.html | 2 +- .../core/templates/includes/_sidebar.html | 24 +- .../core/templatetags/__init__.py} | 0 .../apps/core/templatetags/custom_tags.py | 22 ++ multigranja/apps/entities/services/animal.py | 75 +------ multigranja/apps/entities/services/farm.py | 86 ++------ .../entities/static/layout/entity_list.css | 208 ++++++++++++++++++ .../templates/_active_rotation_card.html | 6 + .../templates/animal/animal_home.html | 48 ---- .../entities/templates/batch/batch_home.html | 48 ---- .../apps/entities/templates/entity_list.html | 106 +++++++++ .../entities/templates/farm/farm_home.html | 2 +- .../templates/paddock/paddock_home.html | 85 ------- .../paddock_group/paddock_group_home.html | 76 ------- .../templates/rotation/rotation_home.html | 41 +++- multigranja/apps/entities/urls/animal.py | 9 +- multigranja/apps/entities/urls/farm.py | 11 +- multigranja/apps/entities/urls/rotation.py | 7 +- multigranja/apps/entities/views/__init__.py | 9 +- multigranja/apps/entities/views/animal.py | 20 +- multigranja/apps/entities/views/farm.py | 32 +-- .../apps/entities/views/list/animal.py | 23 ++ multigranja/apps/entities/views/list/base.py | 57 +++++ multigranja/apps/entities/views/list/batch.py | 35 +++ .../apps/entities/views/list/paddock.py | 24 ++ .../apps/entities/views/list/paddock_group.py | 35 +++ .../apps/entities/views/list/rotation.py | 28 +++ multigranja/apps/entities/views/rotation.py | 6 +- multigranja/static/css/layout/buttons.css | 2 +- 31 files changed, 661 insertions(+), 515 deletions(-) delete mode 100644 multigranja/apps/core/templates/entity_home.html rename multigranja/{static/css/layout/entity_home.css => apps/core/templatetags/__init__.py} (100%) create mode 100644 multigranja/apps/core/templatetags/custom_tags.py create mode 100644 multigranja/apps/entities/static/layout/entity_list.css create mode 100644 multigranja/apps/entities/templates/_active_rotation_card.html delete mode 100644 multigranja/apps/entities/templates/animal/animal_home.html delete mode 100644 multigranja/apps/entities/templates/batch/batch_home.html create mode 100644 multigranja/apps/entities/templates/entity_list.html delete mode 100644 multigranja/apps/entities/templates/paddock/paddock_home.html delete mode 100644 multigranja/apps/entities/templates/paddock_group/paddock_group_home.html create mode 100644 multigranja/apps/entities/views/list/animal.py create mode 100644 multigranja/apps/entities/views/list/base.py create mode 100644 multigranja/apps/entities/views/list/batch.py create mode 100644 multigranja/apps/entities/views/list/paddock.py create mode 100644 multigranja/apps/entities/views/list/paddock_group.py create mode 100644 multigranja/apps/entities/views/list/rotation.py diff --git a/multigranja/apps/core/templates/404.html b/multigranja/apps/core/templates/404.html index e69de29..19eacfb 100644 --- a/multigranja/apps/core/templates/404.html +++ b/multigranja/apps/core/templates/404.html @@ -0,0 +1 @@ +404 not found \ No newline at end of file diff --git a/multigranja/apps/core/templates/entity_home.html b/multigranja/apps/core/templates/entity_home.html deleted file mode 100644 index 8e6960f..0000000 --- a/multigranja/apps/core/templates/entity_home.html +++ /dev/null @@ -1,48 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block extra_css %} - -{% endblock %} - -{% block content %} -
-

{{entity_name}}

- - Novo -
- {% if not entities %} -

Nenhum registro encontrado.

- {% else %} - - - - - - - - - {% for entity in entities %} - - - - - - - - {% endfor %} -
IdentificadorIdadePesoEditarExcluir
{{ animal.identifier }}{{ animal.age }}{{ animal.weight }} Kg -
- {% csrf_token %} - -
-
- {% endif %} -{% endblock %} \ No newline at end of file diff --git a/multigranja/apps/core/templates/includes/_navbar.html b/multigranja/apps/core/templates/includes/_navbar.html index 5c740e1..e3a965f 100644 --- a/multigranja/apps/core/templates/includes/_navbar.html +++ b/multigranja/apps/core/templates/includes/_navbar.html @@ -10,7 +10,7 @@ - Novo - - {% if not animals %} -

Nenhum animal encontrado.

- {% else %} - - - - - - - - - {% for animal in animals %} - - - - - - - - {% endfor %} -
IdentificadorIdadePesoEditarExcluir
{{ animal.identifier }}{{ animal.age }}{{ animal.weight }} Kg -
- {% csrf_token %} - -
-
- {% endif %} -{% endblock %} \ No newline at end of file diff --git a/multigranja/apps/entities/templates/batch/batch_home.html b/multigranja/apps/entities/templates/batch/batch_home.html deleted file mode 100644 index f36b8ca..0000000 --- a/multigranja/apps/entities/templates/batch/batch_home.html +++ /dev/null @@ -1,48 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block extra_css %} - -{% endblock %} - -{% block content %} -
-

Lotes

- - Novo -
- {% if not batches %} -

Nenhum lote encontrado.

- {% else %} - - - - - - - - - {% for batch in batches %} - - - - - - - - {% endfor %} -
IdentificadorCategoria animalTipo de loteEditarExcluir
{{ batch.identifier }}{{ batch.animal_category }}{{ batch.batch_type }} Kg -
- {% csrf_token %} - -
-
- {% endif %} -{% endblock %} \ No newline at end of file diff --git a/multigranja/apps/entities/templates/entity_list.html b/multigranja/apps/entities/templates/entity_list.html new file mode 100644 index 0000000..860c291 --- /dev/null +++ b/multigranja/apps/entities/templates/entity_list.html @@ -0,0 +1,106 @@ +{% extends 'base.html' %} +{% load static %} +{% load custom_tags %} + +{% block extra_css %} + +{% endblock %} + +{% block content %} +

{{ title }}

+ + {% block before_table %} {% endblock %} + + + + {% if not object_list %} +

Nenhum registro encontrado.

+ {% else %} + {% block table %} + + + {% for col in columns %} + + {% endfor %} + + + + + {% for obj in object_list %} + + {% for col in columns %} + + {% endfor %} + + + + + + + + {% endfor %} +
{{ col.label }}EditarExcluir
+ {{ obj|get_attr:col.field }} + + + + + +
+ {% csrf_token %} + +
+
+ {% endblock %} + + + {% if is_paginated %} + + {% endif %} + {% endif %} + + {% block after_table %} {% endblock %} + +{% endblock %} \ No newline at end of file diff --git a/multigranja/apps/entities/templates/farm/farm_home.html b/multigranja/apps/entities/templates/farm/farm_home.html index 376fe09..6ad0e32 100644 --- a/multigranja/apps/entities/templates/farm/farm_home.html +++ b/multigranja/apps/entities/templates/farm/farm_home.html @@ -16,7 +16,7 @@ - Novo + Novo {% if not farms %}

Nenhuma fazenda encontrado.

diff --git a/multigranja/apps/entities/templates/paddock/paddock_home.html b/multigranja/apps/entities/templates/paddock/paddock_home.html deleted file mode 100644 index cbbcf94..0000000 --- a/multigranja/apps/entities/templates/paddock/paddock_home.html +++ /dev/null @@ -1,85 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block extra_css %} - -{% endblock %} - -{% block content %} -
-

Piquetes

- - - - - Novo - -
- - {% if not paddocks %} -

Nenhum piquete encontrado.

- {% else %} - - - - - - - - - - - - {% for paddock in paddocks %} - - - - - - - - - - - - {% endfor %} - -
NúmeroÁreaCapacidadeOcupadoBlocoEditarExcluir
{{ paddock.paddock_number }}{{ paddock.area }} ha{{ paddock.load_capacity }} - {% if paddock.occupied %} - Sim - {% else %} - Não - {% endif %} - - {% if paddock.paddock_group %} - {{ paddock.paddock_group.identifier }} - {% else %} - - - {% endif %} - - - - - -
- {% csrf_token %} - -
-
- {% endif %} -{% endblock %} \ No newline at end of file diff --git a/multigranja/apps/entities/templates/paddock_group/paddock_group_home.html b/multigranja/apps/entities/templates/paddock_group/paddock_group_home.html deleted file mode 100644 index 9a35fb1..0000000 --- a/multigranja/apps/entities/templates/paddock_group/paddock_group_home.html +++ /dev/null @@ -1,76 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block extra_css %} - -{% endblock %} - -{% block content %} -
-

Blocos

- - - - - Novo - -
- - {% if not paddock_groups %} -

Nenhum bloco encontrado.

- {% else %} - - - - - - - - - - {% for group in paddock_groups %} - - - - - - - - - - - {% endfor %} - -
IdentificadorDescriçãoPiquetesEditarExcluir
{{ group.identifier }}{{ group.description }} - {% for paddock in group.paddocks.all %} - {{ paddock.paddock_number }}{% if not forloop.last %}, {% endif %} - {% empty %} - - - {% endfor %} - - - - - -
- {% csrf_token %} - -
-
- {% endif %} -{% endblock %} \ No newline at end of file diff --git a/multigranja/apps/entities/templates/rotation/rotation_home.html b/multigranja/apps/entities/templates/rotation/rotation_home.html index 8044d70..cf5e5fc 100644 --- a/multigranja/apps/entities/templates/rotation/rotation_home.html +++ b/multigranja/apps/entities/templates/rotation/rotation_home.html @@ -1,10 +1,37 @@ -{% extends 'base.html' %} -{% load static %} +{% extends 'entity_list.html' %} +{% load custom_tags %} -{% block extra_css %} - +{% block before_table %} +

Essas informações aparecem antes da tabela apenas para a tela de movimentações

{% endblock %} -{% block content %} - Home - Rotation -{% endblock %} \ No newline at end of file +{% block table %} + + + {% for col in columns %} + + {% endfor %} + + + + {% for obj in object_list %} + + {% for col in columns %} + + {% endfor %} + + + + + {% endfor %} +
{{ col.label }}Excluir
+ {{ obj|get_attr:col.field }} + +
+ {% csrf_token %} + +
+
+ {% endblock %} \ No newline at end of file diff --git a/multigranja/apps/entities/urls/animal.py b/multigranja/apps/entities/urls/animal.py index 11ba6a6..75be8ed 100644 --- a/multigranja/apps/entities/urls/animal.py +++ b/multigranja/apps/entities/urls/animal.py @@ -1,17 +1,18 @@ from django.urls import path from ..views import animal as views +from ..views import AnimalListView, BatchListView app_name = 'animal' urlpatterns = [ - path('', views.animal_home, name='animal_home'), - path('batch/', views.batch_home, name='batch_home'), + path('list/', AnimalListView.as_view(), name='animal_list'), + path('batch/list/', BatchListView.as_view(), name='batch_list'), - path('new/', views.animal_new, name='animal_new'), + path('new/', views.animal_new, name='animal_create'), path('update/', views.animal_update, name='animal_update'), path('delete/', views.animal_delete, name='animal_delete'), - path('batch/new/', views.batch_new, name='batch_new'), + path('batch/new/', views.batch_new, name='batch_create'), path('batch/update/', views.batch_update, name='batch_update'), path('batch/delete/', views.batch_delete, name='batch_delete'), ] \ No newline at end of file diff --git a/multigranja/apps/entities/urls/farm.py b/multigranja/apps/entities/urls/farm.py index d85df9b..171776f 100644 --- a/multigranja/apps/entities/urls/farm.py +++ b/multigranja/apps/entities/urls/farm.py @@ -1,22 +1,23 @@ from django.urls import path from ..views import farm as views +from ..views import PaddockListView, PaddockGroupListView app_name = 'farm' urlpatterns = [ path('', views.farm_home, name='farm_home'), - path('paddock/', views.paddock_home, name='paddock_home'), - path("paddock/group/", views.paddock_group_home, name="paddock_group_home"), + path('paddock/list/', PaddockListView.as_view(), name='paddock_list'), + path('paddock/group/list/', PaddockGroupListView.as_view(), name='paddock_group_list'), - path('new/', views.farm_new, name='farm_new'), + path('new/', views.farm_new, name='farm_create'), path('update/', views.farm_update, name='farm_update'), path('delete/', views.farm_delete, name='farm_delete'), - path('paddock/new/', views.paddock_new, name='paddock_new'), + path('paddock/new/', views.paddock_new, name='paddock_create'), path('paddock/update/', views.paddock_update, name='paddock_update'), path('paddock/delete/', views.paddock_delete, name='paddock_delete'), - path('paddock_group/new/', views.paddock_group_new, name='paddock_group_new'), + path('paddock_group/new/', views.paddock_group_new, name='paddock_group_create'), path('paddock_group/update/', views.paddock_group_update, name='paddock_group_update'), path('paddock_group/delete/', views.paddock_group_delete, name='paddock_group_delete'), ] \ No newline at end of file diff --git a/multigranja/apps/entities/urls/rotation.py b/multigranja/apps/entities/urls/rotation.py index f676530..4a64065 100644 --- a/multigranja/apps/entities/urls/rotation.py +++ b/multigranja/apps/entities/urls/rotation.py @@ -1,14 +1,13 @@ from django.urls import path -from django.http import HttpResponse -from django.contrib.auth.decorators import login_required +from ..views import RotationListView from ..views import rotation as views app_name = 'rotation' urlpatterns = [ - path('', views.rotation_home, name='rotation_home'), + path('', RotationListView.as_view(), name='rotation_home'), - path('new/', views.rotation_new, name='rotation_new'), + path('new/', views.rotation_create, name='rotation_create'), path('delete/', views.rotation_delete, name='rotation_delete'), ] \ No newline at end of file diff --git a/multigranja/apps/entities/views/__init__.py b/multigranja/apps/entities/views/__init__.py index 9f69dcb..f786ef8 100644 --- a/multigranja/apps/entities/views/__init__.py +++ b/multigranja/apps/entities/views/__init__.py @@ -1,3 +1,10 @@ from .animal import * from .farm import * -from .rotation import * \ No newline at end of file +from .rotation import * + +from .list.base import BaseListView +from .list.animal import AnimalListView +from .list.batch import BatchListView +from .list.paddock import PaddockListView +from .list.paddock_group import PaddockGroupListView +from .list.rotation import RotationListView \ No newline at end of file diff --git a/multigranja/apps/entities/views/animal.py b/multigranja/apps/entities/views/animal.py index bc01734..02ad90a 100644 --- a/multigranja/apps/entities/views/animal.py +++ b/multigranja/apps/entities/views/animal.py @@ -5,12 +5,6 @@ from core.decorators import farm_required from ..services import animal as services # Animal Views -@farm_required -def animal_home(request): - context = services.get_animal_home_context(request) - return render(request, 'animal/animal_home.html', context) - - @farm_required def animal_new(request): if request.method == 'GET': @@ -20,9 +14,9 @@ def animal_new(request): elif request.method == 'POST': success = services.create_animal(request) if success: - return redirect('entities:animal:animal_home') + return redirect('entities:animal:animal_list') - return redirect('entities:animal:animal_new') + return redirect('entities:animal:animal_create') @farm_required @@ -39,16 +33,10 @@ def animal_update(request, animal_id): @require_http_methods(["POST"]) def animal_delete(request, animal_id): services.delete_animal(request, animal_id) - return redirect('entities:animal:animal_home') + return redirect('entities:animal:animal_list') # Batch Views -@farm_required -def batch_home(request): - context = services.get_batch_home_context(request) - return render(request, 'batch/batch_home.html', context) - - @farm_required def batch_new(request): result = services.create_batch(request) @@ -73,4 +61,4 @@ def batch_update(request, batch_id): @require_http_methods(["POST"]) def batch_delete(request, batch_id): services.delete_batch(batch_id) - return redirect('entities:animal:batch_home') \ No newline at end of file + return redirect('entities:animal:batch_list') \ No newline at end of file diff --git a/multigranja/apps/entities/views/farm.py b/multigranja/apps/entities/views/farm.py index e70a65c..f284286 100644 --- a/multigranja/apps/entities/views/farm.py +++ b/multigranja/apps/entities/views/farm.py @@ -19,9 +19,9 @@ def farm_new(request): elif request.method == 'POST': success = services.create_farm(request) if success: - return redirect('entities:farm:farm_home') + return redirect('entities:farm:farm_list') - return redirect('entities:farm:farm_new') + return redirect('entities:farm:farm_create') @@ -39,17 +39,10 @@ def farm_update(request, farm_id): @require_http_methods(["POST"]) def farm_delete(request, farm_id): services.delete_farm(request, farm_id) - return redirect('entities:farm:farm_home') + return redirect('entities:farm:farm_create') # Paddock Views -@farm_required -def paddock_home(request): - context = {} - context['title'] = 'Piquete' - return render(request, 'paddock/paddock_home.html', context) - - @farm_required def paddock_new(request): if request.method == 'GET': @@ -59,9 +52,9 @@ def paddock_new(request): elif request.method == 'POST': success = services.create_paddock(request) if success: - return redirect('entities:farm:paddock_home') + return redirect('entities:farm:paddock_list') - return redirect('entities:farm:paddock_new') + return redirect('entities:farm:paddock_create') @@ -79,17 +72,10 @@ def paddock_update(request, paddock_id): @require_http_methods(["POST"]) def paddock_delete(request, paddock_id): services.delete_paddock(request, paddock_id) - return redirect('entities:farm:paddock_home') + return redirect('entities:farm:paddock_list') # Paddock Group Views -@farm_required -def paddock_group_home(request): - context = {} - context['title'] = 'Bloco' - return render(request, 'paddock_group/paddock_group_home.html', context) - - @farm_required def paddock_group_new(request): if request.method == 'GET': @@ -99,9 +85,9 @@ def paddock_group_new(request): elif request.method == 'POST': success = services.create_paddock_group(request) if success: - return redirect('entities:farm:paddock_group_home') + return redirect('entities:farm:paddock_group_list') - return redirect('entities:farm:paddock_group_new') + return redirect('entities:farm:paddock_group_create') @@ -119,4 +105,4 @@ def paddock_group_update(request, paddock_group_id): @require_http_methods(["POST"]) def paddock_group_delete(request, paddock_group_id): services.delete_paddock_group(request, paddock_group_id) - return redirect('entities:farm:paddock_group_home') \ No newline at end of file + return redirect('entities:farm:paddock_group_list') \ No newline at end of file diff --git a/multigranja/apps/entities/views/list/animal.py b/multigranja/apps/entities/views/list/animal.py new file mode 100644 index 0000000..dac2d8d --- /dev/null +++ b/multigranja/apps/entities/views/list/animal.py @@ -0,0 +1,23 @@ +from .base import BaseListView +from entities.models.animal import Animal + +class AnimalListView(BaseListView): + model = Animal + + title = "Animais" + + columns = [ + {"field": "identifier", "label": "Identificador"}, + {"field": "age", "label": "Idade"}, + {"field": "weight", "label": "Peso"}, + ] + + create_url = "entities:animal:animal_create" + edit_url = "entities:animal:animal_update" + delete_url = "entities:animal:animal_delete" + list_url = "entities:animal:animal_list" + + filter_fields = ["identifier"] + + def get_queryset(self): + return super().get_queryset().filter(is_active=True, farm=self.selected_farm) \ No newline at end of file diff --git a/multigranja/apps/entities/views/list/base.py b/multigranja/apps/entities/views/list/base.py new file mode 100644 index 0000000..e163dd6 --- /dev/null +++ b/multigranja/apps/entities/views/list/base.py @@ -0,0 +1,57 @@ +from django.views.generic import ListView +from django.db.models import Q +from entities.models.farm import Farm + +class BaseListView(ListView): + template_name = "entity_list.html" + paginate_by = 10 + selected_farm = "" + order_by = ["id"] + + # Specific configurations for each entity + title = "" + columns = [] + + create_url = "" + edit_url = "" + delete_url = "" + list_url = "" + + filter_fields = [] # ex: ["identifier", "name"] + + # Acts like a init function - provides the select_farm Farm object to all dependent views + def dispatch(self, request, *args, **kwargs): + farm_id = self.request.session.get('selected_farm_id') + self.selected_farm = Farm.objects.filter(id=farm_id).first() + return super().dispatch(request, *args, **kwargs) + + # Filter + def get_queryset(self): + queryset = super().get_queryset() + query = self.request.GET.get("q") + + if query and self.filter_fields: + q_objects = Q() + + for field in self.filter_fields: + q_objects |= Q(**{f"{field}__icontains": query}) + + queryset = queryset.filter(q_objects) + + return queryset.order_by(*self.order_by) + + # Context + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + context.update({ + "title": self.title, + "columns": self.columns, + "create_url": self.create_url, + "edit_url": self.edit_url, + "delete_url": self.delete_url, + "list_url": self.list_url, + "query": self.request.GET.get("q", ""), + }) + + return context \ No newline at end of file diff --git a/multigranja/apps/entities/views/list/batch.py b/multigranja/apps/entities/views/list/batch.py new file mode 100644 index 0000000..6e65dc7 --- /dev/null +++ b/multigranja/apps/entities/views/list/batch.py @@ -0,0 +1,35 @@ +from .base import BaseListView +from django.db.models import Prefetch +from entities.models.animal import Batch, Animal + +class BatchListView(BaseListView): + model = Batch + + title = "Lotes" + + columns = [ + {"field": "identifier", "label": "Identificador"}, + {"field": "animal_cathgory", "label": "Categoria"}, + {"field": "batch_type", "label": "Tipo"}, + ] + + create_url = "entities:animal:batch_create" + edit_url = "entities:animal:batch_update" + delete_url = "entities:animal:batch_delete" + list_url = "entities:animal:batch_list" + + filter_fields = ["identifier"] + + def get_queryset(self): + queryset = Batch.objects.filter( + batchanimal__animal__farm=self.selected_farm, + is_active=True + ).distinct().prefetch_related( + Prefetch('animals', queryset=Animal.objects.filter(is_active=True)) + ) + + query = self.request.GET.get("q") + if query: + queryset = queryset.filter(identifier__icontains=query) + + return queryset \ No newline at end of file diff --git a/multigranja/apps/entities/views/list/paddock.py b/multigranja/apps/entities/views/list/paddock.py new file mode 100644 index 0000000..98e545f --- /dev/null +++ b/multigranja/apps/entities/views/list/paddock.py @@ -0,0 +1,24 @@ +from .base import BaseListView +from entities.models.farm import Paddock + +class PaddockListView(BaseListView): + model = Paddock + + title = "Piquetes" + + columns = [ + {"field": "paddock_number", "label": "Número"}, + {"field": "area", "label": "Área"}, + {"field": "load_capacity", "label": "Capacidade"}, + {"field": "occupied", "label": "Ocupado"}, + ] + + create_url = "entities:farm:paddock_group_create" + edit_url = "entities:farm:paddock_group_update" + delete_url = "entities:farm:paddock_group_delete" + list_url = "entities:farm:paddock_group_list" + + filter_fields = ["paddock_number"] + + def get_queryset(self): + return super().get_queryset().filter(is_active=True, farm=self.selected_farm) \ No newline at end of file diff --git a/multigranja/apps/entities/views/list/paddock_group.py b/multigranja/apps/entities/views/list/paddock_group.py new file mode 100644 index 0000000..ad93d6f --- /dev/null +++ b/multigranja/apps/entities/views/list/paddock_group.py @@ -0,0 +1,35 @@ +from .base import BaseListView +from django.db.models import Prefetch +from entities.models.farm import PaddockGroup, Paddock + +class PaddockGroupListView(BaseListView): + model = PaddockGroup + + title = "Blocos" + + columns = [ + {"field": "identifier", "label": "Identificador"}, + {"field": "description", "label": "Descrição"}, + ] + + create_url = "entities:farm:paddock_group_create" + edit_url = "entities:farm:paddock_group_update" + delete_url = "entities:farm:paddock_group_delete" + list_url = "entities:farm:paddock_group_list" + + filter_fields = ["identifier"] + + def get_queryset(self): + + queryset = PaddockGroup.objects.filter( + paddocks__farm=self.selected_farm, + is_active=True + ).distinct().prefetch_related( + Prefetch('paddocks', queryset=Paddock.objects.filter(is_active=True)) + ) + + query = self.request.GET.get("q") + if query: + queryset = queryset.filter(identifier__icontains=query) + + return queryset \ No newline at end of file diff --git a/multigranja/apps/entities/views/list/rotation.py b/multigranja/apps/entities/views/list/rotation.py new file mode 100644 index 0000000..95e17b3 --- /dev/null +++ b/multigranja/apps/entities/views/list/rotation.py @@ -0,0 +1,28 @@ +from .base import BaseListView +from entities.models.rotation import Rotation + +class RotationListView(BaseListView): + model = Rotation + + template_name = "rotation/rotation_home.html" + + title = "Movimentações" + + columns = [ + #{"field": "id", "label": "ID"}, + {"field": "batch", "label": "Lote"}, + {"field": "paddock", "label": "Piquete"}, + {"field": "entry_date", "label": "Entrada"}, + {"field": "exit_date", "label": "Saída"}, + {"field": "animal_count", "label": "Animais"}, + {"field": "livestock_unit", "label": "UGM"}, + ] + + create_url = "entities:rotation:rotation_create" + delete_url = "entities:rotation:rotation_delete" + list_url = "entities:rotation:rotation_home" + + filter_fields = ["id", "batch", "paddock"] + + def get_queryset(self): + return super().get_queryset().filter(is_active=True, paddock__farm=self.selected_farm) \ No newline at end of file diff --git a/multigranja/apps/entities/views/rotation.py b/multigranja/apps/entities/views/rotation.py index 2cca8b7..9737840 100644 --- a/multigranja/apps/entities/views/rotation.py +++ b/multigranja/apps/entities/views/rotation.py @@ -1,10 +1,14 @@ from django.shortcuts import render +from core.decorators import farm_required +@farm_required def rotation_home(request): return render(request, 'rotation/rotation_home.html') -def rotation_new(request): +@farm_required +def rotation_create(request): return render(request, 'rotation/rotation_new.html') +@farm_required def rotation_delete(request): return render(request, 'rotation/rotation_delete.html') \ No newline at end of file diff --git a/multigranja/static/css/layout/buttons.css b/multigranja/static/css/layout/buttons.css index 9cda81b..5c6aab4 100644 --- a/multigranja/static/css/layout/buttons.css +++ b/multigranja/static/css/layout/buttons.css @@ -48,7 +48,7 @@ /* HOVER EFFECTS */ .highlight-hover:hover { - background-color: rgba(255, 255, 255, 0.15); + background-color: rgba(255, 255, 255, 0.1); backdrop-filter: blur(8px); transition: all var(--transition-speed) ease; } \ No newline at end of file