def query_filter_date_range(context, request, query, domain_model):
    """Add date range filter to query:
    - if the model has start & end dates, constrain the query to objects 
      appearing within those dates.
    - else (archive section) pick off start/end date from the request's cookies
    - else try getting a display date off request
    """
    if ((ufaces.IBusinessSectionLayer.providedBy(request) and (
            mfaces.ICommitteeContainer.providedBy(context) or 
            mfaces.ICommitteeMemberContainer.providedBy(context) or
            mfaces.ICommitteeStaffContainer.providedBy(context))
        ) or
        (ufaces.IMembersSectionLayer.providedBy(request) and
            mfaces.IMemberOfParliamentContainer.providedBy(context))
    ):
        start_date, end_date = datetime.date.today(), None
    elif ufaces.IArchiveSectionLayer.providedBy(request):
        start_date, end_date = cookies.get_date_range(request)
    else:
        start_date, end_date = date.getDisplayDate(request), None
    
    if not start_date and not end_date:
        return query
    elif not start_date:
        start_date = datetime.date(1900, 1, 1)
    elif not end_date:
        end_date = datetime.date(2100, 1, 1)
    
    date_range_filter = component.getSiteManager().adapters.lookup(
        (interface.implementedBy(domain_model),), mfaces.IDateRangeFilter)
    if date_range_filter is not None:
        query = query.filter(date_range_filter(domain_model)).params(
            start_date=start_date, end_date=end_date)
    return query
Beispiel #2
0
def query_filter_date_range(context, request, query, domain_model):
    """Add date range filter to query:
    - if the model has start & end dates, constrain the query to objects 
      appearing within those dates.
    - else (archive section) pick off start/end date from the request's cookies
    - else try getting a display date off request
    """
    if ((ufaces.IBusinessSectionLayer.providedBy(request) and
         (mfaces.ICommitteeContainer.providedBy(context)
          or mfaces.ICommitteeMemberContainer.providedBy(context)
          or mfaces.ICommitteeStaffContainer.providedBy(context)))
            or (ufaces.IMembersSectionLayer.providedBy(request)
                and mfaces.IMemberOfParliamentContainer.providedBy(context))):
        start_date, end_date = datetime.date.today(), None
    elif ufaces.IArchiveSectionLayer.providedBy(request):
        start_date, end_date = cookies.get_date_range(request)
    else:
        start_date, end_date = date.getDisplayDate(request), None

    if not start_date and not end_date:
        return query
    elif not start_date:
        start_date = datetime.date(1900, 1, 1)
    elif not end_date:
        end_date = datetime.date(2100, 1, 1)

    date_range_filter = component.getSiteManager().adapters.lookup(
        (interface.implementedBy(domain_model), ), mfaces.IDateRangeFilter)
    if date_range_filter is not None:
        query = query.filter(date_range_filter(domain_model)).params(
            start_date=start_date, end_date=end_date)
    return query
Beispiel #3
0
def dateFilter(request):
    filter_by = ""
    displayDate = date.getDisplayDate(request)
    if displayDate:
        filter_by = date.getFilter(displayDate)
    else:
        filter_by = ""
    return filter_by
Beispiel #4
0
 def _getDisplayDate(self, request):
     display_date = date.getDisplayDate(self.request)
     session = self.context
     if display_date:
         if session.end_date:
             if display_date > session.end_date:
                 display_date = session.end_date
         if session.start_date > display_date:
             display_date = session.start_date
     else:
         display_date = session.end_date
     return display_date
Beispiel #5
0
 def _getDisplayDate(self, request):
     display_date = date.getDisplayDate(self.request)
     session = self.context
     if display_date:
         if session.end_date:
             if display_date > session.end_date:
                 display_date = session.end_date
         if session.start_date > display_date:
             display_date = session.start_date
     else:
         display_date = session.end_date
     return display_date
def dateFilter(request):
    displayDate = date.getDisplayDate(request)
    if displayDate:
        return date.getFilter(displayDate)
    return ""
Beispiel #7
0
def dateFilter(request):
    displayDate = date.getDisplayDate(request)
    if displayDate:
        return date.getFilter(displayDate)
    return ""