Martín Miranda

Inicia proyecto

celerybeat-schedule
*.log
*.py[codt]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
logs
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
coverage.xml
junit.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Complexity
output/*.html
output/*/index.html
# Sphinx
docs/_build
.webassets-cache
# Virtualenvs
venv
# intellij
*.ipr
*.iml
*.iws
# vim
*.sw[o,p]
.DS_Store
# node
node_modules/
# bower packages
.sass-cache/
.idea/.name
.idea/scopes/scope_settings.xml
.idea/encodings.xml
.idea/workspace.xml
# models
models.png
.idea/*
*.db
secret.key
.bash_history
.vagrant/*
# Sublime Text 3
*.sublime-project
*.sublime-workspace
# ?
.cache
src
# Configuration
.env
# Virtual Environment
.venv
tmp
Procfile.dev
# Cython .C files (precompilation)
*.c
__pycache__/
# Logs nginx
deployment/logs/
deployment/circus.ini
deployment/nginx.conf
.pytest_cache/
project/settings/production.py
project/static/*
project/media/*
# Tests
project/test_:memory:
test_:memory:
# Directorio de backups
database_backups
project/test_media/
# Redis dump
dump.rdb
db.sqlite3
\ No newline at end of file
... ...
"""
ASGI config for capacitacion project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'capacitacion.settings')
application = get_asgi_application()
... ...
"""
Django settings for capacitacion project.
Generated by 'django-admin startproject' using Django 3.2.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-6)zkbdelud_+qz14g$q!56o62(+-k!*kgwdygn+)ku4paq(#+w'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'persona',
'organismo',
'core',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'capacitacion.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'capacitacion.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
... ...
"""capacitacion URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
... ...
"""
WSGI config for capacitacion project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'capacitacion.settings')
application = get_wsgi_application()
... ...
from django.contrib import admin
# Register your models here.
... ...
from django.apps import AppConfig
class CoreConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'core'
... ...
from django.db import models
class Activos(models.Model):
class Meta:
abstract = True
es_activo = models.BooleanField(default=True)
def activar_registro(self):
if not self.es_activo:
self.es_activo = True
self.save(update_fields=('es_activo',))
... ...
from django.test import TestCase
# Create your tests here.
... ...
from django.shortcuts import render
# Create your views here.
... ...
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'capacitacion.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
... ...
from django.contrib import admin
from django.db.models import Count
from organismo.models import Organismo, TipoOrganismo
@admin.register(TipoOrganismo)
class TipoOrganismoAdmin(admin.ModelAdmin):
list_display = ('nombre', 'es_activo', 'cantidad_organismo')
search_fields = ('nombre',)
actions = ('desactivar_seleccionados', )
def get_queryset(self, request):
queryset = super().get_queryset(request).values('organismos').annotate(cantidad_organismo=Count('organismos')).all()
if request.user.is_superuser:
return queryset
return queryset.filter(es_activo=True)
def desactivar_seleccionados(self, request, queryset):
queryset.update(es_activo=False)
def cantidad_organismo(self, tipo):
return tipo.cantidad_organismo
@admin.register(Organismo)
class OrganismoAdmin(admin.ModelAdmin):
list_display = ('nombre', 'tipo')
search_fields = ('nombre', 'tipo__nombre')
autocomplete_fields = ('tipo',)
\ No newline at end of file
... ...
from django.apps import AppConfig
class OrganismoConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'organismo'
... ...
# Generated by Django 3.2.7 on 2021-09-27 14:00
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Organismo',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nombre', models.CharField(max_length=200)),
],
),
]
... ...
# Generated by Django 3.2.7 on 2021-09-27 14:08
from django.db import migrations, models
import django.db.models.deletion
def crear_tipo_organismo_defecto(apps, schema):
TipoOrganismo = apps.get_model('organismo', 'TipoOrganismo')
TipoOrganismo.objects.create(nombre='default')
class Migration(migrations.Migration):
dependencies = [
('organismo', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='TipoOrganismo',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nombre', models.CharField(max_length=100)),
],
),
migrations.RunPython(crear_tipo_organismo_defecto),
migrations.AddField(
model_name='organismo',
name='tipo',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='organismo.tipoorganismo'),
preserve_default=False,
),
]
... ...
# Generated by Django 3.2.7 on 2021-09-27 15:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('organismo', '0002_auto_20210927_1408'),
]
operations = [
migrations.AddField(
model_name='tipoorganismo',
name='es_activo',
field=models.BooleanField(default=True),
),
]
... ...
from django.db import models
from core.models import Activos
class TipoOrganismo(Activos, models.Model):
nombre = models.CharField(max_length=100)
def __str__(self):
return self.nombre
class Organismo(models.Model):
nombre = models.CharField(max_length=200)
tipo = models.ForeignKey(
'organismo.TipoOrganismo',
on_delete=models.CASCADE,
related_name='organismos'
)
def __str__(self):
return self.nombre
\ No newline at end of file
... ...
from django.test import TestCase
# Create your tests here.
... ...
from django.shortcuts import render
# Create your views here.
... ...
from django.contrib import admin
from persona.models import Persona, Agente
@admin.register(Persona)
class PersonaAdmin(admin.ModelAdmin):
list_display = ('nombre', 'apellido', 'organismo')
autocomplete_fields = ('organismo',)
list_filter = ('organismo__tipo',)
admin.site.register(Agente)
\ No newline at end of file
... ...
from django.apps import AppConfig
class PersonaConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'persona'
... ...
# Generated by Django 3.2.7 on 2021-09-27 13:48
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Persona',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nombre', models.CharField(max_length=150)),
('apellido', models.CharField(max_length=200)),
('documento_identidad', models.CharField(max_length=12, unique=True)),
('fecha_nacimiento', models.DateField(blank=True, null=True)),
],
options={
'verbose_name': 'Persona',
'verbose_name_plural': 'Personas',
},
),
]
... ...
# Generated by Django 3.2.7 on 2021-09-27 14:36
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('organismo', '0002_auto_20210927_1408'),
('persona', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='persona',
name='organismo',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='organismo.organismo'),
),
]
... ...
# Generated by Django 3.2.7 on 2021-09-27 15:12
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('organismo', '0003_tipoorganismo_es_activo'),
('persona', '0002_persona_organismo'),
]
operations = [
migrations.AlterField(
model_name='persona',
name='organismo',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='personas', to='organismo.organismo'),
),
]
... ...
# Generated by Django 3.2.7 on 2021-09-27 15:21
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
dependencies = [
('persona', '0003_alter_persona_organismo'),
]
operations = [
migrations.CreateModel(
name='Agente',
fields=[
('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')),
('identificador', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
],
options={
'verbose_name': 'Agente',
'verbose_name_plural': 'Agentes',
},
bases=('persona.persona',),
),
]
... ...
import uuid
from django.db import models
class Persona(models.Model):
class Meta:
verbose_name = 'Persona'
verbose_name_plural = 'Personas'
nombre = models.CharField(max_length=150)
apellido = models.CharField(max_length=200)
documento_identidad = models.CharField(max_length=12, unique=True)
fecha_nacimiento = models.DateField(blank=True, null=True)
organismo = models.ForeignKey(
'organismo.Organismo',
on_delete=models.PROTECT,
blank=True, null=True,
related_name='personas'
)
def __str__(self):
return f'{self.apellido}, {self.nombre}'
class Agente(Persona):
class Meta:
verbose_name = 'Agente'
verbose_name_plural = 'Agentes'
identificador = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
def __str__(self):
return f'{self.identificador}'
\ No newline at end of file
... ...
from django.test import TestCase
# Create your tests here.
... ...
from django.shortcuts import render
# Create your views here.
... ...