<repo_name>setuphub/webLEC<file_sep>/LEC/usuarios/migrations/0006_auto_20201019_1105.py
# Generated by Django 3.1.1 on 2020-10-19 11:05

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


class Migration(migrations.Migration):

    dependencies = [
        ('usuarios', '0005_codigos_activacio_usuarios'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='usuario',
            name='registrado',
        ),
        migrations.AddField(
            model_name='usuario',
            name='confirmacion_activacion',
            field=models.BooleanField(default=False),
        ),
        migrations.AlterField(
            model_name='usuario',
            name='baja',
            field=models.DateTimeField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name='usuario',
            name='equipo',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='usuarios.equipo'),
        ),
        migrations.AlterField(
            model_name='usuario',
            name='imagen_perfil',
            field=models.ImageField(blank=True, null=True, upload_to=None),
        ),
        migrations.AlterField(
            model_name='usuario',
            name='rol',
            field=models.CharField(choices=[('JE', 'Jefe de Equipo'), ('RP', 'Representante'), ('PV', 'Portavoz'), ('PI', 'Piloto')], default='JE', max_length=25),
        ),
        migrations.DeleteModel(
            name='codigos_activacio_usuarios',
        ),
    ]
<file_sep>/LEC/blog/migrations/0001_initial.py
# Generated by Django 3.1.1 on 2020-10-06 11:37

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('usuarios', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='Post',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('titulo', models.CharField(max_length=50, unique_for_date='fecha_creacion')),
                ('subtitulo', models.CharField(max_length=75)),
                ('imagen', models.ImageField(upload_to=None)),
                ('cuerpo', models.TextField()),
                ('categoria', models.CharField(max_length=50)),
                ('etiquetas', models.CharField(max_length=50)),
                ('fecha_creacion', models.DateTimeField(auto_now_add=True)),
                ('fecha_modificado', models.DateTimeField(auto_now_add=True)),
                ('fecha_eliminado', models.DateTimeField()),
                ('creado_por', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='usuarios.usuario', verbose_name='Creado por')),
            ],
            options={
                'verbose_name': 'Post',
                'verbose_name_plural': 'Posts',
                'db_table': 'post',
                'ordering': ['-fecha_modificado'],
                'get_latest_by': '-fecha_modificado',
            },
        ),
        migrations.AddIndex(
            model_name='post',
            index=models.Index(fields=['creado_por'], name='creador_por'),
        ),
    ]
<file_sep>/LEC/usuarios/models.py
from django.db import models
from django.contrib.auth.models import User

# Create your models here.

ROL_CHOICES = [
    ('JE', 'Jefe de Equipo'),
    ('RP', 'Representante'),
    ('PV', 'Portavoz'),
    ('PI', 'Piloto') 
]

class Equipo(models.Model):
    """Model definition for Equipo."""

    # TODO: Define fields here

    nombre_equipo = models.CharField( max_length=50)
    abreviatura = models.CharField(max_length=50)
    email_equipo = models.EmailField(max_length=254)
    pilotos = models.ManyToManyField(User, through='Usuario') #foreign key con usuarios
    activo = models.BooleanField(default = False)
    fecha_creacion = models.DateTimeField( auto_now_add=True)
    fecha_modificacion = models.DateTimeField(auto_now_add=True)
    fecha_baja = models.DateTimeField(auto_now_add=False)

    class Meta:
        """Meta definition for Equipo."""
        db_table ='equipo'
        managed = True
        verbose_name = 'Equipo'
        verbose_name_plural = 'Equipos'

    def __str__(self):
        """Unicode representation of Equipo."""
        return self.nombre_equipo

class Usuario(models.Model):

    user = models.OneToOneField(User, verbose_name="usuario", on_delete=models.CASCADE)
    equipo = models.ForeignKey(Equipo, on_delete=models.CASCADE, null = True)
    rol = models.CharField( max_length=25, choices=ROL_CHOICES, default = 'JE') #si es piloto,jefe de  equipo,representante,etc.
    imagen_perfil = models.ImageField( upload_to=None, height_field=None, width_field=None, max_length=None, blank= True, null = True)
    confirmacion_activacion = models.BooleanField(default = False)
    baja = models.DateTimeField( auto_now=False, auto_now_add=False, null = True, blank = True)



    def __str__(self):
        return self.user.username

    class Meta:
        db_table ='usuario'
        managed = True
        verbose_name = 'Usuario'
        verbose_name_plural = 'Usuarios'


