Exemple #1
0
    def create_event(self, context, id='e1', title='New event', days=(1, 1), start=0, end=1, whole_day=False, open_end=False):
        now = localized_now().replace(minute=0, second=0, microsecond=0)
        if now.day > 30:
            target_day_start = 1
            target_day_end = 1 + days[1]
        else:
            target_day_start = now.day + days[0]
            target_day_end = now.day + days[1]
        if now.hour == 23:
            target_hour_start = 1
            target_hour_end = 2
        else:
            target_hour_start = now.hour + start
            target_hour_end = now.hour + end

        start = localized_now().replace(day=target_day_start, hour=target_hour_start)
        end = localized_now().replace(day=target_day_end, hour=target_hour_end)

        EventAccessor.event_type = 'Event'
        acc = EventAccessor.create(
            container=context,
            content_id=id,
            title=title,
            start=start,
            end=end,
            timezone=TZNAME,
            whole_day=whole_day,
            open_end=open_end
        )
        acc.location = u"Graz, Austria"

        return context[id]
    def events(self):
        context = aq_inner(self.context)
        data = self.data

        query = {}
        if data.state:
            query['review_state'] = data.state

        events = []
        query.update(self.request.get('contentFilter', {}))
        search_base = self.search_base
        if ICollection and ICollection.providedBy(search_base):
            # Whatever sorting is defined, we're overriding it.
            query = queryparser.parseFormquery(
                search_base, search_base.query,
                sort_on='start', sort_order=None
            )

            start = None
            if 'start' in query:
                start = query['start']
            else:
                start = localized_now(context)

            end = None
            if 'end' in query:
                end = query['end']

            start, end = _prepare_range(search_base, start, end)
            query.update(start_end_query(start, end))
            events = search_base.results(
                batch=False, brains=True, custom_query=query,
                limit=data.count
            )
            events = expand_events(
                events, ret_mode=RET_MODE_ACCESSORS,
                start=start, end=end,
                sort='start', sort_reverse=False
            )
            events = events[:data.count]  # limit expanded
        else:
            search_base_path = self.search_base_path
            if search_base_path:
                query['path'] = {'query': search_base_path}
            events = get_events(
                context, start=localized_now(context),
                ret_mode=RET_MODE_ACCESSORS,
                expand=True, limit=data.count, **query
            )
            eventlist=[]
            for ev in events:
                hasimage = bool(getattr(ev.context, 'image', None))
                eventlist.append((ev, hasimage))
        return eventlist
    def events(self):
        """
        Return the events in this workspace
        to be shown in the events section of the sidebar
        """
        catalog = api.portal.get_tool('portal_catalog')
        workspace = parent_workspace(self.context)
        workspace_path = '/'.join(workspace.getPhysicalPath())
        now = localized_now()

        # Current and future events
        upcoming_events = catalog.searchResults(
            object_provides=IEvent.__identifier__,
            path=workspace_path,
            end={'query': now, 'range': 'min'},
            sort_on='start',
            sort_order='descending',
        )

        # Events which have finished
        older_events = catalog.searchResults(
            object_provides=IEvent.__identifier__,
            path=workspace_path,
            end={'query': now, 'range': 'max'},
            sort_on='start',
            sort_order='descending',
        )
        return {'upcoming': upcoming_events, 'older': older_events}
Exemple #4
0
    def __init__(self, context, request):
        super(EventListing, self).__init__(context, request)

        self.now = now = localized_now(context)
        self.settings = IEventListingSettings(self.context)

        # Request parameter
        req = self.request.form
        self.b_start = 'b_start' in req and int(req['b_start']) or 0
        self.b_size = 'b_size' in req and int(req['b_size']) or 10
        self.orphan = 'orphan' in req and int(req['orphan']) or 1
        self.mode = 'mode' in req and req['mode'] or None
        self._date = 'date' in req and req['date'] or None
        self.tags = 'tags' in req and req['tags'] or None
        self.searchable_text = 'SearchableText' in req and\
            req['SearchableText'] or None
        self.path = 'path' in req and req['path'] or None

        day = 'day' in req and int(req['day']) or None
        month = 'month' in req and int(req['month']) or None
        year = 'year' in req and int(req['year']) or None

        if not self._date and day or month or year:
            self._date = date(year or now.year,
                              month or now.month,
                              day or now.day).isoformat()

        if self.mode is None:
            self.mode = self._date and 'day' or 'future'

        self.uid = None  # Used to get all occurrences from a single event.
def caseworkspaces_spec(context):
    now = localized_now()
    caseworkspaces = [{
        'title': 'Example Case',
        'description': 'A case management workspace demonstrating the '
                       'adaptive case management functionality.',
        'members': {'allan_neece': [u'Members'],
                    'christian_stoney': [u'Admins', u'Members']},
        'contents': [{
            'title': 'Populate Metadata',
            'type': 'todo',
            'description': 'Retrieve and assign metadata',
            'milestone': 'new',
        }, {
            'title': 'Identify the requirements',
            'type': 'todo',
            'description': 'Investigate the request and identify requirements',
            'milestone': 'in_progress',
        }, {
            'title': 'Future Meeting',
            'type': 'Event',
            'start': now + timedelta(days=7),
            'end': now + timedelta(days=14)
        }, {
            'title': 'Past Meeting',
            'type': 'Event',
            'start': now + timedelta(days=-7),
            'end': now + timedelta(days=-14)
        }],
    }]
    return caseworkspaces
 def test_start_defaults(self):
     data = MockEvent()
     data.context = MockEvent()
     default_value = default_start(data)
     today = localized_now()
     delta = default_value - today
     self.assertEquals(0, delta.seconds)
 def test_start_defaults(self):
     data = MockEvent()
     data.context = MockEvent()
     default_value = default_start(data)
     now = localized_now().replace(minute=0, second=0, microsecond=0)
     delta = default_value - now
     self.assertEqual(0, delta.seconds)
    def __init__(self, context, request):
        super(EventListing, self).__init__(context, request)

        self.now = now = localized_now(context)

        # Request parameter
        req = self.request.form
        self.b_start = int(req['b_start']) if 'b_start' in req else 0
        self.b_size  = int(req['b_size'])  if 'b_size'  in req else 10
        self.orphan  = int(req['orphan'])  if 'orphan'  in req else 1
        self.mode    = req['mode'] if 'mode' in req else None
        self._date   = req['date'] if 'date' in req else None
        self.tags    = req['tags'] if 'tags' in req else None
        self.searchable_text = req['SearchableText'] if 'SearchableText' in req else None  # noqa
        self.path    = req['path'] if 'path' in req else None

        day   = int(req['day'])   if 'day'   in req else None
        month = int(req['month']) if 'month' in req else None
        year  = int(req['year'])  if 'year'  in req else None

        if not self._date and day or month or year:
            self._date = date(year or now.year,
                              month or now.month,
                              day or now.day).isoformat()

        if self.mode is None:
            self.mode = 'day' if self._date else 'future'

        self.uid = None  # Used to get all occurrences from a single event. Overrides all other settings  # noqa
