Esempio n. 1
0
def json_hours(request):
    """
    View for rendering hours as json.
    """
    current_site = Site.find_for_request(request)
    libcalid = get_libcalid(request)
    if request.method == 'GET':
        if request.GET.get('fallback'):
            return JsonResponse({
                'llid':
                get_default_unit().location.libcal_library_id,
            })
        elif libcalid != 'undefined':
            all_building_hours = json.dumps(
                get_building_hours_and_lid(current_site))
            return JsonResponse({
                'all_building_hours':
                all_building_hours,
                'current_hours':
                get_json_hours_by_id(int(libcalid), all_building_hours),
                'llid':
                libcalid,
                'llid_fallback':
                get_default_unit().location.libcal_library_id,
            })
        return JsonResponse({})
Esempio n. 2
0
def json_hours(request):
    """
    View for rendering hours as json. 
    """
    current_site = Site.find_for_request(request)
    if request.method == 'GET':
        if request.GET.get('fallback'):
            fallback = request.GET['fallback']
            return JsonResponse(
                {
                    'llid': get_default_unit().location.libcal_library_id,
                }
            )
        else:
            libcalid = request.GET['libcalid']
            all_building_hours = json.dumps(get_building_hours_and_lid(current_site))
            return JsonResponse(
                {
                    'all_building_hours': all_building_hours,
                    'current_hours': get_json_hours_by_id(int(libcalid), all_building_hours),
                    'llid': libcalid,
                    'llid_fallback': get_default_unit().location.libcal_library_id,
                }
            )
Esempio n. 3
0
    def get_granular_libcal_lid(self, unit):
        """
        Get the most specific libcal library ID
        for the display of the most granular hours. 
        Recurrs up the tree visiting all parent pages
        and looks at unit -> location -> libcal_library_id
        assignments and returnts the first one found.
        If a granular libcal ID isn't found, display
        the default (Regenstein).
        
        Args:
            unit, page object.

        Returns:
            Integer 
        """
        try:
            current_page_id = unit.location.libcal_library_id
            if current_page_id:
                return current_page_id
            else: 
                return self.get_granular_libcal_lid(self.get_parent().unit.location)
        except(AttributeError):
            return get_default_unit().location.libcal_library_id 
Esempio n. 4
0
def get_hours_and_location(obj):
    """
    Gets the page unit, location, hours and the address 
    in one pass. We get these at the same time in order to 
    minimize calls to the database and centralize the display 
    logic since these all need to reach out to unit > location.

    Args:
        obj: page object (self).

    Returns:
        A mixed dictionary of objects and strings formatted for 
        display in the header and footer templates. The hours
        key contains the hours from libcal. The key with
        address information contains the address information
        from the proper location content type.

        Keys:
        ----------------------------------------------------
        page_unit: the unit of the current page or a generic 
        fallback from the config.

        page_location: the location to display based on unit.
        If the page's unit > location is a building e.g.
        is_building = True, then use that location, otherwise
        use unit > location > parent_building. If for some 
        reason nothing is found, use Regenstein.

        hours: get the current building name and hours for
        a page. If the page's unit > location is a building e.g.
        is_building = True, then display the name and hours
        for that location, otherwise pull hours from
        unit > location > parent_building. If for some reason
        nothing is found, use the hours for Regenstein.

        address: the address entry gets the address from the
        same location used to define the libcal hours in the
        previously mentioned hours key.
        ----------------------------------------------------
    """
    # Set unit, location, and hours
    try:
        unit = obj.unit
        location = recursive_get_parent_building(unit.location)
        libcalid = location.libcal_library_id
        #hours = HOURS_TEMPLATE % (str(location), get_hours_by_id(location.libcal_library_id))
    except(AttributeError):
        from units.utils import get_default_unit
        unit = get_default_unit()
        location = fallback = unit.location
        libcalid = fallback.libcal_library_id
        #hours =  HOURS_TEMPLATE % (str(fallback), get_hours_by_id(fallback.libcal_library_id))

    # Set address
    if location.address_2:
        address = location.address_1 + ', ' + location.address_2
    else:
        address = location.address_1

    # Return everything at once
    return {'page_location': location,
            'page_unit' : unit, 
            #'hours': hours, 
            'libcalid': libcalid,
            'address': ADDRESS_TEMPLATE % (address, location.city, location.state, str(location.postal_code)) }
Esempio n. 5
0
def get_hours_and_location(obj):
    """
    Gets the page unit, location, hours and the address 
    in one pass. We get these at the same time in order to 
    minimize calls to the database and centralize the display 
    logic since these all need to reach out to unit > location.

    Args:
        obj: page object (self).

    Returns:
        A mixed dictionary of objects and strings formatted for 
        display in the header and footer templates. The hours
        key contains the hours from libcal. The key with
        address information contains the address information
        from the proper location content type.

        Keys:
        ----------------------------------------------------
        page_unit: the unit of the current page or a generic 
        fallback from the config.

        page_location: the location to display based on unit.
        If the page's unit > location is a building e.g.
        is_building = True, then use that location, otherwise
        use unit > location > parent_building. If for some 
        reason nothing is found, use Regenstein.

        hours: get the current building name and hours for
        a page. If the page's unit > location is a building e.g.
        is_building = True, then display the name and hours
        for that location, otherwise pull hours from
        unit > location > parent_building. If for some reason
        nothing is found, use the hours for Regenstein.

        address: the address entry gets the address from the
        same location used to define the libcal hours in the
        previously mentioned hours key.
        ----------------------------------------------------
    """
    # Set unit, location, and hours
    try:
        unit = obj.unit
        location = recursive_get_parent_building(unit.location)
        libcalid = location.libcal_library_id
        #hours = HOURS_TEMPLATE % (str(location), get_hours_by_id(location.libcal_library_id))
    except(AttributeError):
        from units.utils import get_default_unit
        unit = get_default_unit()
        location = fallback = unit.location
        libcalid = fallback.libcal_library_id
        #hours =  HOURS_TEMPLATE % (str(fallback), get_hours_by_id(fallback.libcal_library_id))

    # Set address
    if location.address_2:
        address = location.address_1 + ', ' + location.address_2
    else:
        address = location.address_1

    # Return everything at once
    return {'page_location': location,
            'page_unit' : unit, 
            #'hours': hours, 
            'libcalid': libcalid,
            'address': ADDRESS_TEMPLATE % (address, location.city, location.state, str(location.postal_code)) }