def contact_edit(contact_id=None):

    client_id = None

    if contact_id:
        contact = Contact.objects.get(id=contact_id)
        form = FormContact(obj=contact)
        form.client_id.data = contact.client_id.id
    else:
        contact = Contact()
        form = FormContact()

    form.client_id.choices = [(0, 'Selectionnez un client')]
    for choice in Client.objects():
        form.client_id.choices.append((str(choice.id), choice.name))
    form.contact.data = 'contact'

    success = False
    if form.validate_on_submit():

        contact.first_name = form.first_name.data
        contact.last_name = form.last_name.data
        contact.email = form.email.data
        contact.phone1 = form.phone1.data
        contact.phone2 = form.phone2.data

        customer = Client.objects.get(id=form.client_id.data)

        contact.client_id = customer

        contact.save()
        flash('Enregistrement effectue avec success', 'success')
        success = True

    return render_template('client/contact_edit.html', **locals())
Beispiel #2
0
def contact_edit(contact_id=None):

    client_id = None

    if contact_id:
        contact = Contact.get_by_id(contact_id)
        form = FormContact(obj=contact)
        form.client_id.data = contact.client_id.get().key.id()
    else:
        contact = Contact()
        form = FormContact()

    form.client_id.choices = [(0, 'Selectionnez un client')]
    for choice in Client.query():
        form.client_id.choices.append((choice.key.id(), choice.name))
    form.contact.data = 'contact'

    success = False
    if form.validate_on_submit():

        contact.first_name = form.first_name.data
        contact.last_name = form.last_name.data
        contact.email = form.email.data
        contact.phone1 = form.phone1.data
        contact.phone2 = form.phone2.data

        customer = Client.get_by_id(int(form.client_id.data))

        contact.client_id = customer.key

        contact.put()
        flash('Enregistrement effectue avec success', 'success')
        success = True

    return render_template('client/contact_edit.html', **locals())
def contact_edit(client_id, contact_id=None):

    user = Client.objects.get(id=client_id)

    if contact_id:
        contact = Contact.objects.get(id=contact_id)
        form = FormContact(obj=contact)
    else:
        contact = Contact()
        form = FormContact()

    form.client_id.choices = [(0, '')]

    success = False
    if form.validate_on_submit():
        contact.first_name = form.first_name.data
        contact.last_name = form.last_name.data
        contact.email = form.email.data
        contact.phone1 = form.phone1.data
        contact.phone2 = form.phone2.data
        contact.client_id = user

        contact.save()
        flash('Enregistrement effectue avec success', 'success')
        success = True

    return render_template('client/contact_edit.html', **locals())
Beispiel #4
0
def contact_edit(client_id, contact_id=None):

    user = Client.get_by_id(client_id)

    if contact_id:
        contact = Contact.get_by_id(contact_id)
        form = FormContact(obj=contact)
    else:
        contact = Contact()
        form = FormContact()

    form.client_id.choices = [(0, '')]

    success = False
    if form.validate_on_submit():
        contact.first_name = form.first_name.data
        contact.last_name = form.last_name.data
        contact.email = form.email.data
        contact.phone1 = form.phone1.data
        contact.phone2 = form.phone2.data
        contact.client_id = user.key

        contact.put()
        flash('Enregistrement effectue avec success', 'success')
        success = True

    return render_template('client/contact_edit.html', **locals())