Exemple #9
0
    def get_next_three_events(self):
        context = aq_inner(self.context)
        pc = getToolByName(context, 'portal_catalog')
        now = localized_now()

        portal_state = getMultiAdapter((self.context, self.request), name='plone_portal_state')
        navigation_root_path = portal_state.navigation_root_path()

        context = aq_inner(self.context)
        path = navigation_root_path
        for obj in aq_chain(context):
            if ICommunity.providedBy(obj):
                community = aq_inner(obj)
                path = '/'.join(community.getPhysicalPath())

        query = {
            'portal_type': 'Event',
            'review_state': self.state,
            'end': {'query': now, 'range': 'min'},
            'sort_on': 'start',
            'path': path,
        }

        result = pc(**query)
        nearest = self.get_nearest_today_event()
        if nearest:
            return [event for event in result if event.id != nearest.id][:3]
        else:
            return result[:3]
Exemple #10
0
    def get_nearest_today_event(self):
        context = aq_inner(self.context)
        pc = getToolByName(context, 'portal_catalog')
        now = localized_now()

        portal_state = getMultiAdapter((self.context, self.request), name='plone_portal_state')
        navigation_root_path = portal_state.navigation_root_path()

        context = aq_inner(self.context)
        path = navigation_root_path
        for obj in aq_chain(context):
            if ICommunity.providedBy(obj):
                community = aq_inner(obj)
                path = '/'.join(community.getPhysicalPath())

        query = {
            'portal_type': 'Event',
            'review_state': self.state,
            'start': {'query': [now, dt_end_of_day(now)], 'range': 'min:max'},
            'end': {'query': now, 'range': 'min'},
            'sort_on': 'start',
            'path': path,
            'sort_limit': 1
        }

        result = pc(**query)
        if result:
            return result[0]
        else:
            return
