Exemplo n.º 1
0
    def test_by_range_timezone_regression(self):
        year = date.today().year

        self.login_testuser()

        published = self.catalog.indices["published"]

        self.assertEqual(len(published.index), 0)

        event = self.create_event(
            start=datetime(year, 12, 31, 22), end=datetime(year, 12, 31, 23), timezone="Europe/Vienna"
        )
        event.submit()
        event.publish()
        transaction.commit()

        self.assertEqual(len(published.index), 1)

        dtrange = (datetime(year + 1, 1, 1), datetime(year + 1, 12, 31))
        dtrange = [dates.as_timezone(dt, "Europe/Vienna") for dt in dtrange]
        self.assertEqual(len(published.by_range(*dtrange)), 0)

        dtrange = (datetime(year, 1, 1), datetime(year, 12, 31, 23, 59))
        dtrange = [dates.as_timezone(dt, "Europe/Vienna") for dt in dtrange]
        self.assertEqual(len(published.by_range(*dtrange)), 1)
Exemplo n.º 2
0
    def test_by_range_timezone_regression(self):
        year = date.today().year

        self.login_testuser()

        published = self.catalog.indices['published']

        self.assertEqual(len(published.index), 0)

        event = self.create_event(
            start=datetime(year, 12, 31, 22),
            end=datetime(year, 12, 31, 23),
            timezone='Europe/Vienna'
        )
        event.submit()
        event.publish()
        transaction.commit()

        self.assertEqual(len(published.index), 1)

        dtrange = (datetime(year+1, 1, 1), datetime(year+1, 12, 31))
        dtrange = [dates.as_timezone(dt, 'Europe/Vienna') for dt in dtrange]
        self.assertEqual(len(published.by_range(*dtrange)), 0)

        dtrange = (datetime(year, 1, 1), datetime(year, 12, 31, 23, 59))
        dtrange = [dates.as_timezone(dt, 'Europe/Vienna') for dt in dtrange]
        self.assertEqual(len(published.by_range(*dtrange)), 1)
    def test_whole_day_regression(self, default_now, default_timezone):
        # recurring whole day events would lead to errors because the
        # daterange applied in the catalog did not include 00:00 one day
        # after creating the event

        # the error only happens if the timezone of the event and the
        # server differs

        default_timezone.return_value = 'Europe/Vienna'
        default_now.return_value = dates.as_timezone(
            datetime.now(), 'Europe/Vienna'
        )

        browser = self.admin_browser

        # create the event in europe/vienna timezone
        browser.open(
            '/veranstaltungen/++add++seantis.dir.events.item'
        )

        browser.widget('title').value = 'Title'
        browser.widget('short_description').value = 'Short'

        browser.getControl('Category1').selected = True
        browser.getControl('Category2').selected = True

        browser.widget('submission_date_type').value = ['range']

        start = datetime.now()
        end = datetime.now() + timedelta(days=2)

        browser.set_date('submission_range_start_date', start)
        browser.set_date('submission_range_end_date', end)
        browser.getControl('All day').selected = True

        browser.getControl('Continue').click()
        browser.getControl('Continue').click()

        browser.widget('submitter').value = 'test'
        browser.widget('submitter_email').value = '*****@*****.**'

        browser.getControl('Submit').click()

        # view the event the next day in UTC
        default_timezone.return_value = 'UTC'
        default_now.return_value = dates.as_timezone(
            datetime.now() + timedelta(days=1), 'Europe/Vienna'
        )

        # this used to throw an error
        browser.open('/veranstaltungen?state=submitted')
Exemplo n.º 4
0
def fix_tzinfo(date):
    """ Fix timezone information for dates parsed with dateutil."""
    if date.tzinfo and date.tzname():
        timezone = date.tzname()
        date.replace(tzinfo=None)
        date = as_timezone(date, timezone)
    return date
Exemplo n.º 5
0
def fix_tzinfo(date):
    """ Fix timezone information for dates parsed with dateutil."""
    if date.tzinfo and date.tzname():
        timezone = date.tzname()
        date.replace(tzinfo=None)
        date = as_timezone(date, timezone)
    return date
Exemplo n.º 6
0
    def test_whole_day_regression(self, default_now, default_timezone):
        # recurring whole day events would lead to errors because the
        # daterange applied in the catalog did not include 00:00 one day
        # after creating the event

        # the error only happens if the timezone of the event and the
        # server differs

        default_timezone.return_value = 'Europe/Vienna'
        default_now.return_value = dates.as_timezone(datetime.now(),
                                                     'Europe/Vienna')

        browser = self.admin_browser

        # create the event in europe/vienna timezone
        browser.open('/veranstaltungen/++add++seantis.dir.events.item')

        browser.widget('title').value = 'Title'
        browser.widget('short_description').value = 'Short'

        browser.getControl('Category1').selected = True
        browser.getControl('Category2').selected = True

        browser.widget('submission_date_type').value = ['range']

        start = datetime.now()
        end = datetime.now() + timedelta(days=2)

        browser.set_date('submission_range_start_date', start)
        browser.set_date('submission_range_end_date', end)
        browser.getControl('All day').selected = True

        browser.getControl('Continue').click()
        browser.getControl('Continue').click()

        browser.widget('submitter').value = 'test'
        browser.widget('submitter_email').value = '*****@*****.**'

        browser.getControl('Submit').click()

        # view the event the next day in UTC
        default_timezone.return_value = 'UTC'
        default_now.return_value = dates.as_timezone(
            datetime.now() + timedelta(days=1), 'Europe/Vienna')

        # this used to throw an error
        browser.open('/veranstaltungen?state=submitted')
Exemplo n.º 7
0
def get_event_dates_from_submission(data, timezone=None):

    timezone = timezone or dates.default_timezone()
    in_timezone = lambda date: dates.as_timezone(date, timezone)

    single_day = data['submission_date_type'] == ['date']

    if single_day:
        date, start, end, whole_day, recurrence = (
            data['submission_date'],
            data['submission_start_time'],
            data['submission_end_time'],
            data['submission_whole_day'],
            data['submission_recurrence']
        )

        if whole_day:
            start = time(0, 0, 0)
            end = time(23, 59, 59)

        start, end = map(
            in_timezone, dates.combine_daterange(date, start, end)
        )

        return start, end, whole_day, recurrence
    else:
        start_date, end_date, start_time, end_time, whole_day = (
            data['submission_range_start_date'],
            data['submission_range_end_date'],
            data['submission_range_start_time'],
            data['submission_range_end_time'],
            data['submission_whole_day']
        )

        if whole_day:
            start_time = time(0, 0, 0)
            end_time = time(23, 59, 59)

        start, end = map(
            in_timezone, dates.combine_daterange(
                start_date, start_time, end_time
            )
        )

        recurrence = 'RRULE:FREQ=WEEKLY;UNTIL={}'.format(
            dates.as_rfc5545_string(in_timezone(
                datetime.combine(end_date, time(23, 59, 59))
            ))
        )

        if data['submission_days']:
            recurrence += ';BYDAY={}'.format(
                ','.join(
                    [str(d) for d in data['submission_days']]
                )
            )

        return start, end, whole_day, recurrence
Exemplo n.º 8
0
    def __init__(self, start, end, recurrence="", timezone='Europe/Zurich',
                 whole_day=False):

        # if this is a whole day, the times are adjusted (this is what
        # plone.app.event would do on the dexterity type)
        if whole_day:
            start = datetime(start.year, start.month, start.day)
            end = datetime(end.year, end.month, end.day, 23, 59, 59)

        # the given date is implicitly of the given timezone, so enforce
        # that and then convert to utc as this is what an EventItem actually
        # stores.
        self.start = dates.to_utc(dates.as_timezone(start, timezone))
        self.end = dates.to_utc(dates.as_timezone(end, timezone))

        self.recurrence = recurrence
        self.timezone = timezone
        self.whole_day = whole_day
