Esempio n. 1
0
def horaire_edit(user_id):

    user = Users.get_by_id(user_id)

    horaire = Horaire()
    form = FormHoraire()

    success = False

    if form.validate_on_submit():

        horaire_exist = Horaire.query(
            Horaire.date_start == function.date_convert(form.date_start.data),
            Horaire.user == user.key
        ).count()

        if horaire_exist:
            success = False
            form.date_start.errors.append('Il existe un taux horaire applicable pour la meme date')
        else:
            horaire.date_start = function.date_convert(form.date_start.data)
            horaire.montant = float(form.montant.data)
            horaire.user = user.key
            horaire_id = horaire.put()

            if function.date_convert(form.date_start.data) == datetime.date.today():
                user.tauxH = float(form.montant.data)
                user.tauxHApp = horaire_id.id()
                user.put()

            flash('Enregistement effectue avec succes', 'success')
            success = True

    return render_template('user/horaire_edit.html', **locals())
Esempio n. 2
0
def horaire(user_id):
    menu = 'societe'
    submenu = 'users'
    context = 'horaire'
    title_page = 'Parametre - Utilisateurs'

    user = Users.get_by_id(user_id)

    time_zones = pytz.timezone('Africa/Douala')
    date_auto_nows = datetime.datetime.now(time_zones)

    search = False
    q = request.args.get('q')
    if q:
        search = True
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    datas = Horaire.query(
        Horaire.user == user.key
    ).order(-Horaire.date_start)

    pagination = Pagination(css_framework='bootstrap3', page=page, total=datas.count(), search=search, record_name='horaires')

    if datas.count() > 10:
        if page == 1:
            offset = 0
        else:
            page -= 1
            offset = page * 10
        datas.fetch(limit=10, offset=offset)

    return render_template('user/horaire.html', **locals())
Esempio n. 3
0
def infos(user_id):
    menu = 'societe'
    submenu = 'users'
    context = 'information'
    title_page = 'Parametre - Utilisateurs'

    user = Users.get_by_id(user_id)
    form = FormUser(obj=user)

    if user.fonction_id:
        form.fonction_id.data = user.fonction_id.get().key.id()
    form.fonction_id.choices = [(0, 'Selectionnez une fonction')]
    for choice in Fonction.query():
        form.fonction_id.choices.append((choice.key.id(), choice.libelle))

    if user.site_id:
        form.site_id.data = user.site_id.get().key.id()
    form.site_id.choices = [(0, 'Selectionnez un site')]
    for choice in Site.query():
        form.site_id.choices.append((choice.key.id(), choice.libelle))

    if user.grade_id:
        form.grade_id.data = user.grade_id.get().key.id()
    form.grade_id.choices = [(0, 'Selectionnez un grade')]
    for choice in Grade.query():
        form.grade_id.choices.append((choice.key.id(), choice.libelle))

    if user.departement_id:
        form.departement_id.data = user.departement_id.get().key.id()
    form.departement_id.choices = [(0, 'Selectionnez un departement')]
    for choice in Departement.query():
        form.departement_id.choices.append((choice.key.id(), choice.libelle))

    if form.validate_on_submit() and request.method == 'POST' and current_user.has_roles([('super_admin', 'user_infos')], ['edit']):

        fonction = Fonction.get_by_id(int(form.fonction_id.data))
        user.fonction_id = fonction.key

        site = Site.get_by_id(int(form.site_id.data))
        user.site_id = site.key

        grade = Grade.get_by_id(int(form.grade_id.data))
        user.grade_id = grade.key

        departement = Departement.get_by_id(int(form.departement_id.data))
        user.departement_id = departement.key

        user.matricule = form.matricule.data

        user.is_enabled = True

        if form.date_start.data:
            user.date_start = function.date_convert(form.date_start.data)

        user.put()

        flash('Enregistement effectue avec succes', 'success')
        return redirect(url_for('user_param.infos', user_id=user_id))

    return render_template('user/infos.html', **locals())
