Example #1
0
    def events(self):
        """Return list of dictionary

        :rtype: list
        """
        res = []
        base = IAdapter(self.context)
        before_date = '{}/01/01'.format(self.year() + 1)
        for item in base.get_content_listing(IATEvent,
                                             sort_on='start',
                                             start={
                                                 'query': [
                                                     DateTime(before_date),
                                                 ],
                                                 'range': 'max'
                                             },
                                             end={
                                                 'query': [
                                                     DateTime(),
                                                 ],
                                                 'range': 'min'
                                             }):
            res.append({
                'datetime': base.event_datetime(item),
                'description': item.Description(),
                'title': item.Title(),
                'url': item.getURL(),
            })
        return res
    def __call__(self):
        super(SearchEventResultsView, self).__call__()
        if self.request.form.get("form.buttons.Export", None) is not None:
            defaults_name = [
                self.context.translate(PloneMessageFactory(u"Title")),
                self.context.translate(_(u"Date")),
                self.context.translate(PloneMessageFactory(u"Description")),
                self.context.translate(PloneMessageFactory(u"Text")),
                self.context.translate(PloneMessageFactory(u"URL")),
            ]
            extras = ["location", "attendees", "eventUrl", "contactName", "contactEmail", "contactPhone", "subject"]
            extras_name = [
                self.context.translate(ATCTMessageFactory(ATEvent.schema.get(extra).widget.label)) for extra in extras
            ]

            plone = getMultiAdapter((self.context, self.request), name="plone")
            encoding = plone.site_encoding()

            headers = tuple([header.encode(encoding) for header in (defaults_name + extras_name)])
            out = StringIO()
            writer = csv.writer(out, delimiter="|", quoting=csv.QUOTE_MINIMAL)
            writer.writerow(headers)

            adapter = IAdapter(self.context)
            for item in getMultiAdapter((self.context, self.request), ISearchEventResults)(b_size=None):
                values = [
                    item.Title(),
                    adapter.event_datetime(item).encode(encoding),
                    item.Description(),
                    IItemText(item)(),
                    item.getURL(),
                ]
                obj = item.getObject()
                for extra in extras:
                    if extra == "attendees" or extra == "subject":
                        value = u", ".join(getattr(obj, extra)).encode(encoding)
                    else:
                        value = getattr(obj, extra).encode(encoding)

                    values.append(value)

                writer.writerow(tuple(values))

            filename = "search-event-results-{}.csv".format(datetime.now().isoformat())
            cd = 'attachment; filename="{}"'.format(filename)
            self.request.response.setHeader("Content-Type", "text/csv")
            self.request.response.setHeader("Content-Disposition", cd)
            return out.getvalue()
        else:
            return self.template()
Example #3
0
    def events(self):
        """Return list of dictionary

        :rtype: list
        """
        res = []
        base = IAdapter(self.context)
        before_date = '{}/01/01'.format(self.year() + 1)
        for item in base.get_content_listing(IATEvent, sort_on='start', start={'query': [DateTime(before_date), ], 'range': 'max'}, end={'query': [DateTime(), ], 'range': 'min'}):
            res.append({
                'datetime': base.event_datetime(item),
                'description': item.Description(),
                'title': item.Title(),
                'url': item.getURL(),
            })
        return res
Example #4
0
    def test_event_datetime(self):
        base = IAdapter(self.portal)

        from DateTime import DateTime
        self.create_event(id='event1', startDate=DateTime('2013/02/25'), endDate=DateTime('2013/02/25'))
        self.create_event(id='event2', startDate=DateTime('2013/02/26 20:00'), endDate=DateTime('2013/02/26 22:00'))
        self.create_event(id='event3', startDate=DateTime('2013/02/27'), endDate=DateTime('2013/02/28'))

        from Products.ATContentTypes.interfaces.event import IATEvent
        res = []
        for item in base.get_content_listing(IATEvent, sort_on='start'):
            res.append(base.event_datetime(item))
        try:
            self.assertEqual(res, [
                u'Feb 25, 2013 12:00 AM',
                u'Feb 26, 2013 08:00 PM - 10:00 PM',
                u'Feb 27, 2013 12:00 AM - Feb 28, 2013 12:00 AM'])
        except AssertionError:
            self.assertEqual(res, [
                u'2013-02-25 00:00',
                u'2013-02-26 20:00 - 22:00',
                u'2013-02-27 00:00 - 2013-02-28 00:00'])