def get(self, society_id=None): """Get Society(ies) details.""" if society_id: society = self.Society.query.get(society_id) elif request.args.get('name'): society = self.Society.query.filter_by( name=request.args.get('name')).first() else: # if no search term has been passed, return all societies in DB societies = self.Society.query return paginate_items(societies) if society: society_logged_activities = society.logged_activities.all() data, _ = society_schema.dump(society) data['loggedActivities'], _ = user_logged_activities_schema.dump( society_logged_activities) return response_builder(dict( societyDetails=data, message="{} fetched successfully.".format(society.name) ), 200) else: return response_builder(dict( data=None, message="Resource does not exist." ), 404)
def get(cls): """Get all logged activities.""" paginate = request.args.get("paginate", "true") message = "all Logged activities fetched successfully" if paginate.lower() == "false": logged_activities = LoggedActivity.query.all() count = LoggedActivity.query.count() data = {"count": count} else: logged_activities = LoggedActivity.query pagination_result = paginate_items(logged_activities, serialize=False) logged_activities = pagination_result.data data = { "count": pagination_result.count, "page": pagination_result.page, "pages": pagination_result.pages, "previous_url": pagination_result.previous_url, "next_url": pagination_result.next_url } data.update(dict( loggedActivities=logged_activities_schema.dump( logged_activities ).data)) return response_builder(dict(data=data, message=message, status="success"), 200)
def get(cls, redeem_id=None): """Get Redemption Requests.""" if redeem_id: redemp_request = RedemptionRequest.query.get(redeem_id) return find_item(redemp_request) else: search_term_name = request.args.get('society') if search_term_name: society = Society.query.filter_by( name=search_term_name).first() if not society: mes = f"Society with name:{search_term_name} not found" return {"message": mes}, 400 redemp_request = RedemptionRequest.query.filter_by( society_id=society.uuid) return paginate_items(redemp_request) search_term_status = request.args.get('status') if search_term_status: redemp_request = RedemptionRequest.query.filter_by( status=search_term_status) return paginate_items(redemp_request) search_term_name = request.args.get('name') if search_term_name: redemp_request = RedemptionRequest.query.filter_by( name=search_term_name) return paginate_items(redemp_request) search_term_center = request.args.get("center") if search_term_center: center_query = Center.query.filter_by( name=search_term_center).first() if not center_query: mes = f"country with name:{search_term_center} not found" return {"message": mes}, 400 redemp_request = RedemptionRequest.query.filter_by( center=center_query) return paginate_items(redemp_request) redemption_requests = RedemptionRequest.query return paginate_items(redemption_requests)
def get(cls, role_query=None): """Get Role(s) from API.""" if role_query: role = Role.query.get(role_query) return find_item(role) else: search_term = request.args.get('q') if search_term: role = Role.query.filter( Role.name.ilike(f'%{search_term}%')).first() return find_item(role) else: roles = Role.query return paginate_items(roles)
def get(self, redeem_id=None): """Get Redemption Requests.""" paginate = request.args.get("paginate", "true") paginate = False if paginate.lower().strip() == 'false' else True redemp_request = self.RedemptionRequest.query if redeem_id: redemp_request = redemp_request.get(redeem_id) return find_item(redemp_request) else: if request.args.get('society'): search_term_name = request.args.get('society') society = self.Society.query.filter_by( name=search_term_name).first() if not society: mes = f"Society with name:{search_term_name} not found" return {"message": mes}, 400 redemp_request = redemp_request.filter_by( society_id=society.uuid) elif request.args.get('status'): search_term_status = request.args.get('status') redemp_request = redemp_request.filter_by( status=search_term_status) elif request.args.get('name'): search_term_name = request.args.get('name') redemp_request = redemp_request.filter_by( name=search_term_name) elif request.args.get("center"): search_term_center = request.args.get("center") center_query = self.Center.query.filter_by( name=search_term_center).first() if not center_query: mes = f"country with name:{search_term_center} not found" return {"message": mes}, 400 redemp_request = redemp_request.filter_by(center=center_query) return (paginate_items(redemp_request) if paginate else non_paginated_redemptions(redemp_request))