Ejemplo n.º 1
0
def kladr_search_street(city_code=None, search_query=None, limit=100):
    result = []
    if city_code is None or search_query is None:
        return jsonify([])
    response = requests.get(u'{0}kladr/street/search/{1}/{2}/{3}/'.format(app.config['VESTA_URL'],
                                                                          city_code,
                                                                          search_query,
                                                                          limit))
    for street in response.json()['data']:
        data = {'code': street['identcode'], 'name': u'{0} {1}'.format(street['fulltype'], street['name'])}
        result.append(data)
    return jsonify(result)
Ejemplo n.º 2
0
def kladr_search_city(search_query=None, limit=300):
    result = []
    if search_query is None:
        return jsonify([])
    response = requests.get(u'{0}kladr/psg/search/{1}/{2}/'.format(app.config['VESTA_URL'],
                                                                   search_query,
                                                                   limit))
    for city in response.json()['data']:
        data = {'code': city['identcode'], 'name': u'{0}. {1}'.format(city['shorttype'], city['name'])}
        if city['parents']:
            for parent in city['parents']:
                data['name'] = u'{0}, {1}. {2}'.format(data['name'], parent['shorttype'], parent['name'])
        result.append(data)
    return jsonify(result)
Ejemplo n.º 3
0
def api_doctors_to_assist():
    viz = PersonTreeVisualizer()
    persons = db.session.query(Person).add_entity(rbUserProfile).join(Person.user_profiles).filter(
        rbUserProfile.code.in_([UserProfileManager.doctor_clinic, UserProfileManager.doctor_diag])
    ).options(
        lazyload('*'),
        joinedload(Person.speciality)
    ).order_by(
        Person.lastName,
        Person.firstName
    )
    res = [viz.make_person_with_profile(person, profile) for person, profile in persons]
    return jsonify(res)
Ejemplo n.º 4
0
def doctor_to_assist():
    if request.method == "POST":
        user_id = request.json['user_id']
        profile_id = request.json['profile_id']
        master_user = UserAuth.get_by_id(user_id)
        profile = rbUserProfile.query.get(profile_id)
        master_user.current_role = (profile.code, profile.name)
        current_user.set_master(master_user)
        identity_changed.send(current_app._get_current_object(), identity=Identity(current_user.id))
        return jsonify({
            'redirect_url': request.args.get('next') or UserProfileManager.get_default_url()
        })
    if not UserProfileManager.has_ui_assistant():
        return redirect(UserProfileManager.get_default_url())
    return render_template('user/select_master_user.html')
Ejemplo n.º 5
0
def api_method(func):
    """Декоратор API-функции. Автомагически оборачивает результат или исключение в jsonify-ответ
    :param func: декорируемая функция
    :type func: callable
    """
    from nemesis.lib.utils import jsonify

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            result = func(*args, **kwargs)
        except ApiException, e:
            traceback.print_exc()
            return jsonify(None, e.code, e.message)
        except Exception, e:
            traceback.print_exc()
            return jsonify(None, 500, repr(e))
Ejemplo n.º 6
0
 def wrapper(*args, **kwargs):
     try:
         result = func(*args, **kwargs)
     except ApiException, e:
         traceback.print_exc()
         return jsonify(None, e.code, e.message)
Ejemplo n.º 7
0
    """
    def __init__(self, code, message):
        self.code = code
        self.message = message

    def __str__(self):
        return u'%s %s' % (self.code, self.message)


def api_method(func):
    """Декоратор API-функции. Автомагически оборачивает результат или исключение в jsonify-ответ
    :param func: декорируемая функция
    :type func: callable
    """
    from nemesis.lib.utils import jsonify

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            result = func(*args, **kwargs)
        except ApiException, e:
            traceback.print_exc()
            return jsonify(None, e.code, e.message)
        except Exception, e:
            traceback.print_exc()
            return jsonify(None, 500, repr(e))
        else:
            return jsonify(result)

    return wrapper
Ejemplo n.º 8
0
def page_not_found(e):
    if request_wants_json():
        return jsonify(unicode(e), result_code=404, result_name=u'Page not found')
    flash(u'Указанный вами адрес не найден')
    return render_template('404.html'), 404
Ejemplo n.º 9
0
def authorisation_failed(e):
    if request_wants_json():
        return jsonify(unicode(e), result_code=403, result_name=u'Forbidden')
    flash(u'У вас недостаточно прав для доступа к функционалу')
    return render_template('user/denied.html'), 403
Ejemplo n.º 10
0
def kladr_street(code=None):
    if code is None:
        return jsonify([])
    return jsonify([get_kladr_street(code)])
Ejemplo n.º 11
0
def kladr_city(code=None):
    if code is None:
        return jsonify([])
    return jsonify([get_kladr_city(code)])