Esempio n. 4
0
def unique_email_validator(form, field):
    """ email must be unique"""
    user_manager = Users.query(Users.email == field.data).count()
    if user_manager >= 1 and field.data:
        if not form.id.data:
            raise wtf.ValidationError('Cette adresse email est deja utilise.')
        else:
            code = Users.get_by_id(int(form.id.data))
            if code.email != field.data:
                raise wtf.ValidationError(
                    'Cette adresse email est deja utilise.')
Esempio n. 5
0
def unique_email_validator(form, field):
    """ email must be unique"""
    user_manager = Users.query(
        Users.email == field.data
    ).count()
    if user_manager >= 1 and field.data:
        if not form.id.data:
            raise wtf.ValidationError('Cette adresse email est deja utilise.')
        else:
            code = Users.get_by_id(int(form.id.data))
            if code.email != field.data:
                raise wtf.ValidationError('Cette adresse email est deja utilise.')
Esempio n. 6
0
def active(user_id):

    users = Users.get_by_id(user_id)

    if users.is_active():
        users.is_enabled = False
    else:
        users.is_enabled = True

    users.put()
    flash('Enregistement effectue avec succes', 'success')
    return redirect(url_for('user_param.index'))
Esempio n. 7
0
def active(user_id):

    users = Users.get_by_id(user_id)

    if users.is_active():
        users.is_enabled = False
    else:
        users.is_enabled = True

    users.put()
    flash('Enregistement effectue avec succes', 'success')
    return redirect(url_for('user_param.index'))
Esempio n. 8
0
def logout():
    change = None

    if 'user_id' in session:
        UserLogout = Users.get_by_id(int(session.get('user_id')))
        UserLogout.logged = False
        change = UserLogout.put()

    if change:
        session.pop('user_id')

    return redirect(url_for('home.home'))
Esempio n. 9
0
def logout():
    change = None

    if 'user_id' in session:
        UserLogout = Users.get_by_id(int(session.get('user_id')))
        UserLogout.logged = False
        change = UserLogout.put()

    if change:
        session.pop('user_id')

    return redirect(url_for('home.index'))
Esempio n. 10
0
def password(user_id):

    users = Users.get_by_id(user_id)
    form = FormPassword()

    success = False
    if form.validate_on_submit():

        users.password = hashlib.sha224(form.password.data).hexdigest()
        users.put()

        flash('Enregistement effectue avec succes', 'success')
        success = True

    return render_template('user/password.html', **locals())
Esempio n. 11
0
def password(user_id):

    users = Users.get_by_id(user_id)
    form = FormPassword()

    success = False
    if form.validate_on_submit():

        users.password = hashlib.sha224(form.password.data).hexdigest()
        users.put()

        flash('Enregistement effectue avec succes', 'success')
        success = True

    return render_template('user/password.html', **locals())
Esempio n. 12
0
def random(user_id):

    users = Users.get_by_id(user_id)

    from random import choice
    from string import digits

    code = list()
    for i in range(4):
        code.append(choice(digits))

    users.pin = int("".join(code))

    users.put()
    flash('Enregistement effectue avec succes', 'success')
    return redirect(url_for('user_param.index'))
Esempio n. 13
0
def random(user_id):

    users = Users.get_by_id(user_id)

    from random import choice
    from string import digits

    code = list()
    for i in range(4):
        code.append(choice(digits))

    users.pin = int("".join(code))


    users.put()
    flash('Enregistement effectue avec succes', 'success')
    return redirect(url_for('user_param.index'))