def caseworkspaces_spec(context):
    now = localized_now()
    # use template todos as a base
    base_contents = case_templates_spec(context)[0]['contents']
    for todo in base_contents:
        todo['initiator'] = 'christian_stoney'
    for i in range(2):
        base_contents[i]['state'] = 'done'
    for i in range(4):
        base_contents[i]['assignee'] = random.choice(['dollie_nocera',
                                                      'allan_neece'])
    for i in range(6):
        base_contents[i]['due'] = now + timedelta(days=i * 2)

    caseworkspaces = [{
        'title': 'Example Case',
        'description': 'A case management workspace demonstrating the '
                       'adaptive case management functionality.',
        'state': 'prepare',
        'members': {'allan_neece': [u'Members'],
                    'dollie_nocera': [u'Members'],
                    'christian_stoney': [u'Admins', u'Members']},
        'contents': base_contents + [{
            'title': 'Future Meeting',
            'type': 'Event',
            'start': now + timedelta(days=7),
            'end': now + timedelta(days=14)
        }, {
            'title': 'Past Meeting',
            'type': 'Event',
            'start': now + timedelta(days=-7),
            'end': now + timedelta(days=-14)
        }],
    }]
    return caseworkspaces
 def test_end_default(self):
     data = MockEvent()
     data.context = MockEvent()
     default_value = default_end(data)
     today = localized_now()
     delta = default_value - today
     self.assertEquals(3600, delta.seconds)
    def __init__(self, context, request):
        super(EventListing, self).__init__(context, request)

        self.now = now = localized_now(context)

        # Batch parameter
        req = self.request.form
        self.b_start = 'b_start' in req and int(req['b_start']) or 0
        self.b_size  = 'b_size'  in req and int(req['b_size'])  or 10
        self.orphan  = 'orphan'  in req and int(req['orphan'])  or 1
        self.mode    = 'mode'    in req and req['mode']         or None
        self._date   = 'date'    in req and req['date']         or None
        self._all    = 'all'     in req and True                or False

        day   = 'day'   in req and int(req['day'])   or None
        month = 'month' in req and int(req['month']) or None
        year  = 'year'  in req and int(req['year'])  or None

        if not self._date and day or month or year:
            self._date = date(year or now.year,
                              month or now.month,
                              day or now.day).isoformat()

        if self.mode == None:
            self.mode = self._date and 'day' or 'future'
    def __init__(self, context, request):
        super(EventListing, self).__init__(context, request)

        self.now = now = localized_now(context)
        self.settings = IEventListingSettings(self.context)

        # Batch parameter
        req = self.request.form
        self.b_start = 'b_start' in req and int(req['b_start']) or 0
        self.b_size  = 'b_size'  in req and int(req['b_size'])  or 10
        self.orphan  = 'orphan'  in req and int(req['orphan'])  or 1
        self.mode    = 'mode'    in req and req['mode']         or None
        self._date   = 'date'    in req and req['date']         or None
        self.tags    = 'tags'    in req and req['tags']         or None
        self.searchable_text = 'SearchableText' in req and\
                req['SearchableText'] or None
        self.path    = 'path'    in req and req['path']         or None
        if self.settings.language_neutral:
             ptool = getToolByName(context, 'portal_url')
             self.path = ptool.getPortalPath()

        day   = 'day'   in req and int(req['day'])   or None
        month = 'month' in req and int(req['month']) or None
        year  = 'year'  in req and int(req['year'])  or None

        if not self._date and day or month or year:
            self._date = date(year or now.year,
                              month or now.month,
                              day or now.day).isoformat()

        if self.mode == None:
            self.mode = self._date and 'day' or 'future'
    def update(self):
        try:
            self.now = now = self.context.start
        except:
            self.now = now = localized_now(self.context)

        # Request parameter
        req = self.request.form
        self.b_start = 'b_start' in req and int(req['b_start']) or 0
        self.b_size = 'b_size' in req and int(req['b_size']) or 10
        self.orphan = 'orphan' in req and int(req['orphan']) or 1
        self.mode = 'mode' in req and req['mode'] or None
        self._date = 'date' in req and req['date'] or None
        self.tags = 'tags' in req and req['tags'] or None
        self.searchable_text = 'SearchableText' in req and\
            req['SearchableText'] or None
        self.path = 'path' in req and req['path'] or None

        day = 'day' in req and int(req['day']) or None
        month = 'month' in req and int(req['month']) or None
        year = 'year' in req and int(req['year']) or None

        if not self._date and day or month or year:
            self._date = date(year or now.year,
                              month or now.month,
                              day or now.day).isoformat()
        if self.mode is None:
            self.mode = self._date and 'day' or 'future'
    def test_portlet_event_renderer__recurring(self):
        start = localized_now() + timedelta(days=1)

        e1 = createContentInContainer(
            self.portal, PTYPE, id='e1', title=u'Event 1', start=start,
            recurrence='RRULE:FREQ=WEEKLY;COUNT=10')
        createContentInContainer(
            self.portal, PTYPE, id='e1', title=u'Event 1', start=start,
            recurrence='RRULE:FREQ=DAILY;COUNT=3')

        self.portal.portal_workflow.doActionFor(e1, 'publish')

        r = self.renderer(
            assignment=portlet_events.Assignment(count=5,
                                                 state=('published',)))
        r.update()
        events = r.events
        self.assertEqual(5, len(events))
        self.assertTrue('Event 2' not in [x.title for x in events])

        rd = r.render()
        occ1dt = start + timedelta(days=7)
        # The first occurrence of the event itself should show up. It should
        # link to the event and not an occurrence.
        self.assertTrue('http://nohost/plone/e1"' in rd)
        # Occurrences should link to the Occurrence.
        self.assertTrue(
            'http://nohost/plone/e1/%s-%02d-%02d' %
            (occ1dt.year, occ1dt.month, occ1dt.day) in rd
        )
    def test_default_start_DT(self):
        DTS = default_start_DT()
        DTN = DT(localized_now())

        self.assertTrue(DTS.year() == DTN.year() and
                        DTS.month() == DTN.month() and
                        DTS.day() == DTN.day() and
                        DTS.hour() == DTN.hour() and
                        DTS.minute() == DTN.minute())
    def test_default_end_DT(self):
        DTE = default_end_DT()
        DTN = DT(localized_now() + datetime.timedelta(hours=DEFAULT_END_DELTA))

        self.assertTrue(DTE.year() == DTN.year() and
                        DTE.month() == DTN.month() and
                        DTE.day() == DTN.day() and
                        DTE.hour() == DTN.hour() and
                        DTE.minute() == DTN.minute())
Exemple #19
0
 def _recurrence_upcoming_event(self):
     """Return the next upcoming event"""
     adapter = IRecurrenceSupport(self.context)
     occs = adapter.occurrences(range_start=localized_now())
     try:
         return next(occs)
     except StopIteration:
         # No more future occurrences: passed event
         return IEventBasic(self.context)
    def test_view_get_data_startdate(self):
        future = localized_now() + datetime.timedelta(days=5)
        form = dict(start=str(future.date()))
        request = TestRequest(form=form)
        view = zope.component.getMultiAdapter(
            (self.portal, request), name='occurrences.html')

        result = view.get_data()
        self.assertEqual(2, result.length)
Exemple #21
0
 def events(self):
     context = aq_inner(self.context)
     portal = api.portal.get()
     container = portal["termine"]
     kw = {}
     kw["path"] = dict(query="/".join(container.getPhysicalPath()), depth=1)
     kw["review_state"] = "published"
     items = get_events(
         context, start=localized_now(context), ret_mode=RET_MODE_ACCESSORS, expand=True, limit=3, **kw
     )
     return items
    def events(self):
        context = aq_inner(self.context)
        data = self.data

        kw = {}
        if data.search_base:
            kw["path"] = {"query": "%s%s" % ("/".join(self.portal.getPhysicalPath()), data.search_base)}
        if data.state:
            kw["review_state"] = data.state

        return get_events(context, start=localized_now(context), ret_mode=3, expand=True, limit=data.count, **kw)
Exemple #23
0
 def published_events_expanded(self):
     """
     Return expanded ongoing events, i.e. taking into account their
     occurrences in case they are recurrent events.
     """
     return [self.event_to_view_obj(event) for event in get_events(
         self.context,
         ret_mode=2,
         start=localized_now(),
         expand=True,
         sort='start',
         limit=self.data.count,
         review_state=self.data.state)]
    def events(self):
        context = aq_inner(self.context)
        data = self.data

        kw = {}
        if data.search_base:
            kw['path'] = {'query': '%s%s' % (
                '/'.join(self.portal.getPhysicalPath()), data.search_base)}
        if data.state:
            kw['review_state'] = data.state

        return get_events(context, start=localized_now(context),
                          ret_mode=3, expand=True, limit=data.count, **kw)