Exemplo n.º 9
0
    def __init__(self,
                 start,
                 end,
                 recurrence="",
                 timezone='Europe/Zurich',
                 whole_day=False):

        # if this is a whole day, the times are adjusted (this is what
        # plone.app.event would do on the dexterity type)
        if whole_day:
            start = datetime(start.year, start.month, start.day)
            end = datetime(end.year, end.month, end.day, 23, 59, 59)

        # the given date is implicitly of the given timezone, so enforce
        # that and then convert to utc as this is what an EventItem actually
        # stores.
        self.start = dates.to_utc(dates.as_timezone(start, timezone))
        self.end = dates.to_utc(dates.as_timezone(end, timezone))

        self.recurrence = recurrence
        self.timezone = timezone
        self.whole_day = whole_day
Exemplo n.º 10
0
def get_event_dates_from_submission(data, timezone=None):

    timezone = timezone or dates.default_timezone()
    in_timezone = lambda date: dates.as_timezone(date, timezone)

    single_day = data['submission_date_type'] == ['date']

    if single_day:
        date, start, end, whole_day, recurrence = (
            data['submission_date'], data['submission_start_time'],
            data['submission_end_time'], data['submission_whole_day'],
            data['submission_recurrence'])

        if whole_day:
            start = time(0, 0, 0)
            end = time(23, 59, 59)

        start, end = map(in_timezone,
                         dates.combine_daterange(date, start, end))

        return start, end, whole_day, recurrence
    else:
        start_date, end_date, start_time, end_time, whole_day = (
            data['submission_range_start_date'],
            data['submission_range_end_date'],
            data['submission_range_start_time'],
            data['submission_range_end_time'], data['submission_whole_day'])

        if whole_day:
            start_time = time(0, 0, 0)
            end_time = time(23, 59, 59)

        start, end = map(
            in_timezone,
            dates.combine_daterange(start_date, start_time, end_time))

        recurrence = 'RRULE:FREQ=WEEKLY;UNTIL={}'.format(
            dates.as_rfc5545_string(
                in_timezone(datetime.combine(end_date, time(23, 59, 59)))))

        if data['submission_days']:
            recurrence += ';BYDAY={}'.format(','.join(
                [str(d) for d in data['submission_days']]))

        return start, end, whole_day, recurrence
Exemplo n.º 11
0
    def fetch(self, json_string=None):

        try:
            if json_string is None:
                url = self.build_url()
                json_string = urlopen(url, timeout=300).read()

            events = json.loads(json_string)
        except:
            raise NoImportDataException()

        for event in events:

            cat1, cat2 = event.get('cat1'), event.get('cat2')
            cat1 = set(cat1) if cat1 is not None else set()
            cat2 = set(cat2) if cat2 is not None else set()

            if self.context.do_filter:
                if self.context.cat1:
                    if self.context.cat1:
                        if self.context.cat1 not in cat1:
                            continue
                    else:
                        continue
                if self.context.cat2:
                    if self.context.cat2:
                        if self.context.cat2 not in cat2:
                            continue
                    else:
                        continue

            e = {}
            e['fetch_id'] = self.context.url
            updated = event.get('last_update')
            e['last_update'] = parse(updated) if updated else default_now()
            e['source_id'] = event['id']

            e['id'] = event.get('id')
            e['title'] = event.get('title')
            e['short_description'] = event.get('short_description')
            e['long_description'] = event.get('long_description')
            e['cat1'] = cat1
            e['cat2'] = cat2

            timezone = event.get('timezone')
            start = fix_tzinfo(parse(event.get('start')))
            end = fix_tzinfo(parse(event.get('end')))

            e['timezone'] = timezone
            e['start'] = as_timezone(start, timezone)
            e['end'] = as_timezone(end, timezone)
            e['recurrence'] = event.get('recurrence')
            e['whole_day'] = event.get('whole_day')

            e['locality'] = event.get('locality')
            e['street'] = event.get('street')
            e['housenumber'] = event.get('housenumber')
            e['zipcode'] = event.get('zipcode')
            e['town'] = event.get('town')
            e['location_url'] = event.get('location_url')
            lon, lat = event.get('longitude'), event.get('latitude')
            e['longitude'] = str(lon) if lon is not None else None
            e['latitude'] = str(lat) if lon is not None else None
            e['organizer'] = event.get('organizer')
            e['contact_name'] = event.get('contact_name')
            e['contact_email'] = event.get('contact_email')
            e['contact_phone'] = event.get('contact_phone')
            e['prices'] = event.get('prices')
            e['event_url'] = event.get('event_url')
            e['registration'] = event.get('registration')
            e['submitter'] = event.get('submitter')
            e['submitter_email'] = event.get('submitter_email')

            try:
                e['image'] = event['images'][0]['url']
                e['image_name'] = event['images'][0]['name']
            except (TypeError, KeyError, IndexError):
                e['image'] = None

            try:
                e['attachment_1'] = event['attachements'][0]['url']
                e['attachment_1_name'] = event['attachements'][0]['name']
            except (TypeError, KeyError, IndexError):
                e['attachment_1'] = None
            try:
                e['attachment_2'] = event['attachements'][1]['url']
                e['attachment_2_name'] = event['attachements'][1]['name']
            except (TypeError, KeyError, IndexError):
                e['attachment_2'] = None

            yield e