<file_sep>/LEC/usuarios/migrations/0005_codigos_activacio_usuarios.py
# Generated by Django 3.1.1 on 2020-10-09 10:46

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


class Migration(migrations.Migration):

    dependencies = [
        ('usuarios', '0004_auto_20201009_1020'),
    ]

    operations = [
        migrations.CreateModel(
            name='codigos_activacio_usuarios',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('codigo', models.CharField(max_length=5)),
                ('usuario', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='usuarios.usuario')),
            ],
            options={
                'verbose_name': 'Codigo activacion',
                'verbose_name_plural': 'Codigos de activacion',
            },
        ),
    ]
<file_sep>/LEC/blog/migrations/0005_auto_20201027_1123.py
# Generated by Django 3.1.1 on 2020-10-27 11:23

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('blog', '0004_auto_20201012_1625'),
    ]

    operations = [
        migrations.AlterField(
            model_name='post',
            name='categoria',
            field=models.CharField(choices=[('GTS', 'Gran Turismo Sport'), ('GT7', 'Gran Turismo 7'), ('IR', 'iRacing'), ('PC2', 'Project Cars 2'), ('PC3', 'Project Cars 3'), ('RD4', 'Ride 4'), ('ATM', 'Automobilista 2'), ('RFC2', 'rFactor 2'), ('SR', 'SimRacing')], max_length=50),
        ),
    ]
<file_sep>/LEC/blog/urls.py
from django.urls import path

from . import views
from usuarios.views import registro, login, logout

urlpatterns = [
    path('', views.index, name='index'),
    path('login', login, name='login'),
    path('logout',logout, name='logout'),
    path('blog/articulo/<str:id>', views.entrada, name='post')
    #path('registro', registro, name='registro')
]<file_sep>/LEC/foro/migrations/0001_initial.py
# Generated by Django 3.1.1 on 2020-11-02 18:05

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('usuarios', '0006_auto_20201019_1105'),
    ]

    operations = [
        migrations.CreateModel(
            name='Comentario',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('comentario', models.TextField(blank=True, null=True, unique_for_date='fecha_creado')),
                ('fecha_creado', models.DateTimeField(auto_now_add=True)),
                ('fecha_modificado', models.DateTimeField(auto_now_add=True)),
                ('autor', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='usuarios.usuario', verbose_name='autor_comentario')),
            ],
            options={
                'verbose_name': 'Comentario',
                'verbose_name_plural': 'Comentarios',
                'ordering': ['-fecha_creado'],
                'get_latest_by': '-fecha_creado',
            },
        ),
        migrations.CreateModel(
            name='Post',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Titulo', models.CharField(max_length=50, unique_for_date='fecha_creado')),
                ('cuerpo', models.TextField()),
                ('fecha_creado', models.DateTimeField(auto_now_add=True)),
                ('fecha_modificado', models.DateTimeField(auto_now_add=True)),
                ('activo', models.BooleanField(default=True, null=True)),
                ('autor', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, to='usuarios.usuario', verbose_name='autor_post')),
                ('comentarios', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='foro.comentario')),
            ],
            options={
                'verbose_name': 'Post',
                'verbose_name_plural': 'Posts',
                'ordering': ['-fecha_creado'],
                'get_latest_by': '-fecha_creado',
            },
        ),
        migrations.CreateModel(
            name='Subcategoria',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Titulo', models.CharField(max_length=50)),
                ('creado', models.DateTimeField(auto_now_add=True)),
                ('modificado', models.DateTimeField(auto_now_add=True)),
                ('Posts', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='foro.post', verbose_name='Posts')),
            ],
            options={
                'verbose_name': 'Subcategoria',
                'verbose_name_plural': 'Subcategoria',
            },
        ),
        migrations.CreateModel(
            name='Categoria',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Titulo', models.CharField(max_length=50, unique=True)),
                ('creado', models.DateTimeField()),
                ('modificado', models.DateTimeField()),
                ('Subcategoria', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='foro.subcategoria', verbose_name='Subcategoria')),
            ],
            options={
                'verbose_name': 'Categoria',
                'verbose_name_plural': 'Categorias',
            },
        ),
    ]
<file_sep>/LEC/blog/views.py
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import permission_required, login_required
from django.db.models import Q
from .models import Entrada

# Create your views here.
def index(request):

    try:
        entradas = Entrada.objects.all()[:16]
    except:
        entradas = []
    
    context = {
        "entradas": entradas,
    }
    
    #return render(request,'GeneralTemplates/loginForm.html', {'form':form})
    return render(request,'blog/blog.html', context)