Exemple #25
0
    def upcoming_events(self):
        """
        Return the events in this workspace
        to be shown in the events section of the sidebar
        """
        catalog = api.portal.get_tool('portal_catalog')
        now = localized_now()

        upcoming_events = catalog.searchResults(
            object_provides=IEvent.__identifier__,
            end={'query': now, 'range': 'min'},
        )
        return upcoming_events
    def events(self):
        context = aq_inner(self.context)
        data = self.data

        kw = {}
        search_base_path = self.search_base_path()
        if search_base_path:
            kw['path'] = {'query': search_base_path}
        if data.state:
            kw['review_state'] = data.state

        return get_events(context, start=localized_now(context),
                          ret_mode=RET_MODE_ACCESSORS,
                          expand=True, limit=data.count, **kw)
    def create_event(self, context, id='e1', title='New event', days=(1, 1), start=0, end=1, whole_day=False, open_end=False):
        """ Creates an event with delta days tuple (start, end) beggining from
            now. The start and end arguments are also treated as delta hours.
        """
        delta_start = timedelta(hours=start, days=days[0])
        delta_end = timedelta(hours=end, days=days[1])

        start = localized_now() + delta_start
        end = localized_now() + delta_end

        EventAccessor.event_type = 'Event'
        acc = EventAccessor.create(
            container=context,
            content_id=id,
            title=title,
            start=start,
            end=end,
            timezone=TZNAME,
            whole_day=whole_day,
            open_end=open_end
        )
        acc.location = u'Graz, Austria'

        return context[id]
Exemple #28
0
    def _data(self):
        context = aq_inner(self.context)
        catalog = getToolByName(context, 'portal_catalog')
        limit = self.data.count
        state = self.data.state

        now = localized_now()
        tomorrow = date.today() + timedelta(1)
        yesterday = date.today() - timedelta(1)

        results = catalog(portal_type='Event',
                          review_state=state,
                          end={'query': now,
                               'range': 'min'},
                          start={'query': [yesterday, tomorrow],
                                 'range': 'min:max'},
                          Language=pref_lang(),
                          sort_on='start',
                          sort_limit=limit)[:limit]
        count = len(results)
        if count < limit:
            results2 = catalog(portal_type=('Event'),
                               review_state=state,
                               end={'query': now,
                                    'range': 'min'},
                               start={'query': yesterday,
                                      'range': 'max'},
                               Language=pref_lang(),
                               sort_on='start',
                               sort_limit=limit - count)[:limit - count]
            count = len(results + results2)
            if count < limit:
                results3 = catalog(portal_type=('Event'),
                                   review_state=state,
                                   end={'query': now,
                                        'range': 'min'
                                        },
                                   start={'query': tomorrow,
                                          'range': 'min'},
                                   Language=pref_lang(),
                                   sort_on='start',
                                   sort_limit=limit - count)[:limit - count]
                return results + results2 + results3
            else:
                return results + results2
        else:
            return results
Exemple #29
0
    def events(self):
        context = aq_inner(self.context)
        data = self.data

        kw = {}
        search_base_path = self.search_base_path()
        if search_base_path:
            kw['path'] = {'query': search_base_path}
        if data.state:
            kw['review_state'] = data.state

        return get_events(context,
                          start=localized_now(context),
                          ret_mode=RET_MODE_ACCESSORS,
                          expand=True,
                          limit=data.count,
                          **kw)
Exemple #30
0
    def upcoming_events(self):
        """
        Return the events in this workspace
        to be shown in the events section of the sidebar
        """
        catalog = api.portal.get_tool('portal_catalog')
        now = localized_now()

        upcoming_events = catalog.searchResults(
            object_provides=IEvent.__identifier__,
            end={
                'query': now,
                'range': 'min'
            },
            sort_on='start',
            sort_order='ascending',
        )
        return upcoming_events
Exemple #31
0
    def get_authenticated_events(self):
        """ Load events from solr """
        # We only provide a history of 30 days, otherwise, fullcalendar has
        # too much to render. This could be made more flexible
        user = api.user.get_current()
        if not user:
            return []

        fullcalendar_day_span = api.portal.get_registry_record(
            'ploneintranet.calendar.fullcalendar_day_span',
            default=30,
        )
        evt_date = localized_now() - timedelta(fullcalendar_day_span)
        query = dict(object_provides=IEvent.__identifier__,
                     end__gt=solr_date(evt_date))
        query['is_archived'] = False

        sitesearch = getUtility(ISiteSearch)
        return sitesearch.query(filters=query, step=99999)
Exemple #32
0
 def setUp(self):
     super(TestDashboard, self).setUp()
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     self.account = addAccount(password="******")
     # We setup two surveys, an archived one and one which is not archived
     survey_session = model.SurveySession(
         title="Dummy session 1",
         zodb_path="nl/ict/software-development",
         account=self.account,
     )
     model.Session.add(survey_session)
     survey_session = model.SurveySession(
         title="Dummy session 2",
         zodb_path="nl/ict/software-development",
         account=self.account,
     )
     survey_session.archived = localized_now() - timedelta(days=1)
     model.Session.add(survey_session)
    def _data(self):
        context = aq_inner(self.context)
        data = self.data

        query_kw = {}
        if data.search_base:
            query_kw['path'] = {'query': '%s%s' % (
                '/'.join(self.portal.getPhysicalPath()), data.search_base)}

        if data.state:
            query_kw['review_state'] = data.state

        ret = get_portal_events(
                context,
                range_start=localized_now(context),
                limit=data.count,
                **query_kw)

        return ret
    def test_portlet_event_renderer__get_events(self):
        start = localized_now()
        end = start + timedelta(hours=1)

        e1 = createContentInContainer(
            self.portal, PTYPE,
            id='e1', title=u'e1', start=start, end=end)
        self.portal.portal_workflow.doActionFor(e1, 'publish')

        self.portal.invokeFactory('Folder', 'eventfolder')
        createContentInContainer(
            self.portal.eventfolder, PTYPE,
            id='e2', title=u'e2', start=start, end=end)

        r = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=('draft',)))
        r.update()
        self.assertEqual(0, len(r.events))

        r = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=('published', )))
        r.update()
        self.assertEqual(1, len(r.events))

        r = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=('published', 'private',)))
        r.update()
        self.assertEqual(2, len(r.events))

        r = self.renderer(assignment=portlet_events.Assignment(count=5))
        r.update()
        self.assertEqual(2, len(r.events))

        # No search base gives calendar urls with event_listing part
        self.assertTrue('event_listing' in r.render())

        r = self.renderer(assignment=portlet_events.Assignment(
            count=5, search_base_uid=self.portal.eventfolder.UID()))
        r.update()
        self.assertEqual(1, len(r.events))

        # A given search base gives calendar urls without event_listing part
        self.assertTrue('event_listing' not in r.render())
