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

[accounts][models] create a model manager TemporaryUrlManager

parent f40abcce
......@@ -153,6 +153,27 @@ def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
class TemporaryUrlManager(models.Manager):
def create_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)
)
now = datetime.datetime.now()
expiration_date_delta = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS_FROM_SUPERVISOR)
expires = now + expiration_date_delta
temporary_url = self.model(status=status,
url_hash=url_hash,
expires=expires,
supervision_track=supervision_track)
temporary_url.save()
return temporary_url
class TemporaryUrl(models.Model):
# _____ Constants __________
......@@ -175,19 +196,4 @@ class TemporaryUrl(models.Model):
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()
objects = TemporaryUrlManager()
Markdown is supported
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