示例#1
0
    def load_roles(cls):
        for _id, name in USER_ROLES.items():
            existing = cls.query.filter_by(id=_id, name=name)\
                                .first()

            if not existing:
                db.session.add(Roles(id=_id, name=name))
        db.session.commit()
示例#2
0
    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        self.offices.choices = [(o.id, f'{self.translate("Office : ")}{o.prefix}{o.name}')
                                for o in Office.query.all()]

        has_offices = bool(Office.get())
        for _id, role in USER_ROLES.items():
            if _id != 3 or has_offices:
                self.role.choices = (self.role.choices or []) + [(_id, role)]