Example #1
0
def certificates_series(current_user):
    if request.method == 'GET':
        return force_pagination(refbooks.CounterModel.query)

    if request.json['action'] == Action.updated:
        return crud(request.method, request.json, refbooks.CounterModel,
                    current_user)
Example #2
0
def document_type(current_user):
    if request.method == 'GET':
        query = refbooks.DocumentTypeModel.query

        code = request.args.get('code', '')
        if code:
            query = query.filter_by(code=code)

        return force_pagination(query)

    return crud(request.method, None, refbooks.DocumentTypeModel, current_user)
Example #3
0
def death_certificate(current_user: UserModel):
    if request.method == 'GET':
        query = certificates.DeathCertificateModel.query.filter_by(
            organisation_id=current_user.organisationId)
        query = query.outerjoin(certificates.DeathCertificateModel.updateUser)
        return force_query_by_request_values(
            certificates.DeathCertificateModel,
            query,
            order=certificates.DeathCertificateModel.id.desc())
    else:
        json_data = request.json if request.method != 'GET' else None
        if request.method == 'POST' and json_data['action'] == 'updated':
            json_data['data']['updateDatetime'] = datetime.datetime.now()
        return crud(request.method, json_data,
                    certificates.DeathCertificateModel, current_user)
Example #4
0
def user_preferences(current_user):
    if request.method == 'GET':
        model = refbooks.UserPreferencesModel
        query = model.query

        if request.values.get('certificateType', None) is not None:
            query = query.filter(
                model.certificateType == request.values['certificateType'])
        query = query.filter(model.user_id == current_user.id)

        return jsonify(
            {'rows': [instance.to_json() for instance in query.all()]})
    return crud(request.method,
                None if request.method == 'GET' else request.json,
                refbooks.UserPreferencesModel, current_user)
Example #5
0
def speciality(current_user):
    if request.method == 'GET':
        model = refbooks.SpecialityModel
        query = model.query

        if request.values.get('name', None) is not None:
            query = query.filter(model.name.like('%{}%'.format(request.values['name'])))
        if request.values.get('code', None) is not None:
            query = query.filter(model.name.like('%{}%'.format(request.values['code'])))
        if request.values.get('id', None) is not None:
            query = query.filter(model.id == request.values['id'])

        return force_pagination(query)
    return crud(request.method,
                None if request.method == 'GET' else request.json,
                refbooks.SpecialityModel,
                current_user)
Example #6
0
def user(current_user):
    if request.method == 'GET':
        if 'admin' in get_user_rights(current_user):
            query = other.UserModel.query
        else:
            query = other.UserModel.query.filter_by(
                organisationId=current_user.organisationId)

        if request.values.get('user_name', None) is not None:
            query = query.filter(
                other.UserModel.login.like('%s%%' %
                                           request.values['user_name']))
        if request.values.get('user_id', None) is not None:
            query = query.filter(
                other.UserModel.id == request.values['user_id'])

        return force_pagination(query)
    return crud(request.method, request.json, other.UserModel, current_user)
Example #7
0
def group(current_user: other.UserModel):
    if request.method == 'GET':
        query = other.GroupModel.query
        if not has_any_right(current_user, ['admin']):
            query = query.filter(other.GroupModel.level <= current_user.level)
        if not has_any_right(current_user, ['admin', 'Groups']):
            query = query.filter(
                other.GroupModel.id.in_([g.id
                                         for g in current_user.groupList]))

        if request.values.get('group_name', None) is not None:
            query = query.filter(
                other.GroupModel.name.like('%s%%' %
                                           request.values['group_name']))
        if request.values.get('group_id', None) is not None:
            query = query.filter(
                other.GroupModel.id == request.values['group_id'])

        return force_pagination(query)
    return crud(request.method, request.json, other.GroupModel, current_user)
Example #8
0
def organisation_post(current_user):
    return crud(request.method, request.json, refbooks.OrganisationModel,
                current_user)
Example #9
0
def client_validation(current_user):
    return crud(request.method,
                None if request.method == 'GET' else request.json,
                refbooks.ClientValidationModel, current_user)