예제 #1
0
def create_sittings_map(sittings, request):
    """Returns a dictionary that maps:

      (day, hour) -> {
         'record'   : sitting database record
         'actions'  : actions that apply to this sitting
         'class'    : sitting
         'span'     : span
         }
         
      (day, hour) -> ``None``
      
    If the mapped value is a sitting, then a sitting begins on that
    day and hour, if it's ``None``, then a sitting is reaching into
    this day and hour.
    
    The utility of the returned structure is to aid rendering a
    template with columns spanning several rows.
    """

    mapping = {}
    for sitting in sittings.values():
        day = sitting.start_date.weekday()
        hour = sitting.start_date.hour

        start_date = utils.timedict(sitting.start_date.hour, sitting.start_date.minute)

        end_date = utils.timedict(sitting.end_date.hour, sitting.end_date.minute)

        status = misc.get_wf_state(sitting)

        proxied = ProxyFactory(sitting)

        if checkPermission(u"bungeni.agendaitem.wf.schedule", proxied):
            link = "%s/schedule" % url.absoluteURL(sitting, request)
        else:
            link = url.absoluteURL(sitting, request)

        if checkPermission("zope.View", proxied):
            mapping[day, hour] = {
                "url": link,
                "record": sitting,
                "class": u"sitting",
                "actions": get_sitting_actions(sitting, request),
                "span": sitting.end_date.hour - sitting.start_date.hour,
                "formatted_start_time": start_date,
                "formatted_end_time": end_date,
                "status": status,
            }
            for hour in range(sitting.start_date.hour + 1, sitting.end_date.hour):
                mapping[day, hour] = None

        # make sure start- and end-date is the same DAY
        assert (
            (sitting.start_date.day == sitting.end_date.day)
            and (sitting.start_date.month == sitting.end_date.month)
            and (sitting.start_date.year == sitting.end_date.year)
        )

    return mapping
예제 #2
0
def create_sittings_map(sittings, request):
    """Returns a dictionary that maps:

      (day, hour) -> {
         'record'   : sitting database record
         'actions'  : actions that apply to this sitting
         'class'    : sitting
         'span'     : span
         }
         
      (day, hour) -> ``None``
      
    If the mapped value is a sitting, then a sitting begins on that
    day and hour, if it's ``None``, then a sitting is reaching into
    this day and hour.
    
    The utility of the returned structure is to aid rendering a
    template with columns spanning several rows.
    """

    mapping = {}
    for sitting in sittings.values():
        day = sitting.start_date.weekday()
        hour = sitting.start_date.hour

        start_date = utils.timedict(sitting.start_date.hour,
                                    sitting.start_date.minute)

        end_date = utils.timedict(sitting.end_date.hour,
                                  sitting.end_date.minute)

        status = misc.get_wf_state(sitting)

        proxied = ProxyFactory(sitting)

        if checkPermission(u"bungeni.agendaitem.Schedule", proxied):
            link = "%s/schedule" % ui_url.absoluteURL(sitting, request)
        else:
            link = ui_url.absoluteURL(sitting, request)

        if checkPermission("zope.View", proxied):
            mapping[day, hour] = {
                'url': link,
                'record': sitting,
                'class': u"sitting",
                'actions': get_sitting_actions(sitting, request),
                'span': sitting.end_date.hour - sitting.start_date.hour,
                'formatted_start_time': start_date,
                'formatted_end_time': end_date,
                'status': status,
            }
            for hour in range(sitting.start_date.hour + 1,
                              sitting.end_date.hour):
                mapping[day, hour] = None

        # make sure start- and end-date is the same DAY
        assert (sitting.start_date.day == sitting.end_date.day) and \
               (sitting.start_date.month == sitting.end_date.month) and \
               (sitting.start_date.year == sitting.end_date.year)

    return mapping