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)
def organisation_get(current_user): query = refbooks.OrganisationModel.query if request.values.get('org_name', None) is not None: query = query.filter( refbooks.OrganisationModel.name.like('%{}%'.format( request.values['org_name']))) if request.values.get('org_id', None) is not None: query = query.filter( refbooks.OrganisationModel.id == request.values['org_id']) return force_pagination(query)
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)
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)
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)
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)
def log(current_user): query = (other.LoggerModel.query.outerjoin( other.LoggerModel.user).outerjoin(OrganisationModel)) return force_pagination(query)