def entrada(request,id): #No manda el objeto en el contexto

    context={}
    print(id)

    try:
        entrada = Entrada.objects.get(Q(id = id))
    except:
        error = True
        context.update({'error': error})
        return render(request, 'blog/entrada.html', context)

    print(entrada.fecha_modificado)
    context.update({'entrada': entrada})
    return render(request, 'blog/entrada.html', context)

@permission_required('blog.can_publish', raise_exception=True)
def publish_post(request):
    return redirect(index)<file_sep>/LEC/usuarios/migrations/0001_initial.py
# Generated by Django 3.1.1 on 2020-10-06 11:37

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


class Migration(migrations.Migration):

    atomic = False

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Usuario',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('equipo', models.CharField(max_length=50)),
                ('status', models.CharField(max_length=50)),
                ('imagen_perfil', models.ImageField(upload_to=None)),
                ('activo', models.BooleanField()),
                ('registrado', models.DateTimeField()),
                ('baja', models.DateTimeField()),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='user')),
            ],
            options={
                'verbose_name': 'Usuario',
                'verbose_name_plural': 'Usuarios',
                'db_table': 'usuario',
                'managed': True,
            },
        ),
    ]
<file_sep>/LEC/foro/tests.py
from django.test import TestCase

# Create your tests here.

class Hilo(models.Model):
    """Model definition for Hilo."""

    # TODO: Define fields here

    class Meta:
        """Meta definition for Hilo."""

        verbose_name = 'Hilo'
        verbose_name_plural = 'Hilos'

    def __str__(self):
        """Unicode representation of Hilo."""
        pass

class POST(models.Model):
    """Model definition for POST."""

    # TODO: Define fields here

    class Meta:
        """Meta definition for POST."""

        verbose_name = 'POST'
        verbose_name_plural = 'POSTs'

    def __str__(self):
        """Unicode representation of POST."""
        pass

<file_sep>/LEC/blog/models.py
from django.db import models
from usuarios.models import Usuario

# Create your models here.

CATEGORIAS  = [
    ('GTS', 'Gran Turismo Sport'),
    ('GT7', 'Gran Turismo 7'),
    ('IR', 'iRacing'),
    ('PC2', 'Project Cars 2'),
    ('PC3', 'Project Cars 3'),
    ('RD4', 'Ride 4'),
    ('ATM', 'Automobilista 2'),
    ('RFC2', 'rFactor 2'),
    ('SR', 'SimRacing')
]

class Entrada(models.Model):
    """Model definition for Post."""

    # Define fields here

    titulo = models.CharField( blank=False, max_length=50, unique_for_date="fecha_creacion")
    subtitulo = models.CharField( blank=False, max_length=75)
    imagen = models.ImageField( blank=False, upload_to='%Y/%m/%d/', height_field=None, width_field=None, max_length=None)
    cuerpo = models.TextField( blank=False, )
    categoria = models.CharField( blank=False, max_length=50, choices=CATEGORIAS)
    etiquetas = models.CharField( blank=False, max_length=50)
    fecha_creacion = models.DateTimeField( auto_now_add=True)
    fecha_modificado = models.DateTimeField( auto_now_add=True)
    fecha_eliminado = models.DateTimeField( blank = True, null = True, auto_now_add=False)
    creado_por = models.ForeignKey(Usuario, blank=False, verbose_name="Creado por", on_delete=models.CASCADE)

    class Meta:
        """Meta definition for Post."""

        verbose_name = 'Entrada'
        verbose_name_plural = 'Entradas'
        get_latest_by = "-fecha_modificado"
        ordering = ['-fecha_modificado']
        indexes = [models.Index(fields=['creado_por'], name="creador_por")]

    def __str__(self):
        """Unicode representation of Post."""
        return self.titulo
<file_sep>/LEC/foro/urls.py
from django.urls import path

from . import views

urlpatterns = [
    path('', views.foro, name='categorias'),
    path('foro/<str:Titulo>/', views.subcategoria, name='post')
    #path('registro', registro, name='registro')
]<file_sep>/LEC/usuarios/migrations/0002_auto_20201006_1143.py
# Generated by Django 3.1.1 on 2020-10-06 11:43

from django.db import migrations


class Migration(migrations.Migration):
    atomic = False

    dependencies = [
        ('usuarios', '0001_initial'),
    ]

    operations = [
        migrations.AlterModelTable(
            name='usuario',
            table='Usuario',
        ),
    ]
