You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Adunatio/models/Union.py

33 lines
1.1 KiB

from mongoengine import *
from werkzeug.security import generate_password_hash
from string import ascii_letters, digits
from random import choices
class Union(Document):
name = StringField()
logo = ImageField(thumbnail_size=(120, 120))
description = StringField()
legal_registration_number = StringField()
headquarter = StringField()
email = StringField()
def save(self, *args, **kwargs):
super(Union, self).save(*args, **kwargs)
from .Group import Group
from .User import User
group = Group()
group.union = self
group.name = 'Root'
group.rights = ["*::*::{}/*".format(self.id)]
group.save()
user = User()
user.gov_id = 'root'
user.username = "{}@root".format(self.legal_registration_number)
user.user_group = group
user.union = self
password = ''.join(choices(ascii_letters+digits, k=10))
print("New union password : {}".format(password))
user.password = generate_password_hash(password)
# TODO: send password via mail or sms or nothing
user.save()