def get(self, organisation_id): if organisation_id: organisation = Organisation.query.execution_options(show_all=True).get(organisation_id) if organisation is None: response_object = { 'message': 'No such organisation: {}'.format(organisation_id), } return make_response(jsonify(response_object)), 404 response_object = { 'message': 'Successfully Loaded Organisation', 'data': {'organisation': organisation_schema.dump(organisation).data, } } return make_response(jsonify(response_object)), 200 else: organisations_query = Organisation.query.execution_options(show_all=True) organisations, total_items, total_pages, new_last_fetched = paginate_query(organisations_query) if organisations is None: return make_response(jsonify({'message': 'No organisations found'})), 400 response_object = { 'message': 'Successfully Loaded All Projects', 'items': total_items, 'pages': total_pages, 'last_fetched': new_last_fetched, 'data': {'organisations': organisations_schema.dump(organisations).data} } return make_response(jsonify(response_object)), 200
def get_user_organisations(user): active_organisation = getattr(g, "active_organisation", None) or user.fallback_active_organisation() organisations = dict(active_organisation_id=active_organisation.id, organisations=organisations_schema.dump( user.organisations).data) return organisations