<file_sep>/LEC/foro/views.py
from django.shortcuts import render
from .models import *
from django.db.models import Q

# Create your views here.


def foro(request):

    context = {}
    categorias = Categoria.objects.all()

    context.update({'categorias': categorias})
    return render(request,'foro/categorias_foro.html',context)

def subcategoria(request,tCategoria,):

    context = {}
    subcategorias = Subcategoria.objects.get(Q(categoria = tCategoria))

    context.update({'subcategorias': subcategorias})

    return render(request,'foro/categorias_foro', context)<file_sep>/LEC/blog/migrations/0004_auto_20201012_1625.py
# Generated by Django 3.1.1 on 2020-10-12 16:25

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


class Migration(migrations.Migration):

    dependencies = [
        ('usuarios', '0005_codigos_activacio_usuarios'),
        ('blog', '0003_auto_20201006_1144'),
    ]

    operations = [
        migrations.AlterField(
            model_name='post',
            name='creado_por',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='usuarios.usuario', verbose_name='Creado por'),
        ),
    ]
<file_sep>/LEC/LEC/context_processors.py
from usuarios.forms import formulario_login

def add_my_login_form(request):
    return {
        'login_form': formulario_login(),
    }<file_sep>/LEC/requirements.txt
asgiref==3.2.10
attrs==20.2.0
awsebcli==3.19.0
bcrypt==3.2.0
blessed==1.17.10
botocore==1.17.63
cached-property==1.5.2
cement==2.8.2
certifi==2020.6.20
cffi==1.14.3
chardet==3.0.4
colorama==0.4.3
cryptography==3.1.1
Django==3.1.1
docker==4.3.1
docker-compose==1.25.5
dockerpty==0.4.1
docopt==0.6.2
docutils==0.15.2
future==0.16.0
idna==2.7
importlib-metadata==2.0.0
jmespath==0.10.0
jsonschema==3.2.0
paramiko==2.7.2
pathspec==0.5.9
Pillow==7.2.0
pkg-resources==0.0.0
pycparser==2.20
PyNaCl==1.4.0
pyrsistent==0.17.3
python-dateutil==2.8.0
pytz==2020.1
PyYAML==5.3.1
requests==2.20.1
semantic-version==2.5.0
six==1.11.0
sqlparse==0.3.1
termcolor==1.1.0
texttable==1.6.3
urllib3==1.24.3
wcwidth==0.1.9
websocket-client==0.57.0
zipp==3.3.0
<file_sep>/LEC/foro/migrations/0005_auto_20201102_1827.py
# Generated by Django 3.1.1 on 2020-11-02 18:27

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


class Migration(migrations.Migration):

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        ('foro', '0004_auto_20201102_1808'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='post',
            name='comentarios',
        ),
        migrations.AddField(
            model_name='comentario',
            name='content_type',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype'),
        ),
        migrations.AddField(
            model_name='comentario',
            name='object_id',
            field=models.PositiveIntegerField(null=True),
        ),
        migrations.AddField(
            model_name='post',
            name='permitir_comentarios',
            field=models.BooleanField(default=True),
        ),
    ]
<file_sep>/LEC/blog/migrations/0009_auto_20201102_1700.py
# Generated by Django 3.1.1 on 2020-11-02 17:00

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('usuarios', '0006_auto_20201019_1105'),
        ('blog', '0008_auto_20201027_1148'),
    ]

    operations = [
        migrations.RenameModel(
            old_name='Post',
            new_name='Entrada',
        ),
        migrations.AlterModelOptions(
            name='entrada',
            options={'get_latest_by': '-fecha_modificado', 'ordering': ['-fecha_modificado'], 'verbose_name': 'Entrada', 'verbose_name_plural': 'Entradas'},
        ),
    ]
<file_sep>/LEC/foro/models.py
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericRelation
from usuarios.models import Usuario

# Create your models here.

class Comentario(models.Model):
    """Model definition for Comentario."""

    # TODO: Define fields here

    comentario = models.TextField(blank = True, null = True, unique_for_date = "fecha_creado")
    autor = models.OneToOneField(Usuario, verbose_name="autor_comentario", on_delete=models.CASCADE)
    fecha_creado = models.DateTimeField(auto_now_add=True)
    fecha_modificado = models.DateTimeField( auto_now_add=True)
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null = True)
    object_id = models.PositiveIntegerField(null = True)
    content_object = GenericForeignKey('content_type', 'object_id')

    class Meta:
        """Meta definition for Comentario."""

        verbose_name = 'Comentario'
        verbose_name_plural = 'Comentarios'
        get_latest_by = "-fecha_creado"
        ordering = ['-fecha_creado']

    def __str__(self):
        """Unicode representation of Comentario."""
        pass


