def resource(request, resource_id=None):
    """
    Shows bookings for the specified resource.
    """
    if resource_id is None:
        return http_badrequest(_('No resource id given.'))
    mobile_requested = request.path_info.startswith('/m/')
    language = get_language()
    resources = Resource.objects.language(language).all()
    resource = get_object_or_404(Resource, resource_id)
    context = RequestContext(request, {
        'mobile_requested': mobile_requested,
        'resource': resource,
        'resources': resources})

    return render_to_response('resource.html', context)
def resource(request, resource_id=None):
    """
    Shows bookings for the specified resource.
    """
    if resource_id is None:
        return http_badrequest(_('No resource id given.'))
    mobile_requested = request.path_info.startswith('/m/')
    language = get_language()
    resources = Resource.objects.language(language).all()
    resource = get_object_or_404(Resource, resource_id)
    context = RequestContext(
        request, {
            'mobile_requested': mobile_requested,
            'resource': resource,
            'resources': resources
        })

    return render_to_response('resource.html', context)
def resource_type(request, resource_t_id=None):
    """
    Shows bookings for the specified resource type.
    """
    if resource_t_id is None:
        return http_badrequest(_('No resource type id given.'))

    resource_type = get_object_or_404(ResourceType, resource_t_id)
    resources = list(resource_type.resources.all())
    # Sort resources by longitude so that calendar columns correspond to
    # the map shown above them.
    resources = sorted(resources, key=lambda r: r.longitude)
    min_lat = min(resources, key=lambda r: r.latitude)
    max_lat = max(resources, key=lambda r: r.latitude)
    min_long = min(resources, key=lambda r: r.longitude)
    max_long = max(resources, key=lambda r: r.longitude)

    # Calculate margins and calendar widths
    resource_count = len(resources)
    total_width = 100
    width_sans_margins = 58.2
    margin_width = total_width - width_sans_margins

    cal_width = width_sans_margins / resource_count
    if resource_count == 1:
        cal_margin = margin_width
    else:
        cal_margin = margin_width / (resource_count - 1)

    context = RequestContext(
        request, {
            'longitude': (max_long.longitude + min_long.longitude) / 2,
            'latitude': (max_lat.latitude + min_lat.latitude) / 2,
            'cal_width': cal_width,
            'cal_margin': cal_margin,
            'resource_type': resource_type,
            'resources': resources
        })

    return render_to_response('resource_type.html', context)
def resource_type(request, resource_t_id=None):
    """
    Shows bookings for the specified resource type.
    """
    if resource_t_id is None:
        return http_badrequest(_('No resource type id given.'))

    resource_type = get_object_or_404(ResourceType, resource_t_id)
    resources = list(resource_type.resources.all())
    # Sort resources by longitude so that calendar columns correspond to
    # the map shown above them.
    resources = sorted(resources, key=lambda r: r.longitude)
    min_lat = min(resources, key=lambda r: r.latitude)
    max_lat = max(resources, key=lambda r: r.latitude)
    min_long = min(resources, key=lambda r: r.longitude)
    max_long = max(resources, key=lambda r: r.longitude)

    # Calculate margins and calendar widths
    resource_count = len(resources)
    total_width = 100
    width_sans_margins = 58.2
    margin_width = total_width - width_sans_margins

    cal_width = width_sans_margins / resource_count
    if resource_count == 1:
        cal_margin = margin_width
    else:
        cal_margin = margin_width / (resource_count - 1)

    context = RequestContext(request, {
        'longitude': (max_long.longitude + min_long.longitude) / 2,
        'latitude': (max_lat.latitude + min_lat.latitude) / 2,
        'cal_width': cal_width,
        'cal_margin': cal_margin,
        'resource_type': resource_type,
        'resources': resources})

    return render_to_response('resource_type.html', context)