Esempio n. 14
0
def edit(user_id=None):

    if user_id:
        users = Users.get_by_id(user_id)
        form = FormUser(obj=users)
        form.id.data = user_id
        form.profil.data = users.profil_id.id()
    else:
        users = Users()
        form = FormUser()

    form.client.data = 0

    form.profil.choices = [(0, 'Selectionnez un profil')]
    for choice in Profil.query():
        profilRole = ProfilRole.query(ProfilRole.profil_id == choice.key).count()
        if profilRole:
            form.profil.choices.append((choice.key.id(), choice.name))

    success = False
    if form.validate_on_submit():

        profil = None
        if form.profil.data:

            profil = Profil.get_by_id(int(form.profil.data))

            if users.profil_id and users.profil_id != profil.key and user_id:
                role_del = ProfilRole.query(
                    ProfilRole.profil_id == users.profil
                )

                for role_del in role_del:
                    remove_role = UserRole.query(
                        UserRole.role_id == role_del.role_id,
                        UserRole.user_id == users.key
                    ).get()

                    remove_role.key.delete()

            users.profil_id = profil.key

        users.name = form.name.data
        users.phone = form.phone.data
        users.email = form.email.data
        users.login = form.login.data


        from random import choice
        from string import digits

        code = list()
        for i in range(5):
            code.append(choice(digits))

        users.pin = int(''.join(code))

        UserCreate = users.put()


        if form.profil.data:
            all_role = ProfilRole.query(
                    ProfilRole.profil_id == profil.key
            )

            # insertion de chaque role a l'utilisateur cree
            UserCreate = Users.get_by_id(UserCreate.id())

            for role in all_role:
                UserRoles = UserRole()
                UserRoles.role_id = role.role_id
                UserRoles.user_id = UserCreate.key
                UserRoles.edit = role.edit
                UserRoles.delete = role.delete
                UserRoles.put()

        flash('Enregistement effectue avec succes', 'success')
        success = True

    return render_template('user/edit.html', **locals())
Esempio n. 15
0
def load_user(userid):
    return Users.get_by_id(userid)
Esempio n. 16
0
def budget(user_id):
    menu = 'societe'
    submenu = 'users'
    context = 'budget'
    title_page = 'Parametre - Utilisateurs'

    from ..budget.models_budget import Budget, BudgetPrestation

    user = Users.get_by_id(user_id)

    budget_user = Budget.query(
        Budget.user_id == user.key
    )

    search = False
    q = request.args.get('q')
    if q:
        search = True
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    list_budget = []
    datas = budget_user
    if budget_user.count() > 10:
        if page == 1:
            offset = 0
        else:
            page -= 1
            offset = page * 10
        datas = budget_user.fetch(limit=10, offset=offset)

    for budget in datas:
        data = {}

        data['disponible'] = 0
        data['year'] = budget.date_start.year
        if budget.heure:
            data['disponible'] = budget.heure

        budget_prest = BudgetPrestation.query(
            BudgetPrestation.budget_id == budget.key
        )

        data['budget_prestation'] = []

        for prestation in budget_prest:
            data2 = {}
            data2['id'] = prestation.prestation_id.get().key.id()
            data2['prestation'] = prestation.prestation_id.get().libelle
            data2['sigle'] = prestation.prestation_id.get().sigle
            data2['time'] = prestation.heure

            data['budget_prestation'].append(data2)

        list_budget.append(data)

    pagination = Pagination(css_framework='bootstrap3', page=page, total=budget_user.count(), search=search, record_name='Budget de l\'utilisateur')

    return render_template('user/budget.html', **locals())
Esempio n. 17
0
def edit(user_id=None):

    if user_id:
        users = Users.get_by_id(user_id)
        form = FormUser(obj=users)
        form.id.data = user_id
        form.profil.data = users.profil_id.id()
    else:
        users = Users()
        form = FormUser()

    form.client.data = 0

    form.profil.choices = [(0, 'Selectionnez un profil')]
    for choice in Profil.query():
        profilRole = ProfilRole.query(
            ProfilRole.profil_id == choice.key).count()
        if profilRole:
            form.profil.choices.append((choice.key.id(), choice.name))

    success = False
    if form.validate_on_submit():

        profil = None
        if form.profil.data:

            profil = Profil.get_by_id(int(form.profil.data))

            if users.profil_id and users.profil_id != profil.key and user_id:
                role_del = ProfilRole.query(
                    ProfilRole.profil_id == users.profil)

                for role_del in role_del:
                    remove_role = UserRole.query(
                        UserRole.role_id == role_del.role_id,
                        UserRole.user_id == users.key).get()

                    remove_role.key.delete()

            users.profil_id = profil.key

        users.name = form.name.data
        users.phone = form.phone.data
        users.email = form.email.data
        users.login = form.login.data

        from random import choice
        from string import digits

        code = list()
        for i in range(5):
            code.append(choice(digits))

        users.pin = int(''.join(code))

        UserCreate = users.put()

        if form.profil.data:
            all_role = ProfilRole.query(ProfilRole.profil_id == profil.key)

            # insertion de chaque role a l'utilisateur cree
            UserCreate = Users.get_by_id(UserCreate.id())

            for role in all_role:
                UserRoles = UserRole()
                UserRoles.role_id = role.role_id
                UserRoles.user_id = UserCreate.key
                UserRoles.edit = role.edit
                UserRoles.delete = role.delete
                UserRoles.put()

        flash('Enregistement effectue avec succes', 'success')
        success = True

    return render_template('user/edit.html', **locals())