class Post(models.Model):
    """Model definition for MODELNAME."""

    # TODO: Define fields here

    Titulo = models.CharField( max_length=50, unique_for_date = "fecha_creado", null = False, blank = False )
    autor = models.OneToOneField(Usuario, verbose_name="autor_post", on_delete=models.PROTECT, null = False)
    cuerpo = models.TextField(null = False, blank = False)
    comentarios = GenericRelation(Comentario)
    permitir_comentarios = models.BooleanField(default = True)
    fecha_creado = models.DateTimeField(auto_now_add=True)
    fecha_modificado = models.DateTimeField(auto_now_add=True)
    activo = models.BooleanField(default = True, null = True)

    class Meta:
        """Meta definition for MODELNAME."""

        verbose_name = 'Post'
        verbose_name_plural = 'Posts'
        get_latest_by = "-fecha_creado"
        ordering = ['-fecha_creado']

    def __str__(self):
        """Unicode representation of MODELNAME."""
        return self.Titulo


class Subcategoria(models.Model):
    """Model definition for Post."""

    # TODO: Define fields here

    Titulo = models.CharField(max_length=50)
    Posts = models.ForeignKey(Post, verbose_name="Posts", on_delete=models.CASCADE, blank = True, null = True)
    creado = models.DateTimeField(auto_now_add=True)
    modificado = models.DateTimeField(auto_now_add=True)

    class Meta:
        """Meta definition for Post."""

        verbose_name = 'Subcategoria'
        verbose_name_plural = 'Subcategoria'

    def __str__(self):
        """Unicode representation of Post."""
        return self.Titulo


class Categoria(models.Model):
    """Model definition for Hilo."""

    # TODO: Define fields here

    Titulo = models.CharField(max_length=50, unique = True)
    Subcategoria = models.ForeignKey("Subcategoria", verbose_name="Subcategoria", on_delete=models.CASCADE, blank = True, null= True)
    creado = models.DateTimeField(auto_now_add=True)
    modificado = models.DateTimeField(auto_now_add=True)

    class Meta:
        """Meta definition for Hilo."""

        verbose_name = 'Categoria'
        verbose_name_plural = 'Categorias'

    def __str__(self):
        """Unicode representation of Hilo."""
        return self.Titulo<file_sep>/LEC/foro/migrations/0002_auto_20201102_1806.py
# Generated by Django 3.1.1 on 2020-11-02 18:06

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


class Migration(migrations.Migration):

    dependencies = [
        ('foro', '0001_initial'),
    ]

    operations = [
        migrations.AlterField(
            model_name='categoria',
            name='Subcategoria',
            field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='foro.subcategoria', verbose_name='Subcategoria'),
        ),
    ]
<file_sep>/README.md
# webLEC
WEB PARA LEC (Liga Española de Competicion)

Pagina principa donde se pueden ver post creados por redactor(Tipo resultado de competiciones,anuncios,info sobre eventos,etc... como si fuera un blog)

Menu para realizar las inscripciones a campeonato:
  [ ] Para realizar inscripcion primero debe estar registrado(como equipo, no vale nombre de usuario random)
  [ ] Equipo registra a pilotos(Se le asigna ese equipo al piloto). Cuando piloto haga login se muestra pantalla para poner nombre y contraseña
  [ ] Primera pantalla donde se elige el campeonato(se muestra si el periodo de inscripcion esta abierto.En caso de no estarlo, se muestra fecha de apertura si existe)
  [ ] Dentro de campeonato elegido se muestra formulario(diferentes pasos) para inscribir equipo y pilotos.

Consulta de equipos y pilotos por equipos inscritos en campeonatos
Formulario de contacto con administracion
Formulario de peticion de traspaso(Si se realiza traspaso de pilotos entre equipos se queda registrado y se muestra en web)
Se pueda ver streaming oficial desde pagina web<file_sep>/LEC/usuarios/urls.py
from django.urls import path

from . import views

app_name= 'usuarios'

urlpatterns = [
    path('registro', views.registro, name='registro'),
    path('sent/', views.activation_sent_view, name="activation_sent"),
    path('activate/<slug:uidb64>/<slug:token>/', views.activate, name="activate"),
]<file_sep>/LEC/foro/migrations/0003_auto_20201102_1807.py
# Generated by Django 3.1.1 on 2020-11-02 18:07

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('foro', '0002_auto_20201102_1806'),
    ]

    operations = [
        migrations.AlterField(
            model_name='categoria',
            name='creado',
            field=models.DateTimeField(auto_now_add=True),
        ),
        migrations.AlterField(
            model_name='categoria',
            name='modificado',
            field=models.DateTimeField(auto_now_add=True),
        ),
    ]
