def release_time_repeating_slot(application_id): organisations = repo.get_organisations_for_person( current_user.person_id, auth_token_username=current_user.user_id) umbrella_orgs = repo.get_umbrella_organisations_for_person(current_user.person_id, auth_token_username=current_user.user_id) for umbrella_org in umbrella_orgs: umbrella_member_orgs = repo.get_umbrella_org_member_organisations(umbrella_org.get('id'), auth_token_username=current_user.user_id) organisations.extend( [umb_memb.get('organisation') for umb_memb in umbrella_member_orgs if not any(umb_memb.get('organisation').get('uri') == org.get('uri') for org in organisations)]) try: repeating_application = repo.get_application( application_id, auth_token_username=current_user.user_id ) # Show deleted facilities params = dict(show_deleted=True, show_not_published=True) facilities = repo.get_facilities(auth_token_username=current_user.user_id, params=params) map_applications_to_facilities([repeating_application], facilities) map_organisations_to_applications([repeating_application], organisations) return render_flod_template( 'release_time_repeating_application.html', repeating_application=json.dumps(repeating_application) ) except requests.exceptions.ConnectionError: app.logger.exception('Request failed') return "", 500
def applications(): """Render application list page.""" organisations = repo.get_organisations_for_person( current_user.person_id, auth_token_username=current_user.user_id) umbrella_orgs = repo.get_umbrella_organisations_for_person(current_user.person_id, auth_token_username=current_user.user_id) for umbrella_org in umbrella_orgs: umbrella_member_orgs = repo.get_umbrella_org_member_organisations(umbrella_org.get('id'), auth_token_username=current_user.user_id) organisations.extend( [umb_memb.get('organisation') for umb_memb in umbrella_member_orgs if not any(umb_memb.get('organisation').get('uri') == org.get('uri') for org in organisations)]) try: applications = repo.get_applications( # person_uri=user["person_uri"], auth_token_username=current_user.user_id ) # Show deleted facilities params = dict(show_deleted=True, show_not_published=True) facilities = repo.get_facilities(auth_token_username=current_user.user_id, params=params) map_applications_to_facilities(applications, facilities) map_organisations_to_applications(applications, organisations) get_and_map_persons_to_applications(applications) return render_flod_template( 'applications.html', applications=json.dumps(applications) ) except requests.exceptions.ConnectionError: app.logger.exception('Request failed') return "", 500
def booking(facility_id): try: facility = repo.get_facility(facility_id, auth_token_username=current_user.user_id) if not facility: abort(404, 'Could not find facility with id %s', facility_id) resource = repo.get_resource(facility_id, auth_token_username=current_user.user_id) settings_leieform = repo.get_settings(getattr(current_user, 'user_id', None)) if not resource['repeating_booking_allowed'] and not resource['single_booking_allowed'] and settings_leieform['single_booking_allowed']: return render_flod_template( 'no_booking.html', message=u'Lokalet kan ikke lånes ut. Dette er fordi lokalets administator ikke har åpnet for dette.' ) organisations = repo.get_organisations_for_person( current_user.person_id, auth_token_username=current_user.user_id) if not (resource['single_booking_allowed'] and settings_leieform['single_booking_allowed']) and len(organisations) == 0: return render_flod_template( 'no_booking.html', message=u'Lokalet kan kun lånes av aktører for repeterende lån. Du tilhører ingen aktør.' ) facility['single_booking_allowed'] = resource['single_booking_allowed'] and settings_leieform['single_booking_allowed'] facility['repeating_booking_allowed'] = resource['repeating_booking_allowed'] and settings_leieform['repeating_booking_allowed'] and len(organisations) > 0 type_mappings = json.loads(open( os.path.join(__location__, 'type_maps.json'), "r" ).read()) return render_flod_template( 'booking.html', facility=json.dumps(facility), organisations=json.dumps(organisations), type_mappings=json.dumps(type_mappings) ) except requests.exceptions.ConnectionError: app.logger.exception('Request failed') return "", 500
def facility_view(facility_id): """Render facility page.""" try: facility = repo.get_facility(facility_id, getattr(current_user, 'user_id', None)) # get the resource to check what kind of "rental" it allows resource = repo.get_resource(facility_id) if current_user.is_authenticated(): organisations = repo.get_organisations_for_person( current_user.person_id, auth_token_username=current_user.user_id ) allow_repeating = len(organisations) > 0 # only show repeating link to logged in user with orgs else: allow_repeating = True # for non-logged in user, display repeating link if resource allows it settings_leieform = repo.get_settings(getattr(current_user, 'user_id', None)) facility['single_booking_allowed'] = resource['single_booking_allowed'] and settings_leieform['single_booking_allowed'] facility['repeating_booking_allowed'] = resource['repeating_booking_allowed'] and allow_repeating and settings_leieform['repeating_booking_allowed'] type_mappings = json.loads(open( os.path.join(__location__, 'type_maps.json'), "r" ).read()) if not facility: abort(404, 'Could not find facility with id %s', facility_id) # we have to fetch the facility information # from backend and serve it to the template return render_flod_template( 'facility.html', facility=facility, facility_json=json.dumps(facility), type_mappings=json.dumps(type_mappings) ) except requests.exceptions.ConnectionError: app.logger.exception('Request failed') return "", 500
def profile(): """Render profile page.""" user_data = authentication.get_current_person() try: organisations = repo.get_organisations_for_person( current_user.person_id, auth_token_username=current_user.user_id) umbrella_organisations = repo.get_umbrella_organisations_for_person( current_user.person_id, auth_token_username=current_user.user_id, ) return render_flod_template( 'profile.html', user_data=user_data, organisations=organisations, umbrella_organisations=umbrella_organisations ) except requests.exceptions.ConnectionError: app.logger.exception('Request failed') return "", 500
def render_org_template(template, organisation_id, requires_owner=True, **kwargs): try: is_member = True if current_user.is_authenticated() and current_user.is_idporten_user(): organisations = repo.get_organisations_for_person( current_user.person_id, auth_token_username=current_user.user_id) try: org = next(org for org in organisations if org["id"] == organisation_id) is_member = True except StopIteration: if requires_owner: abort(403) is_member = False return render_flod_template( template, organisation_id=organisation_id, is_member=is_member, **kwargs ) except requests.exceptions.ConnectionError: app.logger.exception('Request failed') return "", 500