Commit cd18a930 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[accounts][models/migration] adding TemporaryUrl model

parent a6edb816
# -*- coding: utf-8 -*-
# Generated by Django 1.11.26 on 2020-04-27 23:41
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('accounts', '0011_check_all_accounts'),
]
operations = [
migrations.CreateModel(
name='TemporaryUrl',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('status', models.CharField(choices=[('V', 'Supervisor validates supervisee'), ('Y', 'Self yearly revalidation from sueprvisee')], default='V', max_length=1)),
('url_hash', models.CharField(max_length=32, unique=True, verbose_name='Url')),
('expires', models.DateTimeField(verbose_name='Expires')),
('supervision_track', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='supervisees', to='accounts.SupervisionTrack')),
],
),
migrations.AlterField(
model_name='profile',
name='status',
field=models.CharField(choices=[('N', 'New User'), ('W', 'Waiting Validation'), ('A', 'Accepted'), ('R', 'Rejected'), ('Y', 'Yearly revalidation'), ('B', 'Blocked no supervisor')], default='B', max_length=1),
),
]
......@@ -29,9 +29,11 @@ from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.conf import settings
import random
import string
import datetime
class AccountSettingsManager(models.Manager):
......@@ -149,3 +151,43 @@ def create_user_profile(sender, instance, created, **kwargs):
def save_user_profile(sender, instance, **kwargs):
player, created = Profile.objects.get_or_create(user=instance)
instance.profile.save()
class TemporaryUrl(models.Model):
# _____ Constants __________
# Supervisor validates supervisee
# Self yearly revalidation from supervisee
VALIDATION = "V"
YEARREVALIDATION = "Y"
URL_STATUS = (
(VALIDATION, "Supervisor validates supervisee"),
(YEARREVALIDATION, "Self yearly revalidation from sueprvisee"),
)
# _____ Fields __________
status = models.CharField(max_length=1, choices=URL_STATUS, default=VALIDATION)
url_hash = models.CharField("Url", blank=False, max_length=32, unique=True)
expires = models.DateTimeField("Expires")
supervision_track = models.ForeignKey(
SupervisionTrack, on_delete=models.CASCADE, related_name="supervisees"
)
def _generate_temporary_url(self, status, supervision_track):
# Actions that result creating the object
# url_hash creation
length = 32
url_hash = "".join(
random.choice(string.ascii_letters + string.digits) # nosec
for _ in range(length)
)
self.url_hash = url_hash
now = datetime.datetime.now()
expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS_FROM_SUPERVISOR)
self.expires = now + expiration_date_delta
self.status = status
self.supervision_track = supervision_track
self.save()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment