Exemplo n.º 1
0
def create_or_update_person():

    parameters = get_parameters()
    if not parameters:
        abort(405)

    result = []
    for info in parameters:
        card_id = info.get('CardID')
        name = info.get('Name')
        tabel_id = info.get('TabelID')
        hard_id = info.get('HardID')
        payment_id = info.get('PaymentID')

        if not card_id or not name or not hard_id:
            logger.debug('API: Not valid parameters')
            continue

        query = Person.query.filter(Person.firm_id.in_(g.firms))

        person = query.filter_by(card=card_id).first()
        person_by_hard_id = query.filter_by(hard_id=hard_id).first()
        person_by_payment_id = query.filter_by(payment_id=payment_id).first()

        if person:
            if person_by_hard_id and person.id != person_by_hard_id.id:
                logger.debug('API: Not a unique value hard_id')
                continue

            if person_by_payment_id and person.id != person_by_payment_id.id:
                logger.debug('API: Not a unique value payment_id')
                continue
        else:
            person = Person()

        person.card_id = card_id
        person.name = name
        person.hard_id = hard_id
        person.firm_id = g.firms[0]

        if payment_id:
            person.payment_id = payment_id

        if tabel_id:
            person.tabel_id = tabel_id
        person.save()

        result.append(info)

    return get_success_result(result)
Exemplo n.º 2
0
def del_user(firm_id):
    hard_id = request.args.get('hard_id')
    if not hard_id:
        logger.debug('PERSON: Not found hard_id in request parameters')
        abort(405)

    person = Person.query.filter_by(firm_id=firm_id).\
        filter_by(hard_id=hard_id).first()
    if not person:
        logger.debug('PERSON: Not found person')
        abort(404)

    result = Person.delete(person)
    if not result:
        abort(500)

    return render_template("person/success.xml").encode('cp1251')
Exemplo n.º 3
0
def del_person():

    parameters = get_parameters()
    if not parameters:
        abort(405)

    card_id = parameters.get('CardID')
    if not card_id:
        logger.debug('API: Not found CardID in request parameters')
        abort(405)

    person = Person.query.filter(Person.firm_id.in_(g.firms)).\
        filter_by(id=card_id).first()
    if not person:
        logger.debug('API: Not found person')
        abort(404)

    result = Person.delete(person)
    if not result:
        abort(500)

    return get_success_result()
Exemplo n.º 4
0
def add_user(firm_id):
    search = {}
    for key in Person.MANDATORY_PARAMETERS:
        search_value = request.form.get(key)
        if not search_value:
            continue
        search[key] = search_value

    if len(search) != len(Person.MANDATORY_PARAMETERS):
        if not request.form.get(key):
            logger.debug('PERSON: Required parameters missing')
            abort(405)

    person = Person.query.filter_by(firm_id=firm_id).\
        filter((Person.hard_id == search['hard_id']) |
               (Person.tabel_id == search['tabel_id'])).first()

    if person:
        force = request.form.get('force')
        if not force:
            logger.debug('PERSON: Duplicate person')
            abort(400)

        result = Person.delete(person)
        if not result:
            abort(500)

    person = Person()
    person.firm_id = firm_id
    for key, value in search.iteritems():
        setattr(person, key, value)

    for key in Person.OPTIONAL_PARAMETERS:
        value = request.form.get(key)
        if not value:
            continue

        setattr(person, key, value)

    if not person.payment_id:
        person.payment_id = person.hard_id

    if not person.save():
        abort(500)

    return render_template("person/person.xml", persons=(person,)).encode('cp1251')