Esempio n. 18
0
def permission(user_id):
    menu = 'societe'
    submenu = 'users'
    context = 'permission'
    title_page = 'Parametre - Utilisateurs'

    user = Users.get_by_id(user_id)

    # liste des roles lie a l'utiliasteur en cours
    attrib = UserRole.query(
        UserRole.user_id == user.key
    )
    attrib_list = [role.role_id.get().key.id() for role in attrib]

    # liste des roles lie a l'utiliasteur en cours avec le droit d'edition
    edit = UserRole.query(
        UserRole.user_id == user.key,
        UserRole.edit == True
    )
    edit_list = [role.role_id.get().key.id() for role in edit]

    # liste des roles lie a l'utiliasteur en cours avec le droit de suppression
    delete = UserRole.query(
        UserRole.user_id == user.key,
        UserRole.delete == True
    )
    delete_list = [role.role_id.get().key.id() for role in delete]


    liste_role = []
    data_role = Roles.query(
        Roles.valeur != 'super_admin'
    )

    for role in data_role:
        if not role.parent:
            module = {}
            module['titre'] = role.titre
            module['id'] = role.key.id()
            enfants = Roles.query(
                Roles.parent == role.key
            )
            module['role'] = []
            for enfant in enfants:
                rol = {}
                rol['id'] = enfant.key.id()
                rol['titre'] = enfant.titre
                rol['action'] = enfant.action
                module['role'].append(rol)
            liste_role.append(module)

    # liste des profils de l'application
    list_profil = Profil.query(
        Profil.active == True
    )

    profil_select = None
    if request.args.get('profil') and request.method == 'GET':

        profil_select = int(request.args.get('profil'))
        profil_request = Profil.get_by_id(int(request.args.get('profil')))

        attrib = ProfilRole.query(
            ProfilRole.profil_id == profil_request.key,
        )

        attrib_list = [role.role_id.get().key.id() for role in attrib]

        # liste des roles lie a l'utiliasteur en cours avec le droit d'edition
        edit = ProfilRole.query(
            ProfilRole.profil_id == profil_request.key,
            ProfilRole.edit == True
        )
        edit_list = [role.role_id.get().key.id() for role in edit]

        # liste des roles lie a l'utiliasteur en cours avec le droit de suppression
        delete = ProfilRole.query(
            ProfilRole.profil_id == profil_request.key,
            ProfilRole.delete == True
        )
        delete_list = [role.role_id.get().key.id() for role in delete]


    if request.method == 'POST' and current_user.has_roles([('super_admin', 'user_permission')], ['edit']):

        form_attrib = request.form.getlist('attrib')

        # if not form_attrib and attrib_list:
        #     flash('Les utilisateurs ne doivent pas exister sans permission dans l\'application', 'warning')
        #     return redirect(url_for('user_param.permission', user_id=user_id))
        # elif form_attrib:
        #     user.is_enabled = True
        #     user.put()

        form_edit = request.form.getlist('edit')
        form_delete = request.form.getlist('delete')

        # liste des roles lie au profil et supprimer ce qui ne sont plus attribue
        current_profil_role = UserRole.query(
            UserRole.user_id == user.key
        )
        for current in current_profil_role:
            if current.role_id.get().key.id() not in form_attrib:
                current.key.delete()

        # Insertion des roles et authorisation en provenance du formulaire
        for attrib in form_attrib:

            role_form = Roles.get_by_id(int(attrib))

            profil_role_exist = UserRole.query(
                UserRole.role_id == role_form.key,
                UserRole.user_id == user.key
            ).get()

            if profil_role_exist:
                if attrib in form_edit:
                    profil_role_exist.edit = True
                else:
                    profil_role_exist.edit = False

                if attrib in form_delete:
                    profil_role_exist.delete = True
                else:
                    profil_role_exist.delete = False

                profil_role_exist.put()
            else:
                profil_role_create = UserRole()
                profil_role_create.role_id = role_form.key
                profil_role_create.user_id = user.key
                if attrib in form_edit:
                    profil_role_create.edit = True
                else:
                    profil_role_create.edit = False

                if attrib in form_delete:
                    profil_role_create.delete = True
                else:
                    profil_role_create.delete = False

                profil_role_create.put()

        flash('Enregistement effectue avec succes', 'success')
        return redirect(url_for('user_param.permission', user_id=user_id))

    return render_template('user/permission.html', **locals())