def caseworkspaces_spec(context):
    now = localized_now()
    today = date.today()
    # use template todos as a base
    base_contents = case_templates_spec(context)[0]['contents']
    for todo in base_contents:
        todo['initiator'] = 'christian_stoney'
    for i in range(2):
        base_contents[i]['state'] = 'done'
    for i in range(4):
        base_contents[i]['assignee'] = random.choice(
            ['dollie_nocera', 'allan_neece'])
    for i in range(6):
        base_contents[i]['due'] = today + timedelta(days=i * 2)

    caseworkspaces = [{
        'title':
        'Example Case',
        'description':
        'A case management workspace demonstrating the '
        'adaptive case management functionality.',
        'state':
        'prepare',
        'members': {
            'allan_neece': [u'Members'],
            'dollie_nocera': [u'Members'],
            'christian_stoney': [u'Admins', u'Members']
        },
        'contents':
        base_contents + [{
            'title': 'Future Meeting',
            'type': 'Event',
            'start': now + timedelta(days=7),
            'end': now + timedelta(days=14)
        }, {
            'title': 'Past Meeting',
            'type': 'Event',
            'start': now + timedelta(days=-7),
            'end': now + timedelta(days=-14)
        }],
    }]
    return caseworkspaces
    def __init__(self, context, request):
        super(EventListing, self).__init__(context, request)

        self.now = now = localized_now(context)

        # Try to get the default page
        default = getDefaultPage(context)
        self.default_context = context[default] if default else context

        self.is_collection = False
        if ICollection:
            self.is_collection = ICollection.providedBy(self.default_context)

        # Request parameter
        req = self.request.form

        b_size  = int(req.get('b_size', 0))
        if not b_size and self.is_collection:
            collection_behavior = ICollection(self.default_context)
            b_size = getattr(collection_behavior, 'item_count', 0)
        self.b_size = b_size or 10
        self.b_start = int(req.get('b_start', 0))
        self.orphan  = int(req.get('orphan', 1))
        self.mode    = req.get('mode', None)
        self._date   = req.get('date', None)
        self.tags    = req.get('tags', None)
        self.searchable_text = req.get('SearchableText', None)
        self.path    = req.get('path', None)

        day   = int(req.get('day', 0)) or None
        month = int(req.get('month', 0)) or None
        year  = int(req.get('year', 0)) or None

        if not self._date and day or month or year:
            self._date = date(year or now.year,
                              month or now.month,
                              day or now.day).isoformat()

        if self.mode is None:
            self.mode = 'day' if self._date else 'future'

        self.uid = None  # Used to get all occurrences from a single event. Overrides all other settings  # noqa
    def events(self):
        context = aq_inner(self.context)
        data = self.data

        kw = {}
        if data.search_base:
            kw['path'] = {
                'query':
                '%s%s' %
                ('/'.join(self.portal.getPhysicalPath()), data.search_base)
            }
        if data.state:
            kw['review_state'] = data.state

        return get_events(context,
                          start=localized_now(context),
                          ret_mode=RET_MODE_ACCESSORS,
                          expand=True,
                          limit=data.count,
                          **kw)
Exemple #38
0
def on_content_created(obj, event):
    if obj.portal_type == 'Dashboard':
        return
    metadata = IPublication(obj, None)
    if metadata is not None:
        if metadata.effective is None:
            metadata.effective = localized_now(obj)
    _touch_contributors(obj)

    if obj.portal_type == 'Collection':
        # enable syndication on type by default
        settings = FeedSettings(obj)
        settings.enabled = True

    adapted = ILayoutAware(obj, None)
    if adapted:
        if not adapted.content and not adapted.contentLayout:
            registry = getUtility(IRegistry)
            try:
                default_layout = registry['%s.%s' %
                                          (DEFAULT_CONTENT_LAYOUT_REGISTRY_KEY,
                                           obj.portal_type.replace(' ', '-'))]
                adapted.contentLayout = default_layout
            except (KeyError, AttributeError):
                pass
            try:
                default_layout = registry['%s.%s' %
                                          (DEFAULT_SITE_LAYOUT_REGISTRY_KEY,
                                           obj.portal_type.replace(' ', '-'))]
                adapted.pageSiteLayout = default_layout
            except (KeyError, AttributeError):
                pass

    try:
        tasks.scan_links.delay('/'.join(obj.getPhysicalPath()))
    except CannotGetPortalError:
        pass

    obj.reindexObject()
Exemple #39
0
    def upcoming_events(self):
        """
        Return upcoming events, potentially filtered by invitation status
        and/or search term
        """
        now = localized_now()

        query = dict(
            object_provides=IEvent.__identifier__,
            end__gt=solr_date(now),
        )
        phrase = None
        if self.data.get('SearchableText', ''):
            phrase = self.data['SearchableText'] + '*'
        elif self.data.get('my_events', True):
            query['invitees'] = [api.user.get_current().getId()]
        search_util = getUtility(ISiteSearch)
        upcoming_events = search_util.query(
            phrase=phrase,
            filters=query,
            sort='start',
        )
        return [ev.getObject() for ev in upcoming_events]
