Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
beat
beat.web
Commits
cd18a930
Commit
cd18a930
authored
4 years ago
by
Flavio TARSETTI
Browse files
Options
Downloads
Patches
Plain Diff
[accounts][models/migration] adding TemporaryUrl model
parent
a6edb816
No related branches found
No related tags found
1 merge request
!328
Improve automatic emails with temporary urls
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
beat/web/accounts/migrations/0012_accounts_tempoary_url.py
+31
-0
31 additions, 0 deletions
beat/web/accounts/migrations/0012_accounts_tempoary_url.py
beat/web/accounts/models.py
+42
-0
42 additions, 0 deletions
beat/web/accounts/models.py
with
73 additions
and
0 deletions
beat/web/accounts/migrations/0012_accounts_tempoary_url.py
0 → 100644
+
31
−
0
View file @
cd18a930
# -*- 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
),
),
]
This diff is collapsed.
Click to expand it.
beat/web/accounts/models.py
+
42
−
0
View file @
cd18a930
...
@@ -29,9 +29,11 @@ from django.db import models
...
@@ -29,9 +29,11 @@ from django.db import models
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.db.models.signals
import
post_save
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
from
django.conf
import
settings
import
random
import
random
import
string
import
string
import
datetime
class
AccountSettingsManager
(
models
.
Manager
):
class
AccountSettingsManager
(
models
.
Manager
):
...
@@ -149,3 +151,43 @@ def create_user_profile(sender, instance, created, **kwargs):
...
@@ -149,3 +151,43 @@ def create_user_profile(sender, instance, created, **kwargs):
def
save_user_profile
(
sender
,
instance
,
**
kwargs
):
def
save_user_profile
(
sender
,
instance
,
**
kwargs
):
player
,
created
=
Profile
.
objects
.
get_or_create
(
user
=
instance
)
player
,
created
=
Profile
.
objects
.
get_or_create
(
user
=
instance
)
instance
.
profile
.
save
()
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment