def render(args): """ Helper that helps us render the REST Api responses. :param args: :return: """ query = database.session_query(Authority) sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') if filt: terms = filt.split(';') if 'active' in filt: # this is really weird but strcmp seems to not work here?? query = query.filter(Authority.active == terms[1]) else: query = database.filter(query, Authority, terms) # we make sure that a user can only use an authority they either own are are a member of - admins can see all if not g.current_user.is_admin: authority_ids = [] for role in g.current_user.roles: if role.authority: authority_ids.append(role.authority.id) query = query.filter(Authority.id.in_(authority_ids)) query = database.find_all(query, Authority, args) if sort_by and sort_dir: query = database.sort(query, Authority, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): """ Helper that paginates and filters data when requested through the REST Api :param args: :return: """ query = database.session_query(User) sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') if filt: terms = filt.split(';') query = database.filter(query, User, terms) query = database.find_all(query, User, args) if sort_by and sort_dir: query = database.sort(query, User, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') certificate_id = args.pop('certificate_id', None) if certificate_id: query = database.session_query(Source).join(Certificate, Source.certificate) query = query.filter(Certificate.id == certificate_id) else: query = database.session_query(Source) if filt: terms = filt.split(';') query = database.filter(query, Source, terms) query = database.find_all(query, Source, args) if sort_by and sort_dir: query = database.sort(query, Source, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') certificate_id = args.pop('certificate_id', None) if certificate_id: query = database.session_query(Notification).join( Certificate, Notification.certificate) query = query.filter(Certificate.id == certificate_id) else: query = database.session_query(Notification) if filt: terms = filt.split(';') if terms[0] == 'active' and terms[1] == 'false': query = query.filter(Notification.active == False) # noqa elif terms[0] == 'active' and terms[1] == 'true': query = query.filter(Notification.active == True) # noqa else: query = database.filter(query, Notification, terms) query = database.find_all(query, Notification, args) if sort_by and sort_dir: query = database.sort(query, Notification, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): """ Helper to parse REST Api requests :param args: :return: """ query = database.session_query(Domain).join(Certificate, Domain.certificate) sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') certificate_id = args.pop('certificate_id', None) if filt: terms = filt.split(';') query = database.filter(query, Domain, terms) if certificate_id: query = query.filter(Certificate.id == certificate_id) query = database.find_all(query, Domain, args) if sort_by and sort_dir: query = database.sort(query, Domain, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): sort_by = args.pop("sort_by") sort_dir = args.pop("sort_dir") page = args.pop("page") count = args.pop("count") filt = args.pop("filter") certificate_id = args.pop("certificate_id", None) if certificate_id: query = database.session_query(Notification).join(Certificate, Notification.certificate) query = query.filter(Certificate.id == certificate_id) else: query = database.session_query(Notification) if filt: terms = filt.split(";") if terms[0] == "active" and terms[1] == "false": query = query.filter(Notification.active == False) # noqa elif terms[0] == "active" and terms[1] == "true": query = query.filter(Notification.active == True) # noqa else: query = database.filter(query, Notification, terms) query = database.find_all(query, Notification, args) if sort_by and sort_dir: query = database.sort(query, Notification, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') certificate_id = args.pop('certificate_id', None) if certificate_id: query = database.session_query(Notification).join(Certificate, Notification.certificate) query = query.filter(Certificate.id == certificate_id) else: query = database.session_query(Notification) if filt: terms = filt.split(';') if terms[0] == 'active' and terms[1] == 'false': query = query.filter(Notification.active == False) # noqa elif terms[0] == 'active' and terms[1] == 'true': query = query.filter(Notification.active == True) # noqa else: query = database.filter(query, Notification, terms) query = database.find_all(query, Notification, args) if sort_by and sort_dir: query = database.sort(query, Notification, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): """ Helper that filters subsets of roles depending on the parameters passed to the REST Api :param args: :return: """ query = database.session_query(Role) sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') user_id = args.pop('user_id', None) authority_id = args.pop('authority_id', None) if user_id: query = query.filter(Role.users.any(User.id == user_id)) if authority_id: query = query.filter(Role.authority_id == authority_id) # we make sure that user can see the role - admins can see all if not g.current_user.is_admin: ids = [] for role in g.current_user.roles: ids.append(role.id) query = query.filter(Role.id.in_(ids)) if filt: terms = filt.split(';') query = database.filter(query, Role, terms) query = database.find_all(query, Role, args) if sort_by and sort_dir: query = database.sort(query, Role, sort_by, sort_dir) return database.paginate(query, page, count)