コード例 #1
0
ファイル: views_projet.py プロジェクト: wilrona/Gesacom
def services(domaine_id = None):
    data = {}
    if domaine_id:
        domaine = Domaine.get_by_id(domaine_id)
        service = Service.query(
            Service.domaine == domaine.key
        )
        for ser in service:
            data[str(ser.key.id())] = ser.libelle
    resp = jsonify(data)
    return resp
コード例 #2
0
ファイル: views_projet.py プロジェクト: wilrona/Gesacom
def edit(projet_id=None):
    menu = 'projet'
    submenu = 'projet'
    context = 'information'
    title_page = 'Projets - Edition'

    if projet_id:
        projet = Projet.get_by_id(projet_id)
        form = FormProjet(obj=projet)
        if request.method != 'POST':
            form.domaine_id.data = projet.domaine_id.get().key.id()
            form.service_id.data = projet.service_id.get().key.id()
            form.client_id.data = projet.client_id.get().key.id()
            form.responsable_id.data = projet.responsable_id.get().key.id()
            if projet.prospect_id:
                form.prospect_id.data = projet.prospect_id.get().key.id()
            form.id.data = projet_id

    else:
        projet = Projet()
        form = FormProjet()

    form.domaine_id.choices = [(0, 'Selection du domaine')]
    for domaine in Domaine.query():
        form.domaine_id.choices.append((domaine.key.id(), domaine.libelle))

    service = []
    if projet_id:
        services = Service.query(
            Service.domaine == projet.domaine_id
        )
        prospects = Client.query(
            Client.prospect == True
        )

    if form.domaine_id.data and not projet_id:
        domaine = Domaine.get_by_id(int(form.domaine_id.data))
        services = Service.query(
            Service.domaine == domaine.key
        )

    if not projet_id:
        prospects = Client.query(
            Client.prospect == True
        )


    form.client_id.choices = [(0, 'Selection du client')]
    for client in Client.query(Client.prospect == False):
        form.client_id.choices.append((client.key.id(), client.name))

    form.responsable_id.choices = [(0, 'Selection du responsable')]
    for user in Users.query(Users.email != '*****@*****.**'):
        form.responsable_id.choices.append((user.key.id(), user.first_name+" "+user.last_name))

    if form.validate_on_submit() and current_user.has_roles([('super_admin', 'projet')], ['edit']):

        projet.titre = form.titre.data

        client_code = Client.get_by_id(int(form.client_id.data))
        if not projet_id:
            projet_client = Projet.query(
                Projet.client_id == client_code.key
            ).count()
            projet.code = client_code.ref+""+str(projet_client+1)

        projet.heure = form.heure.data
        projet.montant = float(form.montant.data)
        projet.date_start = function.date_convert(form.date_start.data)
        projet.date_end = function.date_convert(form.date_end.data)
        projet.client_id = client_code.key

        if client_code.myself and int(form.prospect_id.data):
            pros = Client.get_by_id(int(form.prospect_id.data))
            projet.prospect_id = pros.key

        user = Users.get_by_id(int(form.responsable_id.data))
        projet.responsable_id = user.key

        domaine = Domaine.get_by_id(int(form.domaine_id.data))
        projet.domaine_id = domaine.key

        service = Service.get_by_id(int(form.service_id.data))
        projet.service_id = service.key

        if not projet_id:
            projet.facturable = form.facturable.data

        projet.closed = form.closed.data

        projet_id = projet.put()
        flash('Enregistrement effectue avec succes', 'success')
        return redirect(url_for('projet.edit', projet_id=projet_id.id()))

    return render_template('projet/edit.html', **locals())