def default_start():
    now = localized_now()
    return now.replace(minute=(now.minute - now.minute % 5),
                       second=0,
                       microsecond=0)
Exemple #41
0
 def is_archived(self):
     archived = self.archived
     if not archived:
         return False
     return archived <= localized_now()
Exemple #42
0
 def get_archived_filter(cls):
     """Filter sessions that are archived"""
     return sql.or_(
         cls.archived >= localized_now(),
         cls.archived == None  # noqa: E711
     )
 def current_datetime(self):
     """
     Returns the current set date time, based on the registry
     settings.
     """
     return localized_now()
Exemple #44
0
 def test_default_start(self):
     now = localized_now().replace(minute=0, second=0, microsecond=0)
     self.assertEqualDatetime(default_start(), now)
def workspaces_spec(context):
    now = localized_now()
    budget_proposal_filename = u'budget-proposal.png'
    budget_proposal_path = os.path.join('images', budget_proposal_filename)
    budget_proposal_img = NamedBlobImage(
        data=context.openDataFile(budget_proposal_path).read(),
        filename=budget_proposal_filename)
    minutes_filename = u'minutes.docx'
    minutes_path = os.path.join('files', minutes_filename)
    minutes_file = NamedBlobImage(
        data=context.openDataFile(minutes_path).read(),
        filename=minutes_filename)

    tomorrow = (now + timedelta(days=1)).replace(hour=9,
                                                 minute=0,
                                                 second=0,
                                                 microsecond=0)
    next_month = (now + timedelta(days=30)).replace(hour=9,
                                                    minute=0,
                                                    second=0,
                                                    microsecond=0)

    # Create workspaces
    workspaces = [
        {
            'title':
            'Open Market Committee',
            'description':
            'The OMC holds eight regularly scheduled meetings '
            'during the year and other meetings as needed.',
            'transition':
            'make_private',
            'participant_policy':
            'publishers',
            'members': {
                'allan_neece': [u'Members'],
                'christian_stoney': [u'Admins', u'Members'],
                'neil_wichmann': [u'Members'],
                'francois_gast': [u'Members'],
                'jamie_jacko': [u'Members'],
                'jesse_shaik': [u'Members'],
                'jorge_primavera': [u'Members'],
                'silvio_depaoli': [u'Members'],
                'lance_stockstill': [u'Members'],
                'pearlie_whitby': [u'Members'],
                'dollie_nocera': [u'Members'],
                'esmeralda_claassen': [u'Members'],
                'rosalinda_roache': [u'Members'],
                'guy_hackey': [u'Members'],
            },
            'contents': [{
                'title':
                'Manage Information',
                'type':
                'Folder',
                'contents': [
                    {
                        'title': 'Preparation of Records',
                        'description': 'How to prepare records',
                        'state': 'published',
                        'subject': 'Read carefully',
                        'type': 'File',
                    },
                    {
                        'title':
                        'Public bodies reform',
                        'description':
                        'Making arrangements for the transfer of '
                        'information, records and knowledge is a '
                        'key part of any Machinery of Government '
                        'change.',
                        'type':
                        'Document',
                        'state':
                        'published'
                    },
                    {
                        'title':
                        'Repurchase Agreements',
                        'description':
                        'A staff presentation outlined several '
                        'approaches to raising shortterm interest '
                        'rates when it becomes appropriate to do '
                        'so, and to controlling the level of '
                        'short-term interest rates ',
                        'owner':
                        'allan_neece',
                        'type':
                        'Document'
                    },
                    {
                        'title':
                        u'Budget Proposal',
                        'description':
                        (u'A diagram of the factors impacting the budget and '
                         u'results'),
                        'owner':
                        'allan_neece',
                        'image':
                        budget_proposal_img,
                        'type':
                        'Image',
                    },
                    {
                        'title': u'Minutes',
                        'owner': 'allan_neece',
                        'description': u'Meeting Minutes',
                        'file': minutes_file,
                        'type': 'File',
                    },
                    {
                        'title': u'Minutes Overview',
                        'owner': 'allan_neece',
                        'description': u'Meeting Minutes Overview',
                        'type': 'Document',
                        'modification_date': now - timedelta(days=60),
                    },
                    {
                        'title': 'Open Market Day',
                        'type': 'Event',
                        'state': 'published',
                        'start': tomorrow,
                        'end': tomorrow + timedelta(hours=8)
                    },
                    {
                        'title': 'Plone Conf',
                        'type': 'Event',
                        'state': 'published',
                        'start': next_month,
                        'end': next_month + timedelta(days=3, hours=8)
                    },
                    {
                        'title': "Yesterday's gone",
                        'type': 'Event',
                        'state': 'published',
                        'owner': 'allan_neece',
                        'start': tomorrow - timedelta(days=3),
                        'end': tomorrow - timedelta(days=2)
                    },
                ]
            }, {
                'title':
                'Projection Materials',
                'type':
                'Folder',
                'contents': [{
                    'title': 'Projection Material',
                    'type': 'File'
                }]
            }, {
                'title': 'Future Event',
                'type': 'Event',
                'start': now + timedelta(days=7),
                'end': now + timedelta(days=14)
            }, {
                'title': 'Past Event',
                'type': 'Event',
                'start': now + timedelta(days=-7),
                'end': now + timedelta(days=-14)
            }, {
                'title':
                'Files for application 2837',
                'type':
                'ploneintranet.workspace.mail',
                'mail_from':
                u'*****@*****.**',
                'mail_to': (
                    u'*****@*****.**',
                    u'*****@*****.**',
                ),
                'mail_body':
                RichTextValue(u'''
                    <p>Dear mister Kolbach,</p>
                    <p>We’ll process your application with the shortest
                     delay.</p>
                    <p>Yours sincerely, <br>
                    Alexander Pilz</p>

                    <blockquote>
                      <p>Dear Sir or Madam,</p>

                      <p>Sed ut perspiciatis unde omnis iste natus error
                      sit voluptatem accusantium doloremque laudantium,
                      totam rem aperiam, eaque ipsa quae ab illo inventore
                      veritatis et quasi architecto beatae vitae dicta sunt
                      explicabo.</p>

                      <p>Kind regards,<br>
                    Cornelis G. A. Kolbach</p>
                    </blockquote>
                   '''),
                'contents': [
                    {
                        'title': 'Budget proposal',
                        'type': 'Image',
                        'image': budget_proposal_img,
                    },
                    {
                        'title': u'Minutes',
                        'owner': 'allan_neece',
                        'description': u'Meeting Minutes',
                        'file': minutes_file,
                        'type': 'File',
                    },
                ]
            }],
        },
        {
            'title':
            'Parliamentary papers guidance',
            'description':
            '"Parliamentary paper" is a term used to describe a '
            'document which is laid before Parliament. Most '
            'government organisations will produce at least one '
            'parliamentary paper per year.',
            'transition':
            'make_private',
            'participant_policy':
            'producers',
            'members': {
                'allan_neece': [u'Members'],
                'christian_stoney': [u'Admins', u'Members'],
                'francois_gast': [u'Members'],
                'jamie_jacko': [u'Members'],
                'fernando_poulter': [u'Members'],
                'jesse_shaik': [u'Members'],
                'jorge_primavera': [u'Members'],
                'silvio_depaoli': [u'Members'],
                'kurt_weissman': [u'Members'],
                'esmeralda_claassen': [u'Members'],
                'rosalinda_roache': [u'Members'],
                'guy_hackey': [u'Members'],
            },
            'contents': [{
                'title': 'Test Document',
                'description': 'A document just for testing',
                'type': 'Document'
            }]
        },
        {
            'title':
            u'Shareholder information',
            'description':
            u'"Shareholder information" contains all documents, '
            u'papers and diagrams for keeping shareholders informed about the '
            u'current state of affairs.',
            'transition':
            'make_private',
            'participant_policy':
            'consumers',
            'members': {
                'allan_neece': [u'Members'],
                'christian_stoney': [u'Admins', u'Members'],
                'francois_gast': [u'Members'],
                'jamie_jacko': [u'Members'],
                'fernando_poulter': [u'Members'],
                'jesse_shaik': [u'Members'],
                'jorge_primavera': [u'Members'],
                'silvio_depaoli': [u'Members'],
                'kurt_weissman': [u'Members'],
                'esmeralda_claassen': [u'Members'],
                'rosalinda_roache': [u'Members'],
                'guy_hackey': [u'Members'],
            },
            'contents': [{
                'title': 'Test Document',
                'description': 'A document just for testing',
                'type': 'Document',
                'state': 'published'
            }]
        },
        {
            'title':
            u'Service announcements',
            'description':
            u'Public service announcements can be found here.',
            'transition':
            'make_open',
            'participant_policy':
            'consumers',
            'members': {
                'allan_neece': [u'Members'],
                'christian_stoney': [u'Admins', u'Members'],
                'francois_gast': [u'Members'],
                'jamie_jacko': [u'Members'],
                'fernando_poulter': [u'Members'],
                'jesse_shaik': [u'Members'],
                'jorge_primavera': [u'Members'],
                'silvio_depaoli': [u'Members'],
                'kurt_weissman': [u'Members'],
                'esmeralda_claassen': [u'Members'],
                'rosalinda_roache': [u'Members'],
                'guy_hackey': [u'Members'],
            },
            'contents': [
                {
                    'title': 'Terms and conditions',
                    'description': 'A document just for testing',
                    'type': 'Document',
                    'state': 'published'
                },
                {
                    'title': 'Customer satisfaction survey',
                    'description': 'A private document',
                    'type': 'Document'
                },
            ]
        },
    ]
    return workspaces
