Martín Miranda

Inicia proyecto

  1 +celerybeat-schedule
  2 +
  3 +*.log
  4 +
  5 +*.py[codt]
  6 +
  7 +# C extensions
  8 +*.so
  9 +
  10 +# Packages
  11 +*.egg
  12 +*.egg-info
  13 +dist
  14 +build
  15 +eggs
  16 +parts
  17 +bin
  18 +var
  19 +sdist
  20 +develop-eggs
  21 +.installed.cfg
  22 +lib
  23 +lib64
  24 +logs
  25 +
  26 +# Installer logs
  27 +pip-log.txt
  28 +
  29 +# Unit test / coverage reports
  30 +.coverage
  31 +.tox
  32 +nosetests.xml
  33 +coverage.xml
  34 +junit.xml
  35 +
  36 +# Translations
  37 +*.mo
  38 +
  39 +# Mr Developer
  40 +.mr.developer.cfg
  41 +.project
  42 +.pydevproject
  43 +
  44 +# Complexity
  45 +output/*.html
  46 +output/*/index.html
  47 +
  48 +# Sphinx
  49 +docs/_build
  50 +
  51 +.webassets-cache
  52 +
  53 +# Virtualenvs
  54 +venv
  55 +
  56 +# intellij
  57 +*.ipr
  58 +*.iml
  59 +*.iws
  60 +
  61 +# vim
  62 +*.sw[o,p]
  63 +
  64 +.DS_Store
  65 +
  66 +# node
  67 +node_modules/
  68 +
  69 +# bower packages
  70 +.sass-cache/
  71 +.idea/.name
  72 +.idea/scopes/scope_settings.xml
  73 +.idea/encodings.xml
  74 +.idea/workspace.xml
  75 +
  76 +# models
  77 +models.png
  78 +
  79 +.idea/*
  80 +
  81 +*.db
  82 +
  83 +secret.key
  84 +
  85 +.bash_history
  86 +.vagrant/*
  87 +
  88 +# Sublime Text 3
  89 +*.sublime-project
  90 +*.sublime-workspace
  91 +
  92 +# ?
  93 +.cache
  94 +src
  95 +
  96 +# Configuration
  97 +.env
  98 +
  99 +# Virtual Environment
  100 +.venv
  101 +tmp
  102 +Procfile.dev
  103 +
  104 +# Cython .C files (precompilation)
  105 +*.c
  106 +
  107 +__pycache__/
  108 +
  109 +# Logs nginx
  110 +deployment/logs/
  111 +deployment/circus.ini
  112 +deployment/nginx.conf
  113 +
  114 +.pytest_cache/
  115 +
  116 +project/settings/production.py
  117 +project/static/*
  118 +project/media/*
  119 +
  120 +
  121 +# Tests
  122 +project/test_:memory:
  123 +test_:memory:
  124 +
  125 +# Directorio de backups
  126 +database_backups
  127 +project/test_media/
  128 +
  129 +
  130 +# Redis dump
  131 +dump.rdb
  132 +db.sqlite3
  1 +"""
  2 +ASGI config for capacitacion project.
  3 +
  4 +It exposes the ASGI callable as a module-level variable named ``application``.
  5 +
  6 +For more information on this file, see
  7 +https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
  8 +"""
  9 +
  10 +import os
  11 +
  12 +from django.core.asgi import get_asgi_application
  13 +
  14 +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'capacitacion.settings')
  15 +
  16 +application = get_asgi_application()
  1 +"""
  2 +Django settings for capacitacion project.
  3 +
  4 +Generated by 'django-admin startproject' using Django 3.2.7.
  5 +
  6 +For more information on this file, see
  7 +https://docs.djangoproject.com/en/3.2/topics/settings/
  8 +
  9 +For the full list of settings and their values, see
  10 +https://docs.djangoproject.com/en/3.2/ref/settings/
  11 +"""
  12 +
  13 +from pathlib import Path
  14 +
  15 +# Build paths inside the project like this: BASE_DIR / 'subdir'.
  16 +BASE_DIR = Path(__file__).resolve().parent.parent
  17 +
  18 +
  19 +# Quick-start development settings - unsuitable for production
  20 +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
  21 +
  22 +# SECURITY WARNING: keep the secret key used in production secret!
  23 +SECRET_KEY = 'django-insecure-6)zkbdelud_+qz14g$q!56o62(+-k!*kgwdygn+)ku4paq(#+w'
  24 +
  25 +# SECURITY WARNING: don't run with debug turned on in production!
  26 +DEBUG = True
  27 +
  28 +ALLOWED_HOSTS = []
  29 +
  30 +
  31 +# Application definition
  32 +
  33 +INSTALLED_APPS = [
  34 + 'django.contrib.admin',
  35 + 'django.contrib.auth',
  36 + 'django.contrib.contenttypes',
  37 + 'django.contrib.sessions',
  38 + 'django.contrib.messages',
  39 + 'django.contrib.staticfiles',
  40 + 'persona',
  41 + 'organismo',
  42 + 'core',
  43 +]
  44 +
  45 +MIDDLEWARE = [
  46 + 'django.middleware.security.SecurityMiddleware',
  47 + 'django.contrib.sessions.middleware.SessionMiddleware',
  48 + 'django.middleware.common.CommonMiddleware',
  49 + 'django.middleware.csrf.CsrfViewMiddleware',
  50 + 'django.contrib.auth.middleware.AuthenticationMiddleware',
  51 + 'django.contrib.messages.middleware.MessageMiddleware',
  52 + 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  53 +]
  54 +
  55 +ROOT_URLCONF = 'capacitacion.urls'
  56 +
  57 +TEMPLATES = [
  58 + {
  59 + 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  60 + 'DIRS': [],
  61 + 'APP_DIRS': True,
  62 + 'OPTIONS': {
  63 + 'context_processors': [
  64 + 'django.template.context_processors.debug',
  65 + 'django.template.context_processors.request',
  66 + 'django.contrib.auth.context_processors.auth',
  67 + 'django.contrib.messages.context_processors.messages',
  68 + ],
  69 + },
  70 + },
  71 +]
  72 +
  73 +WSGI_APPLICATION = 'capacitacion.wsgi.application'
  74 +
  75 +
  76 +# Database
  77 +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
  78 +
  79 +DATABASES = {
  80 + 'default': {
  81 + 'ENGINE': 'django.db.backends.sqlite3',
  82 + 'NAME': BASE_DIR / 'db.sqlite3',
  83 + }
  84 +}
  85 +
  86 +
  87 +# Password validation
  88 +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
  89 +
  90 +AUTH_PASSWORD_VALIDATORS = [
  91 + {
  92 + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  93 + },
  94 + {
  95 + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  96 + },
  97 + {
  98 + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  99 + },
  100 + {
  101 + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  102 + },
  103 +]
  104 +
  105 +
  106 +# Internationalization
  107 +# https://docs.djangoproject.com/en/3.2/topics/i18n/
  108 +
  109 +LANGUAGE_CODE = 'en-us'
  110 +
  111 +TIME_ZONE = 'UTC'
  112 +
  113 +USE_I18N = True
  114 +
  115 +USE_L10N = True
  116 +
  117 +USE_TZ = True
  118 +
  119 +
  120 +# Static files (CSS, JavaScript, Images)
  121 +# https://docs.djangoproject.com/en/3.2/howto/static-files/
  122 +
  123 +STATIC_URL = '/static/'
  124 +
  125 +# Default primary key field type
  126 +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
  127 +
  128 +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  1 +"""capacitacion URL Configuration
  2 +
  3 +The `urlpatterns` list routes URLs to views. For more information please see:
  4 + https://docs.djangoproject.com/en/3.2/topics/http/urls/
  5 +Examples:
  6 +Function views
  7 + 1. Add an import: from my_app import views
  8 + 2. Add a URL to urlpatterns: path('', views.home, name='home')
  9 +Class-based views
  10 + 1. Add an import: from other_app.views import Home
  11 + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
  12 +Including another URLconf
  13 + 1. Import the include() function: from django.urls import include, path
  14 + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
  15 +"""
  16 +from django.contrib import admin
  17 +from django.urls import path
  18 +
  19 +urlpatterns = [
  20 + path('admin/', admin.site.urls),
  21 +]
  1 +"""
  2 +WSGI config for capacitacion project.
  3 +
  4 +It exposes the WSGI callable as a module-level variable named ``application``.
  5 +
  6 +For more information on this file, see
  7 +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
  8 +"""
  9 +
  10 +import os
  11 +
  12 +from django.core.wsgi import get_wsgi_application
  13 +
  14 +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'capacitacion.settings')
  15 +
  16 +application = get_wsgi_application()
  1 +from django.contrib import admin
  2 +
  3 +# Register your models here.
  1 +from django.apps import AppConfig
  2 +
  3 +
  4 +class CoreConfig(AppConfig):
  5 + default_auto_field = 'django.db.models.BigAutoField'
  6 + name = 'core'
  1 +from django.db import models
  2 +
  3 +
  4 +
  5 +class Activos(models.Model):
  6 + class Meta:
  7 + abstract = True
  8 +
  9 + es_activo = models.BooleanField(default=True)
  10 +
  11 + def activar_registro(self):
  12 + if not self.es_activo:
  13 + self.es_activo = True
  14 + self.save(update_fields=('es_activo',))
  1 +from django.test import TestCase
  2 +
  3 +# Create your tests here.
  1 +from django.shortcuts import render
  2 +
  3 +# Create your views here.
  1 +#!/usr/bin/env python
  2 +"""Django's command-line utility for administrative tasks."""
  3 +import os
  4 +import sys
  5 +
  6 +
  7 +def main():
  8 + """Run administrative tasks."""
  9 + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'capacitacion.settings')
  10 + try:
  11 + from django.core.management import execute_from_command_line
  12 + except ImportError as exc:
  13 + raise ImportError(
  14 + "Couldn't import Django. Are you sure it's installed and "
  15 + "available on your PYTHONPATH environment variable? Did you "
  16 + "forget to activate a virtual environment?"
  17 + ) from exc
  18 + execute_from_command_line(sys.argv)
  19 +
  20 +
  21 +if __name__ == '__main__':
  22 + main()
  1 +from django.contrib import admin
  2 +from django.db.models import Count
  3 +
  4 +from organismo.models import Organismo, TipoOrganismo
  5 +
  6 +@admin.register(TipoOrganismo)
  7 +class TipoOrganismoAdmin(admin.ModelAdmin):
  8 + list_display = ('nombre', 'es_activo', 'cantidad_organismo')
  9 + search_fields = ('nombre',)
  10 + actions = ('desactivar_seleccionados', )
  11 +
  12 + def get_queryset(self, request):
  13 + queryset = super().get_queryset(request).values('organismos').annotate(cantidad_organismo=Count('organismos')).all()
  14 + if request.user.is_superuser:
  15 + return queryset
  16 +
  17 + return queryset.filter(es_activo=True)
  18 +
  19 + def desactivar_seleccionados(self, request, queryset):
  20 + queryset.update(es_activo=False)
  21 +
  22 + def cantidad_organismo(self, tipo):
  23 + return tipo.cantidad_organismo
  24 +
  25 +
  26 +
  27 +
  28 +@admin.register(Organismo)
  29 +class OrganismoAdmin(admin.ModelAdmin):
  30 + list_display = ('nombre', 'tipo')
  31 + search_fields = ('nombre', 'tipo__nombre')
  32 + autocomplete_fields = ('tipo',)
  1 +from django.apps import AppConfig
  2 +
  3 +
  4 +class OrganismoConfig(AppConfig):
  5 + default_auto_field = 'django.db.models.BigAutoField'
  6 + name = 'organismo'
  1 +# Generated by Django 3.2.7 on 2021-09-27 14:00
  2 +
  3 +from django.db import migrations, models
  4 +
  5 +
  6 +class Migration(migrations.Migration):
  7 +
  8 + initial = True
  9 +
  10 + dependencies = [
  11 + ]
  12 +
  13 + operations = [
  14 + migrations.CreateModel(
  15 + name='Organismo',
  16 + fields=[
  17 + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
  18 + ('nombre', models.CharField(max_length=200)),
  19 + ],
  20 + ),
  21 + ]
  1 +# Generated by Django 3.2.7 on 2021-09-27 14:08
  2 +
  3 +from django.db import migrations, models
  4 +import django.db.models.deletion
  5 +
  6 +def crear_tipo_organismo_defecto(apps, schema):
  7 + TipoOrganismo = apps.get_model('organismo', 'TipoOrganismo')
  8 + TipoOrganismo.objects.create(nombre='default')
  9 +
  10 +
  11 +class Migration(migrations.Migration):
  12 +
  13 + dependencies = [
  14 + ('organismo', '0001_initial'),
  15 + ]
  16 +
  17 + operations = [
  18 + migrations.CreateModel(
  19 + name='TipoOrganismo',
  20 + fields=[
  21 + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
  22 + ('nombre', models.CharField(max_length=100)),
  23 + ],
  24 + ),
  25 + migrations.RunPython(crear_tipo_organismo_defecto),
  26 + migrations.AddField(
  27 + model_name='organismo',
  28 + name='tipo',
  29 + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='organismo.tipoorganismo'),
  30 + preserve_default=False,
  31 + ),
  32 + ]
  1 +# Generated by Django 3.2.7 on 2021-09-27 15:12
  2 +
  3 +from django.db import migrations, models
  4 +
  5 +
  6 +class Migration(migrations.Migration):
  7 +
  8 + dependencies = [
  9 + ('organismo', '0002_auto_20210927_1408'),
  10 + ]
  11 +
  12 + operations = [
  13 + migrations.AddField(
  14 + model_name='tipoorganismo',
  15 + name='es_activo',
  16 + field=models.BooleanField(default=True),
  17 + ),
  18 + ]
  1 +from django.db import models
  2 +
  3 +from core.models import Activos
  4 +
  5 +
  6 +
  7 +class TipoOrganismo(Activos, models.Model):
  8 + nombre = models.CharField(max_length=100)
  9 +
  10 + def __str__(self):
  11 + return self.nombre
  12 +
  13 +
  14 +class Organismo(models.Model):
  15 + nombre = models.CharField(max_length=200)
  16 + tipo = models.ForeignKey(
  17 + 'organismo.TipoOrganismo',
  18 + on_delete=models.CASCADE,
  19 + related_name='organismos'
  20 + )
  21 +
  22 +
  23 + def __str__(self):
  24 + return self.nombre
  1 +from django.test import TestCase
  2 +
  3 +# Create your tests here.
  1 +from django.shortcuts import render
  2 +
  3 +# Create your views here.
  1 +from django.contrib import admin
  2 +
  3 +from persona.models import Persona, Agente
  4 +
  5 +
  6 +@admin.register(Persona)
  7 +class PersonaAdmin(admin.ModelAdmin):
  8 + list_display = ('nombre', 'apellido', 'organismo')
  9 + autocomplete_fields = ('organismo',)
  10 + list_filter = ('organismo__tipo',)
  11 +
  12 +
  13 +admin.site.register(Agente)
  1 +from django.apps import AppConfig
  2 +
  3 +
  4 +class PersonaConfig(AppConfig):
  5 + default_auto_field = 'django.db.models.BigAutoField'
  6 + name = 'persona'
  1 +# Generated by Django 3.2.7 on 2021-09-27 13:48
  2 +
  3 +from django.db import migrations, models
  4 +
  5 +
  6 +class Migration(migrations.Migration):
  7 +
  8 + initial = True
  9 +
  10 + dependencies = [
  11 + ]
  12 +
  13 + operations = [
  14 + migrations.CreateModel(
  15 + name='Persona',
  16 + fields=[
  17 + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
  18 + ('nombre', models.CharField(max_length=150)),
  19 + ('apellido', models.CharField(max_length=200)),
  20 + ('documento_identidad', models.CharField(max_length=12, unique=True)),
  21 + ('fecha_nacimiento', models.DateField(blank=True, null=True)),
  22 + ],
  23 + options={
  24 + 'verbose_name': 'Persona',
  25 + 'verbose_name_plural': 'Personas',
  26 + },
  27 + ),
  28 + ]
  1 +# Generated by Django 3.2.7 on 2021-09-27 14:36
  2 +
  3 +from django.db import migrations, models
  4 +import django.db.models.deletion
  5 +
  6 +
  7 +class Migration(migrations.Migration):
  8 +
  9 + dependencies = [
  10 + ('organismo', '0002_auto_20210927_1408'),
  11 + ('persona', '0001_initial'),
  12 + ]
  13 +
  14 + operations = [
  15 + migrations.AddField(
  16 + model_name='persona',
  17 + name='organismo',
  18 + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='organismo.organismo'),
  19 + ),
  20 + ]
  1 +# Generated by Django 3.2.7 on 2021-09-27 15:12
  2 +
  3 +from django.db import migrations, models
  4 +import django.db.models.deletion
  5 +
  6 +
  7 +class Migration(migrations.Migration):
  8 +
  9 + dependencies = [
  10 + ('organismo', '0003_tipoorganismo_es_activo'),
  11 + ('persona', '0002_persona_organismo'),
  12 + ]
  13 +
  14 + operations = [
  15 + migrations.AlterField(
  16 + model_name='persona',
  17 + name='organismo',
  18 + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='personas', to='organismo.organismo'),
  19 + ),
  20 + ]
  1 +# Generated by Django 3.2.7 on 2021-09-27 15:21
  2 +
  3 +from django.db import migrations, models
  4 +import django.db.models.deletion
  5 +import uuid
  6 +
  7 +
  8 +class Migration(migrations.Migration):
  9 +
  10 + dependencies = [
  11 + ('persona', '0003_alter_persona_organismo'),
  12 + ]
  13 +
  14 + operations = [
  15 + migrations.CreateModel(
  16 + name='Agente',
  17 + fields=[
  18 + ('persona_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='persona.persona')),
  19 + ('identificador', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
  20 + ],
  21 + options={
  22 + 'verbose_name': 'Agente',
  23 + 'verbose_name_plural': 'Agentes',
  24 + },
  25 + bases=('persona.persona',),
  26 + ),
  27 + ]
  1 +import uuid
  2 +from django.db import models
  3 +
  4 +
  5 +
  6 +class Persona(models.Model):
  7 + class Meta:
  8 + verbose_name = 'Persona'
  9 + verbose_name_plural = 'Personas'
  10 +
  11 + nombre = models.CharField(max_length=150)
  12 + apellido = models.CharField(max_length=200)
  13 + documento_identidad = models.CharField(max_length=12, unique=True)
  14 + fecha_nacimiento = models.DateField(blank=True, null=True)
  15 +
  16 + organismo = models.ForeignKey(
  17 + 'organismo.Organismo',
  18 + on_delete=models.PROTECT,
  19 + blank=True, null=True,
  20 + related_name='personas'
  21 + )
  22 +
  23 + def __str__(self):
  24 + return f'{self.apellido}, {self.nombre}'
  25 +
  26 +
  27 +class Agente(Persona):
  28 + class Meta:
  29 + verbose_name = 'Agente'
  30 + verbose_name_plural = 'Agentes'
  31 +
  32 + identificador = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
  33 +
  34 +
  35 + def __str__(self):
  36 + return f'{self.identificador}'
  1 +from django.test import TestCase
  2 +
  3 +# Create your tests here.
  1 +from django.shortcuts import render
  2 +
  3 +# Create your views here.