示例#1
0
 def occurrences(self):
     if not self.data.is_event: return None
     rec = IRecurrenceSupport(self.context, None)
     if rec:
         return rec.occurrences()
     else:
         return None
示例#2
0
    def next_occurrences(self):
        """Returns occurrences for this context, except the start
        occurrence, limited to self.max_occurrence occurrences.

        :returns: List with next occurrences.
        :rtype: list
        """
        occurrences = []
        adapter = IRecurrenceSupport(self.event_context, None)
        if adapter:
            for cnt, occ in enumerate(adapter.occurrences(range_start=self.data.start)):
                if cnt == self.max_occurrences:
                    break
                occurrences.append(occ)
        return occurrences
示例#3
0
    def next_occurrences(self):
        """Returns occurrences for this context, except the start
        occurrence, limited to self.max_occurrence occurrences.

        :returns: List with next occurrences.
        :rtype: list
        """
        occurrences = []
        adapter = IRecurrenceSupport(self.event_context, None)
        if adapter:
            for cnt, occ in enumerate(adapter.occurrences()):
                if cnt == self.max_occurrences:
                    break
                occurrences.append(occ)
        return occurrences
示例#4
0
    def next_occurrences(self):
        """Returns occurrences for this context, except the start
        occurrence, limited to self.num_occurrences occurrences.

        :returns: List with next occurrences.
        :rtype: list
        """
        occurrences = []
        adapter = IRecurrenceSupport(self.context, None)
        if adapter:
            for cnt, occ in enumerate(adapter.occurrences()):
                if cnt == self.max_occurrences + 1:
                    break
                elif cnt == 0:
                    continue
                occurrences.append(occ)
        return occurrences
示例#5
0
    def next_occurrences(self):
        """Returns occurrences for this context, except the start
        occurrence, limited to self.max_occurrence occurrences.

        :returns: List with next occurrences.
        :rtype: list
        """
        occurrences = []
        adapter = IRecurrenceSupport(self.event_context, None)
        if adapter:
            cnt_future_occ = 0
            for occ in adapter.occurrences():
                if cnt_future_occ == self.max_occurrences:
                    break
                if occ.end >= datetime.utcnow().replace(tzinfo=pytz.utc):
                    cnt_future_occ += 1
                    occurrences.append(occ)
        return occurrences
示例#6
0
 def create_ticket_occurrences(self):
     tickets = self.tickets
     recurrence = IRecurrenceSupport(self.context)
     for occurrence in recurrence.occurrences():
         if not isinstance(occurrence, Occurrence):
             continue
         for ticket in tickets:
             if occurrence.id in ticket.objectIds():
                 continue
             ticket.invokeFactory('Ticket Occurrence',
                                  occurrence.id,
                                  title=ticket.Title())
             ticket_occurrence = ticket[occurrence.id]
             self._copy_field_value(ticket, ticket_occurrence,
                                    'item_available')
             self._copy_field_value(ticket, ticket_occurrence,
                                    'item_overbook')
             ticket_occurrence.reindexObject()
示例#7
0
    def next_occurrences(self):
        """Returns occurrences for this context, except the start
        occurrence, limited to self.max_occurrence occurrences.

        :returns: List with next occurrences.
        :rtype: list
        """
        occurrences = []
        adapter = IRecurrenceSupport(self.event_context, None)
        if adapter:
            cnt_future_occ = 0
            for occ in adapter.occurrences():
                if cnt_future_occ == self.max_occurrences:
                    break
                if occ.end >= datetime.utcnow().replace(tzinfo=pytz.utc):
                    cnt_future_occ += 1
                    occurrences.append(occ)
        return occurrences
 def create_ticket_occurrences(self):
     tickets = self.tickets
     recurrence = IRecurrenceSupport(self.context)
     for occurrence in recurrence.occurrences():
         if not isinstance(occurrence, Occurrence):
             continue
         for ticket in tickets:
             if occurrence.id in ticket.objectIds():
                 continue
             ticket.invokeFactory(
                 'Ticket Occurrence',
                 occurrence.id,
                 title=ticket.Title())
             ticket_occurrence = ticket[occurrence.id]
             self._copy_field_value(
                 ticket, ticket_occurrence, 'item_available')
             self._copy_field_value(
                 ticket, ticket_occurrence, 'item_overbook')
             ticket_occurrence.reindexObject()