Exemple #46
0
def workspaces_spec(context):
    now = localized_now()
    budget_proposal_filename = u'budget-proposal.png'
    budget_proposal_path = os.path.join('images', budget_proposal_filename)
    budget_proposal_img = NamedBlobImage(
        data=context.openDataFile(budget_proposal_path).read(),
        filename=budget_proposal_filename)
    minutes_filename = u'minutes.docx'
    minutes_path = os.path.join('files', minutes_filename)
    minutes_file = NamedBlobImage(
        data=context.openDataFile(minutes_path).read(),
        filename=minutes_filename)

    tomorrow = (now + timedelta(days=1)).replace(hour=9,
                                                 minute=0,
                                                 second=0,
                                                 microsecond=0)
    next_month = (now + timedelta(days=30)).replace(hour=9,
                                                    minute=0,
                                                    second=0,
                                                    microsecond=0)

    # Create workspaces
    workspaces = [
        {
            'title':
            'Open Market Committee',
            'description':
            'The OMC holds eight regularly scheduled meetings '
            'during the year and other meetings as needed.',
            'transition':
            'make_private',
            'participant_policy':
            'publishers',
            'members': {
                'allan_neece': [u'Members'],
                'christian_stoney': [u'Admins', u'Members'],
                'neil_wichmann': [u'Members'],
                'francois_gast': [u'Members'],
                'jaimie_jacko': [u'Members'],
                'jesse_shaik': [u'Members'],
                'jorge_primavera': [u'Members'],
                'silvio_depaoli': [u'Members'],
                'lance_stockstill': [u'Members'],
                'pearly_whitby': [u'Members'],
                'dollie_nocera': [u'Members'],
                'esmeralda_claassen': [u'Members'],
                'rosalinda_roache': [u'Members'],
                'guy_hackey': [u'Members'],
            },
            'contents': [
                {
                    'title':
                    'Manage Information',
                    'type':
                    'Folder',
                    'contents': [
                        {
                            'title': 'Preparation of Records',
                            'description': 'How to prepare records',
                            'state': 'published',
                            'type': 'File'
                        },
                        {
                            'title':
                            'Public bodies reform',
                            'description':
                            'Making arrangements for the transfer of '
                            'information, records and knowledge is a '
                            'key part of any Machinery of Government '
                            'change.',
                            'type':
                            'Document',
                            'state':
                            'published'
                        },
                        {
                            'title':
                            'Repurchase Agreements',
                            'description':
                            'A staff presentation outlined several '
                            'approaches to raising shortterm interest '
                            'rates when it becomes appropriate to do '
                            'so, and to controlling the level of '
                            'short-term interest rates ',
                            'owner':
                            'allan_neece',
                            'type':
                            'Document'
                        },
                        {
                            'title':
                            u'Budget Proposal',
                            'description':
                            (u'A diagram of the factors impacting the budget and '
                             u'results'),
                            'owner':
                            'allan_neece',
                            'image':
                            budget_proposal_img,
                            'type':
                            'Image',
                        },
                        {
                            'title': u'Minutes',
                            'owner': 'allan_neece',
                            'description': u'Meeting Minutes',
                            'file': minutes_file,
                            'type': 'File',
                        },
                        {
                            'title': u'Minutes Overview',
                            'owner': 'allan_neece',
                            'description': u'Meeting Minutes Overview',
                            'type': 'Document',
                            'modification_date': now - timedelta(days=60),
                        },
                        {
                            'title': 'Open Market Day',
                            'type': 'Event',
                            'state': 'published',
                            'start': tomorrow,
                            'end': tomorrow + timedelta(hours=8)
                        },
                        {
                            'title': 'Plone Conf',
                            'type': 'Event',
                            'state': 'published',
                            'start': next_month,
                            'end': next_month + timedelta(days=3, hours=8)
                        },
                        {
                            'title': "Yesterday's gone",
                            'type': 'Event',
                            'state': 'published',
                            'owner': 'allan_neece',
                            'start': tomorrow - timedelta(days=3),
                            'end': tomorrow - timedelta(days=2)
                        },
                    ]
                },
                {
                    'title': 'Projection Materials',
                    'type': 'Folder',
                    'contents': [{
                        'title': 'Projection Material',
                        'type': 'File'
                    }]
                },
                {
                    'title': 'Future Event',
                    'type': 'Event',
                    'start': now + timedelta(days=7),
                    'end': now + timedelta(days=14)
                },
                {
                    'title': 'Past Event',
                    'type': 'Event',
                    'start': now + timedelta(days=-7),
                    'end': now + timedelta(days=-14)
                },
            ],
        },
        {
            'title':
            'Parliamentary papers guidance',
            'description':
            '"Parliamentary paper" is a term used to describe a '
            'document which is laid before Parliament. Most '
            'government organisations will produce at least one '
            'parliamentary paper per year.',
            'transition':
            'make_private',
            'participant_policy':
            'producers',
            'members': {
                'allan_neece': [u'Members'],
                'christian_stoney': [u'Admins', u'Members'],
                'francois_gast': [u'Members'],
                'jaimie_jacko': [u'Members'],
                'fernando_poulter': [u'Members'],
                'jesse_shaik': [u'Members'],
                'jorge_primavera': [u'Members'],
                'silvio_depaoli': [u'Members'],
                'kurt_weissman': [u'Members'],
                'esmeralda_claassen': [u'Members'],
                'rosalinda_roache': [u'Members'],
                'guy_hackey': [u'Members'],
            },
            'contents': [{
                'title': 'Test Document',
                'description': 'A document just for testing',
                'type': 'Document'
            }]
        },
        {
            'title':
            u'Shareholder information',
            'description':
            u'"Shareholder information" contains all documents, '
            u'papers and diagrams for keeping shareholders informed about the '
            u'current state of affairs.',
            'transition':
            'make_private',
            'participant_policy':
            'consumers',
            'members': {
                'allan_neece': [u'Members'],
                'christian_stoney': [u'Admins', u'Members'],
                'francois_gast': [u'Members'],
                'jaimie_jacko': [u'Members'],
                'fernando_poulter': [u'Members'],
                'jesse_shaik': [u'Members'],
                'jorge_primavera': [u'Members'],
                'silvio_depaoli': [u'Members'],
                'kurt_weissman': [u'Members'],
                'esmeralda_claassen': [u'Members'],
                'rosalinda_roache': [u'Members'],
                'guy_hackey': [u'Members'],
            },
            'contents': [{
                'title': 'Test Document',
                'description': 'A document just for testing',
                'type': 'Document',
                'state': 'published'
            }]
        },
        {
            'title':
            u'Service announcements',
            'description':
            u'Public service announcements can be found here.',
            'transition':
            'make_open',
            'participant_policy':
            'consumers',
            'members': {
                'allan_neece': [u'Members'],
                'christian_stoney': [u'Admins', u'Members'],
                'francois_gast': [u'Members'],
                'jaimie_jacko': [u'Members'],
                'fernando_poulter': [u'Members'],
                'jesse_shaik': [u'Members'],
                'jorge_primavera': [u'Members'],
                'silvio_depaoli': [u'Members'],
                'kurt_weissman': [u'Members'],
                'esmeralda_claassen': [u'Members'],
                'rosalinda_roache': [u'Members'],
                'guy_hackey': [u'Members'],
            },
            'contents': [
                {
                    'title': 'Terms and conditions',
                    'description': 'A document just for testing',
                    'type': 'Document',
                    'state': 'published'
                },
                {
                    'title': 'Customer satisfaction survey',
                    'description': 'A private document',
                    'type': 'Document'
                },
            ]
        },
    ]
    return workspaces