-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distritos casi completo, falta conexión con CT
- Loading branch information
Showing
10 changed files
with
475 additions
and
0 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,15 @@ | ||
""" | ||
Distritos, formularios | ||
""" | ||
|
||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, SubmitField | ||
from wtforms.validators import DataRequired, Length | ||
|
||
|
||
class DistritoForm(FlaskForm): | ||
"""Formulario Distrito""" | ||
|
||
clave = StringField("Clave", validators=[DataRequired(), Length(max=16)]) | ||
nombre = StringField("Nombre", validators=[DataRequired(), Length(max=256)]) | ||
guardar = SubmitField("Guardar") |
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,37 @@ | ||
""" | ||
Distritos, modelos | ||
""" | ||
|
||
from typing import List | ||
|
||
from sqlalchemy import ForeignKey, String | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from lib.universal_mixin import UniversalMixin | ||
from orion.extensions import database | ||
|
||
|
||
class Distrito(database.Model, UniversalMixin): | ||
"""Distrito""" | ||
|
||
# Nombre de la tabla | ||
__tablename__ = "distritos" | ||
|
||
# Clave primaria | ||
id: Mapped[int] = mapped_column(primary_key=True) | ||
|
||
# Columnas | ||
clave: Mapped[str] = mapped_column(String(16), unique=True) | ||
nombre: Mapped[str] = mapped_column(String(256)) | ||
|
||
# Hijos | ||
# centros_trabajos = db.relationship("CentroTrabajo", back_populates="distrito") | ||
|
||
@property | ||
def nombre_descriptivo(self): | ||
"""Junta nombre del curso y su descripción""" | ||
return self.clave + ": " + self.nombre | ||
|
||
def __repr__(self): | ||
"""Representación""" | ||
return f"<Distrito {self.id}>" |
96 changes: 96 additions & 0 deletions
96
orion/blueprints/distritos/templates/distritos/detail.jinja2
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,96 @@ | ||
{% extends 'layouts/app.jinja2' %} | ||
{% import 'macros/detail.jinja2' as detail %} | ||
{% import 'macros/modals.jinja2' as modals %} | ||
{% import 'macros/topbar.jinja2' as topbar %} | ||
{% import 'macros/list.jinja2' as list %} | ||
|
||
{% block title %}Distrito {{ distrito.clave }}{% endblock %} | ||
|
||
{% block topbar_actions %} | ||
{% call topbar.page_buttons('Distrito ' + distrito.clave) %} | ||
{{ topbar.button_previous('Distritos', url_for('distritos.list_active')) }} | ||
{% if current_user.can_edit('DISTRITOS') %} | ||
{{ topbar.button_edit('Editar', url_for('distritos.edit', distrito_id=distrito.id)) }} | ||
{% endif %} | ||
{% if current_user.can_admin('DISTRITOS') %} | ||
{% if distrito.estatus == 'A' %}{{ topbar.button_delete('Eliminar', url_for('distritos.delete', distrito_id=distrito.id)) }}{% endif %} | ||
{% if distrito.estatus == 'B' %}{{ topbar.button_recover('Recuperar', url_for('distritos.recover', distrito_id=distrito.id)) }}{% endif %} | ||
{% endif %} | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% call detail.card(estatus=distrito.estatus) %} | ||
{{ detail.label_value_big('Clave', distrito.clave) }} | ||
{{ detail.label_value('Nombre', distrito.nombre) }} | ||
{% endcall %} | ||
<!-- card Centros de Trabajo --> | ||
{% call detail.card('Centros de Trabajos') %} | ||
{% endcall %} | ||
<!-- card Personas --> | ||
{% call detail.card('Personas') %} | ||
<p>TODO: FALTA: filtrar personas en este distrito</p> | ||
<!-- Filtros Personas --> | ||
<div class="row"> | ||
<div class="col"> | ||
<form class="row g-1 mb-3" id="filtradorForm" onsubmit="filtrosPersonas.buscar(); return false;"> | ||
<div class="col-6"> | ||
<div class="form-floating"> | ||
<input id="filtroNombreCompleto" type="text" class="form-control" aria-label="Nombre completo" style="text-transform: uppercase;"> | ||
<label for="filtroNombreCompleto">Nombre completo</label> | ||
</div> | ||
</div> | ||
<div class="col-6 text-end"> | ||
<button title="Buscar" class="btn btn-primary btn-lg" onclick="filtrosPersonas.buscar(); return false;" id="button-buscar"><span class="iconify" data-icon="mdi:magnify"></span></button> | ||
<button title="Limpiar" class="btn btn-warning btn-lg" type="reset" onclick="filtrosPersonas.limpiar();" id="button-limpiar"><span class="iconify" data-icon="mdi:broom"></span></button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
<!-- DataTable Personas --> | ||
<table id="personas_datatable" class="table display nowrap" style="width:100%"> | ||
<thead> | ||
<tr> | ||
<th>Nombre completo</th> | ||
<th>Sexo</th> | ||
<th>Situación</th> | ||
</tr> | ||
</thead> | ||
</table> | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block custom_javascript %} | ||
{% if current_user.can_admin('DISTRITOS') %} | ||
{% if distrito.estatus == 'A' %}{{ modals.custom_javascript_delete('Eliminar', '¿Eliminar a ' + distrito.clave + '?') }}{% endif %} | ||
{% if distrito.estatus == 'B' %}{{ modals.custom_javascript_recover('Recuperar', '¿Recuperar a ' + distrito.clave + '?') }}{% endif %} | ||
{% endif %} | ||
{{ detail.moment_js(moment) }} | ||
<script src="/static/js/datatables-constructor.js"></script> | ||
<script src="/static/js/datatables-filtros.js"></script> | ||
<script> | ||
// DataTable Personas | ||
const constructorDataTable = new ConfigDataTable( '{{ csrf_token() }}' ); | ||
let configDataTable = constructorDataTable.config(); | ||
configDataTable['ajax']['url'] = '/personas/datatable_json'; | ||
configDataTable['ajax']['data'] = {{ filtros_personas }}; | ||
configDataTable['columns'] = [ | ||
{ data: 'detalle' }, | ||
{ data: 'sexo' }, | ||
{ data: 'situacion' } | ||
]; | ||
configDataTable['columnDefs'] = [ | ||
{ | ||
targets: 0, // detalle | ||
data: null, | ||
render: function(data, type, row, meta) { | ||
return '<a href="' + data.url + '">' + data.nombre_completo + '</a>'; | ||
} | ||
} | ||
]; | ||
// Filtros Personas | ||
const filtrosPersonas = new FiltrosDataTable('#personas_datatable', configDataTable); | ||
filtrosPersonas.agregarInput('filtroNombreCompleto', 'nombre_completo'); | ||
filtrosPersonas.precargar(); | ||
</script> | ||
{% endblock %} |
22 changes: 22 additions & 0 deletions
22
orion/blueprints/distritos/templates/distritos/edit.jinja2
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,22 @@ | ||
{% extends 'layouts/app.jinja2' %} | ||
{% import 'macros/form.jinja2' as f with context %} | ||
{% import 'macros/topbar.jinja2' as topbar %} | ||
|
||
{% block title %}Editar Distrito {{ distrito.clave }}{% endblock %} | ||
|
||
{% block topbar_actions %} | ||
{% call topbar.page_buttons('Editar ' + distrito.clave) %} | ||
{{ topbar.button_cancel() }} | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% call f.card() %} | ||
{% set form_kwargs = {'distrito_id': distrito.id} %} | ||
{% call f.form_tag('distritos.edit', fid='distrito_form', **form_kwargs) %} | ||
{% call f.form_group(form.clave) %}{% endcall %} | ||
{% call f.form_group(form.nombre) %}{% endcall %} | ||
{% call f.form_group(form.guardar) %}{% endcall %} | ||
{% endcall %} | ||
{% endcall %} | ||
{% endblock %} |
84 changes: 84 additions & 0 deletions
84
orion/blueprints/distritos/templates/distritos/list.jinja2
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,84 @@ | ||
{% extends 'layouts/app.jinja2' %} | ||
{% import 'macros/list.jinja2' as list %} | ||
{% import 'macros/topbar.jinja2' as topbar %} | ||
|
||
{% block title %}{{ titulo }}{% endblock %} | ||
|
||
{% block topbar_actions %} | ||
{% call topbar.page_buttons(titulo) %} | ||
{% if current_user.can_admin('DISTRITOS') %} | ||
{% if estatus == 'A' %}{{ topbar.button_list_inactive('Inactivos', url_for('distritos.list_inactive')) }}{% endif %} | ||
{% if estatus == 'B' %}{{ topbar.button_list_active('Activos', url_for('distritos.list_active')) }}{% endif %} | ||
{% endif %} | ||
{% if current_user.can_insert('DISTRITOS') %} | ||
{{ topbar.button_new('Nuevo Distrito', url_for('distritos.new')) }} | ||
{% endif %} | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% call list.card() %} | ||
<!-- Filtros Distritos --> | ||
<div class="row"> | ||
<div class="col"> | ||
<form class="row g-1 mb-3" id="filtradorForm" onsubmit="filtrosDistritos.buscar(); return false;"> | ||
<div class="col-4"> | ||
<div class="form-floating"> | ||
<input id="filtroClave" type="text" class="form-control" aria-label="Clave" style="text-transform: uppercase;"> | ||
<label for="filtroClave">Clave</label> | ||
</div> | ||
</div> | ||
<div class="col-6"> | ||
<div class="form-floating"> | ||
<input id="filtroNombre" type="text" class="form-control" aria-label="Nombre" style="text-transform: uppercase;"> | ||
<label for="filtroNombre">Nombre</label> | ||
</div> | ||
</div> | ||
<div class="col-2 text-end"> | ||
<button title="Buscar" class="btn btn-primary btn-lg" onclick="filtrosDistritos.buscar(); return false;" id="button-buscar"><span class="iconify" data-icon="mdi:magnify"></span></button> | ||
<button title="Limpiar" class="btn btn-warning btn-lg" type="reset" onclick="filtrosDistritos.limpiar();" id="button-limpiar"><span class="iconify" data-icon="mdi:broom"></span></button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
<!-- DataTable Distritos --> | ||
<table id="distritos_datatable" class="table {% if estatus == 'B'%}table-dark{% endif %} display nowrap" style="width:100%"> | ||
<thead> | ||
<tr> | ||
<th>Clave</th> | ||
<th>Nombre</th> | ||
</tr> | ||
</thead> | ||
</table> | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block custom_javascript %} | ||
<script src="/static/js/datatables-constructor.js"></script> | ||
<script src="/static/js/datatables-filtros.js"></script> | ||
<script> | ||
// DataTable Distritos | ||
const constructorDataTable = new ConfigDataTable( '{{ csrf_token() }}' ); | ||
let configDataTable = constructorDataTable.config(); | ||
configDataTable['ajax']['url'] = '/distritos/datatable_json'; | ||
configDataTable['ajax']['data'] = {{ filtros }}; | ||
configDataTable['columns'] = [ | ||
{ data: 'detalle' }, | ||
{ data: 'nombre' } | ||
]; | ||
configDataTable['columnDefs'] = [ | ||
{ | ||
targets: 0, // detalle | ||
data: null, | ||
render: function(data, type, row, meta) { | ||
return '<a href="' + data.url + '">' + data.clave + '</a>'; | ||
} | ||
} | ||
]; | ||
// Filtros Distritos | ||
const filtrosDistritos = new FiltrosDataTable('#distritos_datatable', configDataTable); | ||
filtrosDistritos.agregarInput('filtroClave', 'clave'); | ||
filtrosDistritos.agregarInput('filtroNombre', 'nombre'); | ||
filtrosDistritos.precargar(); | ||
</script> | ||
{% endblock %} |
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 @@ | ||
{% extends 'layouts/app.jinja2' %} | ||
{% import 'macros/form.jinja2' as f with context %} | ||
{% import 'macros/topbar.jinja2' as topbar %} | ||
|
||
{% block title %}Nuevo Distrito{% endblock %} | ||
|
||
{% block topbar_actions %} | ||
{% call topbar.page_buttons('Nuevo Distrito') %} | ||
{{ topbar.button_cancel() }} | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% call f.card() %} | ||
{% call f.form_tag('distritos.new', fid='distritos_form') %} | ||
{% call f.form_group(form.clave) %}{% endcall %} | ||
{% call f.form_group(form.nombre) %}{% endcall %} | ||
{% call f.form_group(form.guardar) %}{% endcall %} | ||
{% endcall %} | ||
{% endcall %} | ||
{% endblock %} |
Oops, something went wrong.