Beispiel #1
0
def addorupdate(id_user):

    """
    Route affichant un formulaire vierge ou non (selon l'url) pour ajouter ou mettre à jour un utilisateurs
    L'envoie du formulaire permet l'ajout ou la mise à jour de l'utilisateur dans la base
    Retourne un template accompagné du formulaire pré-rempli ou non selon le paramètre id_user
    Une fois le formulaire validé on retourne une redirection vers la liste des users
    """
    user_profil = user_from_token(request.cookies['token']).id_profil
    form = t_usersforms.Utilisateur()

    if user_profil <= 2:
        id_group = user_from_token(request.cookies['token']).id_group
        form.id_group.choices = TGroups.selectActiveGroups(id_group)
    else:
        form.id_group.choices = TGroups.selectActiveGroups()

    if id_user is not None:
        user = TUsers.get_one(id_user)
        if request.method == 'GET':
            form = process(form, user)

    if request.method == 'POST':
        if form.validate_on_submit() and form.validate():
            form_user = pops(form.data)
            form_user.pop('id_user')

            if form.pass_plus.data:
                try:
                    (
                        form_user['pass_plus']
                    ) = TUsers.set_password(
                        form.pass_plus.data, form.mdpconf.data
                    )
                except Exception as exp:
                    flash(str(exp))
                    return render_template(
                        'user.html', form=form, title="Formulaire Utilisateur"
                    )
            else:
                form_user.pop('pass_plus')

            if id_user is not None:
                form_user['id_user'] = id_user
                TUsers.update(form_user)
            else:
                TUsers.post(form_user)
            return redirect(url_for('user.users'))
        else:
            errors = form.errors
            flash(errors)

    return render_template(
        'user.html', form=form, title="Formulaire Utilisateur"
    )
Beispiel #2
0
def orderchoice(id_delivery=None, id_group=None):
    """
    Route affichant un formulaire préalable à la commande
    Il permet de choisir sa commande et son relais
    L'envoi du formulaire passe les paramètres id_delivery et id_group au formulaire principal de la commande
    Retourne un template accompagné du formulaire pré-rempli ou non
    """
    
    user_profil = user_from_token(request.cookies['token']).id_profil
    user_right = list()
    if user_profil >= 2:
        user_right = ['C','R','U','D']

    form = orderchoiceform()
    form.id_delivery.choices = TDeliveries.selectActiveDeliveries(True) # True select only open deliveries

    if user_profil <= 3:
        id_group = user_from_token(request.cookies['token']).id_group
        form.id_group.choices = TGroups.selectActiveGroups(id_group)
    else:
        form.id_group.choices = TGroups.selectActiveGroups()

    title = "Choisir une livraison et un  " + config.WORD_GROUP

    if id_delivery is not None:
        delivery = TDeliveries.get_one(id_delivery)
        title = "Choisir un "+config.WORD_GROUP+" pour la livraison '" + delivery['delivery_name'] + "'"
        if request.method == 'GET':
            form.id_delivery.process_data(id_delivery)
            form.id_group.process_data(id_group)
        del form.id_delivery

    if request.method == 'POST':
        if form.validate_on_submit() and form.validate():
            if id_delivery is None:
                id_delivery = form.data['id_delivery']
            if id_group is None:
                id_group = form.data['id_group']
            return redirect(url_for('order.addorupdate', id_delivery=id_delivery, id_group=id_group))
        else:
            errors = form.errors
            flash(errors)
        
    return render_template('order_choice.html', form=form, title=title)