示例#1
0
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
示例#2
0
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