<file_sep>/LEC/usuarios/migrations/0004_auto_20201009_1020.py
# Generated by Django 3.1.1 on 2020-10-09 10:20

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),
        ('usuarios', '0003_auto_20201006_1147'),
    ]

    operations = [
        migrations.RenameField(
            model_name='usuario',
            old_name='status',
            new_name='rol',
        ),
        migrations.RemoveField(
            model_name='usuario',
            name='activo',
        ),
        migrations.AlterField(
            model_name='usuario',
            name='user',
            field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='usuario'),
        ),
        migrations.CreateModel(
            name='Equipo',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('nombre_equipo', models.CharField(max_length=50)),
                ('abreviatura', models.CharField(max_length=50)),
                ('email_equipo', models.EmailField(max_length=254)),
                ('activo', models.BooleanField(default=False)),
                ('fecha_creacion', models.DateTimeField(auto_now_add=True)),
                ('fecha_modificacion', models.DateTimeField(auto_now_add=True)),
                ('fecha_baja', models.DateTimeField()),
                ('pilotos', models.ManyToManyField(through='usuarios.Usuario', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Equipo',
                'verbose_name_plural': 'Equipos',
                'db_table': 'equipo',
                'managed': True,
            },
        ),
        migrations.AlterField(
            model_name='usuario',
            name='equipo',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='usuarios.equipo'),
        ),
    ]
<file_sep>/LEC/usuarios/views.py
from django.shortcuts import render, redirect
from django.contrib.sites.shortcuts import get_current_site
from django.utils.http import urlsafe_base64_decode
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from .tokens import account_activation_token
from django.template.loader import render_to_string
from django.utils.encoding import force_text
from django.contrib.auth.models import User
from .models import Usuario
from django.contrib.auth import authenticate, login as do_login, logout as do_logout
from .forms import  formulario_registro, formulario_registro_equipo
# Create your views here.

def activation_sent_view(request):
    return render(request, 'usuarios/activacion_enviada.html')

def login(request):

    do_logout(request)
    username = request.POST['nombre_usuario']
    password = request.POST['<PASSWORD>']

    usuario = authenticate(request, username=username, password=password)
    print(usuario)

    if usuario is not None:
        do_login(request, usuario)
        return redirect('index')
    else:
        return redirect('index') 

def logout(request):
    do_logout(request)
    return redirect('index')



def registro(request):
    """
    Funcion para realizar el registro de un usuario de manera manual(solo lo pueden hacer los jefes de equipo)
    """
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = formulario_registro(request.POST)
        print(form.errors)
        # check whether it's valid:
        if form.is_valid():
            print
            # process the data in form.cleaned_data as required
            user = form.save()
            user.refresh_from_db()

            user.is_active = False
            user.save()

            usuario = Usuario()
            usuario.user = user 
            usuario.save()

            current_site = get_current_site(request)

            subject = 'Activacion de cuenta'
            message = render_to_string('usuarios/activacion_cuenta.html',{
                'usuario' : user,
                'dominio' : current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })

            user.email_user(subject,message)
            return redirect('usuarios:activation_sent')

            # username = form.cleaned_data.get("username")
            # password = form.cleaned_data.get("<PASSWORD>")
            # usuario = authenticate(username=username, password=<PASSWORD>)
            # print(usuario)

            # if usuario is not None:
            #     do_login(request, usuario)
            #     return redirect('index')
            # else:
            #     return redirect('index')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = formulario_registro()
    

    return render(request,'GeneralTemplates/registerForm.html', {'form':form})

def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None
    # checking if the user exists, if the token is valid.
    if user is not None and account_activation_token.check_token(user, token):
        # if valid set active true 
        user.is_active = True
        # set signup_confirmation true
        user.usuario.signup_confirmation = True
        user.save()
        do_login(request, user)
        return redirect('index')
    else:
        return render(request, 'activacion_error.html')

def registro_equipo(request):
    """
    Funcion para registrar los datos del equipo
    """
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = formulario_registro_equipo(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            return render(request,'blog/blog.html')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = formulario_registro_equipo()
    

    return render(request,'GeneralTemplates/teamRegister.html', {'form':form})