Esempio n. 19
0
def load_user(userid):
    return Users.get_by_id(userid)
Esempio n. 20
0
def permission(user_id):

    user = Users.get_by_id(user_id)

    # liste des roles lie a l'utiliasteur en cours
    attrib = UserRole.query(UserRole.user_id == user.key)
    attrib_list = [role.role_id.get().key.id() for role in attrib]

    # liste des roles lie a l'utiliasteur en cours avec le droit d'edition
    edit = UserRole.query(UserRole.user_id == user.key, UserRole.edit == True)
    edit_list = [role.role_id.get().key.id() for role in edit]

    # liste des roles lie a l'utiliasteur en cours avec le droit de suppression
    delete = UserRole.query(UserRole.user_id == user.key,
                            UserRole.delete == True)
    delete_list = [role.role_id.get().key.id() for role in delete]

    liste_role = []
    data_role = Roles.query(Roles.valeur != 'super_admin')

    for role in data_role:
        if not role.parent:
            module = {}
            module['titre'] = role.titre
            module['id'] = role.key.id()
            enfants = Roles.query(Roles.parent == role.key)
            module['role'] = []
            for enfant in enfants:
                rol = {}
                rol['id'] = enfant.key.id()
                rol['titre'] = enfant.titre
                rol['action'] = enfant.action
                module['role'].append(rol)
            liste_role.append(module)

    # liste des profils de l'application
    list_profil = Profil.query(Profil.active == True)
    # and current_user.has_roles([('super_admin', 'user_permission')], ['edit'])
    success = False
    if request.method == 'POST':

        form_attrib = request.form.getlist('attrib')

        # if not form_attrib and attrib_list:
        #     flash('Les utilisateurs ne doivent pas exister sans permission dans l\'application', 'warning')
        #     return redirect(url_for('user_param.permission', user_id=user_id))
        # elif form_attrib:
        #     user.is_enabled = True
        #     user.put()

        form_edit = request.form.getlist('edit')
        form_delete = request.form.getlist('delete')

        # liste des roles lie au profil et supprimer ce qui ne sont plus attribue
        current_profil_role = UserRole.query(UserRole.user_id == user.key)
        for current in current_profil_role:
            if current.role_id.get().key.id() not in form_attrib:
                current.key.delete()

        # Insertion des roles et authorisation en provenance du formulaire
        for attrib in form_attrib:

            role_form = Roles.get_by_id(int(attrib))

            profil_role_exist = UserRole.query(
                UserRole.role_id == role_form.key,
                UserRole.user_id == user.key).get()

            if profil_role_exist:
                if attrib in form_edit:
                    profil_role_exist.edit = True
                else:
                    profil_role_exist.edit = False

                if attrib in form_delete:
                    profil_role_exist.delete = True
                else:
                    profil_role_exist.delete = False

                profil_role_exist.put()
            else:
                profil_role_create = UserRole()
                profil_role_create.role_id = role_form.key
                profil_role_create.user_id = user.key
                if attrib in form_edit:
                    profil_role_create.edit = True
                else:
                    profil_role_create.edit = False

                if attrib in form_delete:
                    profil_role_create.delete = True
                else:
                    profil_role_create.delete = False

                profil_role_create.put()

        success = True
        flash('Enregistement effectue avec succes', 'success')

    return render_template('user/permission.html', **locals())