Exemplo n.º 12
0
    def fetch(self, json_string=None):

        try:
            if json_string is None:
                url = self.build_url()
                json_string = urlopen(url, timeout=300).read()

            events = json.loads(json_string)
        except:
            raise NoImportDataException()

        for event in events:

            cat1, cat2 = event.get('cat1'), event.get('cat2')
            cat1 = set(cat1) if cat1 is not None else set()
            cat2 = set(cat2) if cat2 is not None else set()

            if self.context.do_filter:
                if self.context.cat1:
                    if self.context.cat1:
                        if self.context.cat1 not in cat1:
                            continue
                    else:
                        continue
                if self.context.cat2:
                    if self.context.cat2:
                        if self.context.cat2 not in cat2:
                            continue
                    else:
                        continue

            e = {}
            e['fetch_id'] = self.context.url
            updated = event.get('last_update')
            e['last_update'] = parse(updated) if updated else default_now()
            e['source_id'] = event['id']

            e['id'] = event.get('id')
            e['title'] = event.get('title')
            e['short_description'] = event.get('short_description')
            e['long_description'] = event.get('long_description')
            e['cat1'] = cat1
            e['cat2'] = cat2

            timezone = event.get('timezone')
            start = fix_tzinfo(parse(event.get('start')))
            end = fix_tzinfo(parse(event.get('end')))

            e['timezone'] = timezone
            e['start'] = as_timezone(start, timezone)
            e['end'] = as_timezone(end, timezone)
            e['recurrence'] = event.get('recurrence')
            e['whole_day'] = event.get('whole_day')

            e['locality'] = event.get('locality')
            e['street'] = event.get('street')
            e['housenumber'] = event.get('housenumber')
            e['zipcode'] = event.get('zipcode')
            e['town'] = event.get('town')
            e['location_url'] = event.get('location_url')
            lon, lat = event.get('longitude'), event.get('latitude')
            e['longitude'] = str(lon) if lon is not None else None
            e['latitude'] = str(lat) if lon is not None else None
            e['organizer'] = event.get('organizer')
            e['contact_name'] = event.get('contact_name')
            e['contact_email'] = event.get('contact_email')
            e['contact_phone'] = event.get('contact_phone')
            e['prices'] = event.get('prices')
            e['event_url'] = event.get('event_url')
            e['registration'] = event.get('registration')
            e['submitter'] = event.get('submitter')
            e['submitter_email'] = event.get('submitter_email')

            try:
                e['image'] = event['images'][0]['url']
                e['image_name'] = event['images'][0]['name']
            except (TypeError, KeyError, IndexError):
                e['image'] = None

            try:
                e['attachment_1'] = event['attachements'][0]['url']
                e['attachment_1_name'] = event['attachements'][0]['name']
            except (TypeError, KeyError, IndexError):
                e['attachment_1'] = None
            try:
                e['attachment_2'] = event['attachements'][1]['url']
                e['attachment_2_name'] = event['attachements'][1]['name']
            except (TypeError, KeyError, IndexError):
                e['attachment_2'] = None

            yield e