示例#9
0
    def occurrences(self):
        """Returns all occurrences for this context, except the start
        occurrence.
        The maximum defaults to 7 occurrences. If there are more occurrences
        defined for this context, the result will contain the last item
        of the occurrence list.

        :rtype: dict - with ``events`` and ``tail`` as keys.

        """
        eventsinfo = dict(events=[], tail=None)
        context = self.context
        adapter = IRecurrenceSupport(context, None)
        if adapter is not None:
            occurrences = adapter.occurrences()[1:] # don't include first
            eventsinfo['events'], eventsinfo['tail'] = (
                self._get_occurrences_helper(occurrences)
            )
        return eventsinfo
示例#10
0
    def next_occurrences(self):
        """Returns all occurrences for this context, except the start
        occurrence.
        The maximum defaults to 7 occurrences. If there are more occurrences
        defined for this context, the result will contain the last item
        of the occurrence list.

        :returns: Dictionary with ``events`` and ``tail`` as keys.
        :rtype: dict

        """
        occ_dict = dict(events=[], tail=None)
        context = self.context
        adapter = IRecurrenceSupport(context, None)
        if adapter is not None:
            occurrences = adapter.occurrences()[1:]  # don't include first
            occ_dict['events'], occ_dict['tail'] = (
                self._get_occurrences_helper(occurrences))
        return occ_dict
示例#11
0
文件: views.py 项目: eea/eionet.theme
    def generate_source_dict_from_event(self, event):
        """generate_source_dict_from_event.

        :param event:
        """
        view = self.request.get('view')
        ret = []
        title = event.Title()
        description = event.Description()

        if event.text:
            description = event.text.output
        editable = api.user.has_permission('Modify portal content', obj=event)
        deletable = api.user.has_permission('Delete objects', obj=event)
        color = 'grey'
        if event.tag:
            for _view_type, group_color, categories in CATEGORIES:
                for cat_id, _cat_title in categories:
                    if cat_id in event.tag:
                        color = group_color
                        break
        else:
            # for events imported from ICS
            for _view_type, group_color, categories in CATEGORIES:
                for cat_id, _cat_tile in categories:
                    for tag in event.subject:
                        if cat_id == tag.lower():
                            color = group_color
                            break

        adapter = IRecurrenceSupport(event)
        # get all occurrences of the current event (if not recurrent,
        # the generator will only produce the event itself) and create a
        # results entry for each one
        for occurrence in adapter.occurrences(
                range_start=DateTime(self.request.get('start')),
                range_end=DateTime(self.request.get('end'))):
            # The default source marks an event as all day if it is longer than
            # one day. Marking an event as all day in contentpage will set
            # the times to 00:00 and 23:59. If those times are on the same
            # date they will not be recognised as all day because that's only a
            # 0.999.. day. This check will mark those events as all day.
            start = occurrence.start
            end = occurrence.end
            duration = occurrence.end - occurrence.start
            if isinstance(duration, timedelta):
                duration = duration.total_seconds() / 60. / 60. / 24.
            # compute real all day for the tooltip information
            real_allday = (event.whole_day or
                           duration > 0.99 or
                           start == end or
                           occurrence.start.date() != occurrence.end.date())
            # For the main calendar_view we set all events to allday because we
            # don't show start and end times anyway and we need the background
            # color that only appears on full day events.
            if view == 'calendar_view':
                allday = True
                end += timedelta(days=1)
            else:
                # on all other views we need the allday to be correct
                allday = real_allday
            iso = 'isoformat' if hasattr(start, 'isoformat') else 'ISO8601'
            start = getattr(start, iso)()
            end = getattr(end, iso)()

            ret.append({
                "id": "UID_%s" % (event.UID()),
                "title": title,
                "start": start,
                "end": end,
                "url": event.absolute_url(),
                "can_edit": editable,
                "can_delete": deletable,
                "backgroundColor": color,
                "allDay": allday,
                "realAllDay": real_allday,
                "className": "state-" + str(get_state(event)) +
                (editable and " editable" or ""),
                "description": description,
                "location": event.location,
                "realStartTime": occurrence.start.strftime('%H:%M'),
                "realEndTime": occurrence.end.strftime('%H:%M'),
                "realStartDate": occurrence.start.strftime('%B %d'),
                "realEndDate": occurrence.end.strftime('%B %d'),
                "oneday": occurrence.start.date() == occurrence.end.date()
            })
        return ret