def default_event(db): cal = default_calendar(db) ev = Event(namespace_id=NAMESPACE_ID, calendar=cal, title='title', description='', location='', busy=False, read_only=False, reminders='', recurrence='', start=START, end=END, all_day=False, provider_name='inbox', raw_data='', source='remote') db.session.add(ev) db.session.commit() return ev
def test_initial(db): remote = _default_event(db) remote.participant_list = [ {'email': '*****@*****.**', 'status': 'noreply'}, {'email': '*****@*****.**', 'status': 'noreply'}, {'email': '*****@*****.**', 'status': 'noreply'}] local = Event(account_id=ACCOUNT_ID, calendar=_default_calendar(db)) local.copy_from(remote) local.source = 'local' assert len(local.participants) == 3 assert len(remote.participants) == 3 db.session.add_all([local, remote]) local.copy_from(remote) assert len(local.participants) == 3 assert len(remote.participants) == 3
def create(namespace, db_session, calendar, title, description, location, reminders, recurrence, when, participants): event = Event(calendar=calendar, namespace=namespace, uid=uuid.uuid4().hex, provider_name=INBOX_PROVIDER_NAME, raw_data='', title=title, description=description, location=location, when=when, read_only=False, is_owner=True, source='local') event.participant_list = participants db_session.add(event) db_session.commit() return event
def test_handle_offset_all_day_events(): raw_event = { "created": "2014-01-09T03:33:02.000Z", "creator": { "displayName": "Ben Bitdiddle", "email": "*****@*****.**", "self": True, }, "etag": '"2778476764000000"', "htmlLink": "https://www.google.com/calendar/event?eid=BAR", "iCalUID": "*****@*****.**", "id": "20140615_60o30dr564o30c1g60o30dr4ck", "kind": "calendar#event", "organizer": { "displayName": "Ben Bitdiddle", "email": "*****@*****.**", "self": True, }, "sequence": 0, "start": {"date": "2014-03-15"}, "end": {u"date": "2014-03-15"}, "status": "confirmed", "summary": "Ides of March", "transparency": "transparent", "updated": "2014-01-09T03:33:02.000Z", "visibility": "public", } expected = Event( uid="20140615_60o30dr564o30c1g60o30dr4ck", title="Ides of March", description=None, read_only=False, busy=False, start=arrow.get(2014, 03, 15), end=arrow.get(2014, 03, 15), all_day=True, owner="Ben Bitdiddle <*****@*****.**>", participants=[], ) assert cmp_event_attrs(expected, parse_event_response(raw_event, False))
def add_fake_event( db_session, namespace_id, calendar=None, title="title", description="", location="", busy=False, read_only=False, reminders="", recurrence="", start=None, end=None, all_day=False, ): from inbox.models import Event start = start or datetime.utcnow() end = end or (datetime.utcnow() + timedelta(seconds=1)) calendar = calendar or add_fake_calendar(db_session, namespace_id) event = Event( namespace_id=namespace_id, calendar=calendar, title=title, description=description, location=location, busy=busy, read_only=read_only, reminders=reminders, recurrence=recurrence, start=start, end=end, all_day=all_day, raw_data="", uid=str(uuid.uuid4()), ) event.sequence_number = 0 db_session.add(event) db_session.commit() return event
def create(namespace, db_session, subject, body, location, reminders, recurrence, when, participants): account = db_session.query(Account).filter( Account.id == namespace.account_id).one() event = Event(calendar=account.default_calendar, account_id=namespace.account_id, uid=uuid.uuid4().hex, provider_name=INBOX_PROVIDER_NAME, raw_data='', subject=subject, body=body, location=location, when=when, read_only=False, is_owner=True, source='local') event.participant_list = participants db_session.add(event) db_session.commit() return event
def test_handle_offset_all_day_events(): raw_event = { 'created': '2014-01-09T03:33:02.000Z', 'creator': { 'displayName': 'Ben Bitdiddle', 'email': '*****@*****.**', 'self': True }, 'etag': '"2778476764000000"', 'htmlLink': 'https://www.google.com/calendar/event?eid=BAR', 'iCalUID': '*****@*****.**', 'id': '20140615_60o30dr564o30c1g60o30dr4ck', 'kind': 'calendar#event', 'organizer': { 'displayName': 'Ben Bitdiddle', 'email': '*****@*****.**', 'self': True }, 'sequence': 0, 'start': {'date': '2014-03-15'}, 'end': {u'date': '2014-03-15'}, 'status': 'confirmed', 'summary': 'Ides of March', 'transparency': 'transparent', 'updated': '2014-01-09T03:33:02.000Z', 'visibility': 'public' } expected = Event(uid='20140615_60o30dr564o30c1g60o30dr4ck', title='Ides of March', description=None, read_only=False, busy=False, start=arrow.get(2014, 03, 15), end=arrow.get(2014, 03, 15), all_day=True, owner='Ben Bitdiddle <*****@*****.**>', participants=[]) assert cmp_event_attrs(expected, parse_event_response(raw_event, False))
def test_add_participant(db, config): """Test the basic logic of the merge() function.""" base = _default_event(db) participant = Participant(email_address="*****@*****.**") remote = Event(account_id=ACCOUNT_ID, calendar=_default_calendar(db), subject='new subject', body='new body', location='new location', busy=True, read_only=True, reminders='', recurrence='', start=2, end=3, all_day=False, source='remote', participants=[participant]) dest = _default_event(db) dest.merge_from(base, remote) assert len(dest.participants) == 1
def add_fake_event(db_session, namespace_id): from inbox.models import Event start = datetime.utcnow() end = datetime.utcnow() + timedelta(seconds=1) calendar = add_fake_calendar(db_session, namespace_id) event = Event(namespace_id=namespace_id, calendar=calendar, title='title', description='', location='', busy=False, read_only=False, reminders='', recurrence='', start=start, end=end, all_day=False, provider_name='inbox', raw_data='', source='local') db_session.add(event) db_session.commit() return event
def test_multi_update(db, config): """Test the basic logic of the merge() function.""" base = _default_event(db) base.participants = [Participant(email_address="*****@*****.**", status="no")] dest = _default_event(db) dest.participants = [Participant(email_address="*****@*****.**", status="no"), Participant(email_address="*****@*****.**", status="no")] participant1 = Participant(email_address="*****@*****.**", status="yes") remote = Event(account_id=ACCOUNT_ID, calendar=_default_calendar(db), subject='new subject', body='new body', location='new location', busy=True, read_only=True, reminders='', recurrence='', start=2, end=3, all_day=False, source='remote', participants=[participant1]) dest.merge_from(base, remote) assert len(dest.participants) == 2 for p in dest.participants: if p.email_address == "*****@*****.**": assert p.status == "yes" if p.email_address == "*****@*****.**": assert p.status == "no"
def supply_event(self, title, description='', when={'time': 0}, busy=True, location='', read_only=False, owner="", reminders='[]', recurrence="", deleted=False, raw_data='', is_owner=True, participants=[]): from inbox.models import Event self._events.append(Event(namespace_id=1, calendar_id=1, uid=str(self._next_uid), source='remote', provider_name=self.PROVIDER_NAME, title=title, description=description, location=location, when=when, busy=busy, is_owner=is_owner, owner=owner, read_only=read_only, raw_data=raw_data, reminders=reminders, recurrence=recurrence, deleted=deleted, participants=[])) self._next_uid += 1
def event_response_with_delete(calendar_uid, sync_from_time): if calendar_uid == 'first_calendar_uid': return [ Event(uid='first_event_uid', status='cancelled', **default_params) ]
def test_event_parsing(): raw_response = [{ 'created': '2012-10-09T22:35:50.000Z', 'creator': { 'displayName': 'Eben Freeman', 'email': '*****@*****.**', 'self': True }, 'end': { 'dateTime': '2012-10-15T18:00:00-07:00' }, 'etag': '"2806773858144000"', 'htmlLink': 'https://www.google.com/calendar/event?eid=FOO', 'iCalUID': '*****@*****.**', 'id': 'tn7krk4cekt8ag3pk6gapqqbro', 'kind': 'calendar#event', 'organizer': { 'displayName': 'Eben Freeman', 'email': '*****@*****.**', 'self': True }, 'attendees': [{ 'displayName': 'MITOC BOD', 'email': '*****@*****.**', 'responseStatus': 'accepted' }, { 'displayName': 'Eben Freeman', 'email': '*****@*****.**', 'responseStatus': 'accepted' }], 'reminders': { 'useDefault': True }, 'recurrence': ['RRULE:FREQ=WEEKLY;UNTIL=20150209T075959Z;BYDAY=MO'], 'sequence': 0, 'start': { 'dateTime': '2012-10-15T17:00:00-07:00' }, 'status': 'confirmed', 'summary': 'BOD Meeting', 'updated': '2014-06-21T21:42:09.072Z' }, { 'created': '2014-01-09T03:33:02.000Z', 'creator': { 'displayName': 'Holidays in United States', 'email': 'en.usa#[email protected]', 'self': True }, 'end': { u'date': '2014-06-16' }, 'etag': '"2778476764000000"', 'htmlLink': 'https://www.google.com/calendar/event?eid=BAR', 'iCalUID': '*****@*****.**', 'id': '20140615_60o30dr564o30c1g60o30dr4ck', 'kind': 'calendar#event', 'organizer': { 'displayName': 'Holidays in United States', 'email': 'en.usa#[email protected]', 'self': True }, 'sequence': 0, 'start': { 'date': '2014-06-15' }, 'status': 'confirmed', 'summary': "Fathers' Day", 'transparency': 'transparent', 'updated': '2014-01-09T03:33:02.000Z', 'visibility': 'public' }, { 'created': '2015-03-10T01:19:59.000Z', 'creator': { 'displayName': 'Ben Bitdiddle', 'email': '*****@*****.**', 'self': True }, 'end': { u'date': '2015-03-11' }, 'etag': '"2851906839480000"', 'htmlLink': 'https://www.google.com/calendar/event?eid=BAZ', 'iCalUID': '*****@*****.**', 'id': '3uisajkmdjqo43tfc3ig1l5hek', 'kind': 'calendar#event', 'organizer': { 'displayName': 'Ben Bitdiddle', 'email': '*****@*****.**', 'self': True }, 'reminders': { u'useDefault': False }, 'sequence': 1, 'start': { u'date': '2015-03-10' }, 'status': 'cancelled', 'summary': 'TUESDAY', 'transparency': 'transparent', 'updated': '2015-03-10T02:10:19.740Z' }] expected_deletes = ['3uisajkmdjqo43tfc3ig1l5hek'] expected_updates = [ RecurringEvent( uid='tn7krk4cekt8ag3pk6gapqqbro', title='BOD Meeting', description=None, read_only=False, start=arrow.get(2012, 10, 16, 0, 0, 0), end=arrow.get(2012, 10, 16, 1, 0, 0), all_day=False, busy=True, owner='Eben Freeman <*****@*****.**>', recurrence=['RRULE:FREQ=WEEKLY;UNTIL=20150209T075959Z;BYDAY=MO'], participants=[{ 'email': '*****@*****.**', 'name': 'MITOC BOD', 'status': 'yes', 'notes': None }, { 'email': '*****@*****.**', 'name': 'Eben Freeman', 'status': 'yes', 'notes': None }]), Event( uid='20140615_60o30dr564o30c1g60o30dr4ck', title="Fathers' Day", description=None, read_only=False, busy=False, start=arrow.get(2014, 06, 15), end=arrow.get(2014, 06, 15), all_day=True, owner= 'Holidays in United States <en.usa#[email protected]>', participants=[]) ]
def test_event_parsing(): raw_response = [ { "created": "2012-10-09T22:35:50.000Z", "creator": { "displayName": "Eben Freeman", "email": "*****@*****.**", "self": True, }, "end": {"dateTime": "2012-10-15T18:00:00-07:00"}, "etag": '"2806773858144000"', "htmlLink": "https://www.google.com/calendar/event?eid=FOO", "iCalUID": "*****@*****.**", "id": "tn7krk4cekt8ag3pk6gapqqbro", "kind": "calendar#event", "organizer": { "displayName": "Eben Freeman", "email": "*****@*****.**", "self": True, }, "attendees": [ { "displayName": "MITOC BOD", "email": "*****@*****.**", "responseStatus": "accepted", }, { "displayName": "Eben Freeman", "email": "*****@*****.**", "responseStatus": "accepted", }, ], "reminders": {"useDefault": True}, "recurrence": ["RRULE:FREQ=WEEKLY;UNTIL=20150209T075959Z;BYDAY=MO"], "sequence": 0, "start": {"dateTime": "2012-10-15T17:00:00-07:00"}, "status": "confirmed", "summary": "BOD Meeting", "updated": "2014-06-21T21:42:09.072Z", }, { "created": "2014-01-09T03:33:02.000Z", "creator": { "displayName": "Holidays in United States", "email": "en.usa#[email protected]", "self": True, }, "end": {u"date": "2014-06-16"}, "etag": '"2778476764000000"', "htmlLink": "https://www.google.com/calendar/event?eid=BAR", "iCalUID": "*****@*****.**", "id": "20140615_60o30dr564o30c1g60o30dr4ck", "kind": "calendar#event", "organizer": { "displayName": "Holidays in United States", "email": "en.usa#[email protected]", "self": True, }, "sequence": 0, "start": {"date": "2014-06-15"}, "status": "confirmed", "summary": "Fathers' Day", "transparency": "transparent", "updated": "2014-01-09T03:33:02.000Z", "visibility": "public", }, { "created": "2015-03-10T01:19:59.000Z", "creator": { "displayName": "Ben Bitdiddle", "email": "*****@*****.**", "self": True, }, "end": {u"date": "2015-03-11"}, "etag": '"2851906839480000"', "htmlLink": "https://www.google.com/calendar/event?eid=BAZ", "iCalUID": "*****@*****.**", "id": "3uisajkmdjqo43tfc3ig1l5hek", "kind": "calendar#event", "organizer": { "displayName": "Ben Bitdiddle", "email": "*****@*****.**", "self": True, }, "reminders": {u"useDefault": False}, "sequence": 1, "start": {u"date": "2015-03-10"}, "status": "cancelled", "summary": "TUESDAY", "transparency": "transparent", "updated": "2015-03-10T02:10:19.740Z", }, ] expected_deletes = ["3uisajkmdjqo43tfc3ig1l5hek"] expected_updates = [ RecurringEvent( uid="tn7krk4cekt8ag3pk6gapqqbro", title="BOD Meeting", description=None, read_only=False, start=arrow.get(2012, 10, 16, 0, 0, 0), end=arrow.get(2012, 10, 16, 1, 0, 0), all_day=False, busy=True, owner="Eben Freeman <*****@*****.**>", recurrence=["RRULE:FREQ=WEEKLY;UNTIL=20150209T075959Z;BYDAY=MO"], participants=[ { "email": "*****@*****.**", "name": "MITOC BOD", "status": "yes", "notes": None, }, { "email": "*****@*****.**", "name": "Eben Freeman", "status": "yes", "notes": None, }, ], ), Event( uid="20140615_60o30dr564o30c1g60o30dr4ck", title="Fathers' Day", description=None, read_only=False, busy=False, start=arrow.get(2014, 06, 15), end=arrow.get(2014, 06, 15), all_day=True, owner="Holidays in United States <en.usa#[email protected]>", participants=[], ), ]
def parse_event(self, event, cal_info): """Constructs an Event object from a Google calendar entry. Parameters ---------- event: gdata.calendar.entry.CalendarEntry The Google calendar entry to parse. Returns ------- ..models.tables.base.Event A corresponding Inbox Event instance. Raises ------ MalformedEventError If the calendar data could not be parsed correctly. """ try: uid = str(event['id']) # The entirety of the raw event data in json representation. raw_data = str(event) # 'cancelled' events signify those instances within a series # that have been cancelled (for that given series). As such, # since full support for dealing with single instances within # a reocurring event series is not added, right now we just # treat this event as 'malformed'. -cg3 # TODO: Add support for reocurring events (see ways to handle # this generically across providers) if 'status' in event and event['status'] == 'cancelled': raise MalformedEventError() subject = event.get('summary', '')[:SUBJECT_MAX_LEN] body = event.get('description', None) location = event.get('location', None) if location: location = location[:LOCATION_MAX_LEN] all_day = False read_only = True is_owner = False start = event['start'] end = event['end'] g_reccur = event.get('recurrence', None) recurrence = str(g_reccur) if g_reccur else None busy = event.get('transparency', True) if busy == 'transparent': busy = False reminders = [] if 'dateTime' in start: if event['reminders']['useDefault']: reminder_source = cal_info['defaultReminders'] elif 'overrides' in event['reminders']: reminder_source = event['reminders']['overrides'] else: reminder_source = None if reminder_source: for reminder in reminder_source: reminders.append(reminder['minutes']) start = parse_datetime(start['dateTime']) end = parse_datetime(end['dateTime']) else: start = date_parser.parse(start['date']) end = date_parser.parse(end['date']) all_day = True reminders = str(reminders) # Convert google's notion of status into our own participants = [] status_map = {'accepted': 'yes', 'needsAction': 'noreply', 'declined': 'no', 'tentative': 'maybe'} for attendee in event.get('attendees', []): g_status = attendee.get('responseStatus') if g_status not in status_map: raise MalformedEventError() status = status_map[g_status] email = attendee.get('email') if not email: raise MalformedEventError() name = attendee.get('displayName') notes = None if 'additionalGuests' in attendee: notes = "Guests: {}".format(attendee['additionalGuests']) if 'comment' in attendee: notes += " Notes: {}".format(attendee['comment']) elif 'comment' in attendee: notes = "Notes: {}".format(attendee['comment']) participants.append(Participant(email_address=email, name=name, status=status, notes=notes)) if 'self' in event['creator']: is_owner = True read_only = False elif 'guestsCanModify' in event: read_only = False owner = "{} <{}>".format(event['creator']['displayName'], event['creator']['email']) except (KeyError, AttributeError): raise MalformedEventError() return Event(account_id=self.account_id, uid=uid, provider_name=self.PROVIDER_NAME, raw_data=raw_data, subject=subject, body=body, location=location, reminders=reminders, recurrence=recurrence, start=start, end=end, owner=owner, is_owner=is_owner, busy=busy, all_day=all_day, read_only=read_only, source='remote', participants=participants)
def event_response_with_update(calendar_uid, sync_from_time): if calendar_uid == 'first_calendar_uid': return [Event(uid='first_event_uid', title='Top Secret Plotting Meeting', **default_params)]
def events_from_ics(namespace, calendar, ics_str): try: cal = Calendar.from_ical(ics_str) except ValueError: raise MalformedEventError() events = [] for component in cal.walk(): if component.name == "VEVENT": start = component.get('dtstart').dt end = component.get('dtend').dt title = component.get('summary') description = str(component.get('description')) if isinstance(start, datetime): all_day = False else: all_day = True start = datetime.combine(start, datetime.min.time()) end = datetime.combine(end, datetime.min.time()) reccur = component.get('rrule') if reccur: reccur = reccur.to_ical() else: reccur = '' participants = [] for attendee in component.get('attendee'): email = str(attendee) # strip mailto: if it exists if email.startswith('mailto:'): email = email[7:] try: name = attendee.params['CN'] except KeyError: name = None status_map = { 'NEEDS-ACTION': 'noreply', 'ACCEPTED': 'yes', 'DECLINED': 'no', 'TENTATIVE': 'maybe' } status = 'noreply' try: a_status = attendee.params['PARTSTAT'] status = status_map[a_status] except KeyError: pass notes = None try: guests = attendee.params['X-NUM-GUESTS'] notes = "Guests: {}".format(guests) except KeyError: pass participant = Participant(email_address=email, status=status, name=name, notes=notes) participants.append(participant) location = component.get('location') organizer = component.get('organizer') if (organizer): organizer = str(organizer) if organizer.startswith('mailto:'): organizer = organizer[7:] uid = str(component.get('uid')) event = Event(namespace=namespace, calendar=calendar, uid=uid, provider_name='ics', raw_data=component.to_ical(), title=title, description=description, location=location, reminders=str([]), recurrence=reccur, start=start, end=end, busy=True, all_day=all_day, read_only=True, source='local') event.participants = participants events.append(event) return events
def parse_event(self, event, cal_info): """Constructs an Event object from a Google calendar entry. Parameters ---------- event: gdata.calendar.entry.CalendarEntry The Google calendar entry to parse. Returns ------- ..models.tables.base.Event A corresponding Inbox Event instance. Raises ------ MalformedEventError If the calendar data could not be parsed correctly. """ try: uid = str(event['id']) # The entirety of the raw event data in json representation. raw_data = str(event) # 'cancelled' events signify those instances within a series # that have been cancelled (for that given series). As such, # since full support for dealing with single instances within # a reocurring event series is not added, right now we just # ignore the event. -cg3 # TODO: Add support for reocurring events (see ways to handle # this generically across providers) if 'status' in event and event['status'] == 'cancelled': return None title = event.get('summary', '') description = event.get('description', None) location = event.get('location', None) all_day = False read_only = True is_owner = False start = event['start'] end = event['end'] g_recur = event.get('recurrence', None) recurrence = str(g_recur) if g_recur else None busy = event.get('transparency', True) if busy == 'transparent': busy = False reminders = [] if 'dateTime' in start: if event['reminders']['useDefault']: reminder_source = cal_info['defaultReminders'] elif 'overrides' in event['reminders']: reminder_source = event['reminders']['overrides'] else: reminder_source = None if reminder_source: for reminder in reminder_source: reminders.append(reminder['minutes']) try: start = parse_datetime(start['dateTime']) end = parse_datetime(end['dateTime']) except TypeError: self.log.error('Invalid start: {} or end: {}'.format( start['dateTime'], end['dateTime'])) raise MalformedEventError() else: start = date_parser.parse(start['date']) end = date_parser.parse(end['date']) all_day = True reminders = str(reminders) # Convert google's notion of status into our own participants = [] for attendee in event.get('attendees', []): g_status = attendee.get('responseStatus') if g_status not in GoogleEventsProvider.status_map: raise MalformedEventError() status = GoogleEventsProvider.status_map[g_status] email = attendee.get('email') if not email: raise MalformedEventError() name = attendee.get('displayName') notes = None guests = 0 if 'additionalGuests' in attendee: guests = attendee['additionalGuests'] elif 'comment' in attendee: notes = attendee['comment'] participants.append({ 'email_address': email, 'name': name, 'status': status, 'notes': notes, 'guests': guests }) if 'guestsCanModify' in event: read_only = False owner = '' if 'creator' in event: creator = event['creator'] if 'self' in creator: is_owner = True read_only = False owner = u'{} <{}>'.format(creator.get('displayName', ''), creator.get('email', '')) except (KeyError, AttributeError): raise MalformedEventError() return Event(namespace_id=self.namespace_id, uid=uid, provider_name=self.PROVIDER_NAME, raw_data=raw_data, title=title, description=description, location=location, reminders=reminders, recurrence=recurrence, start=start, end=end, owner=owner, is_owner=is_owner, busy=busy, all_day=all_day, read_only=read_only, source='remote', participants=participants)
def _parse_event(self, cal_info, event): """Constructs a Calendar object from a Google calendar entry. Parameters ---------- google_calendar: gdata.calendar.entry.CalendarEntry The Google calendar entry to parse. Returns ------- ..models.tables.base.Calendar A corresponding Inbox Calendar instance. Raises ------ AttributeError If the calendar data could not be parsed correctly. """ try: uid = str(event['id']) # The entirety of the raw event data in json representation. raw_data = str(event) # 'cancelled' events signify those instances within a series # that have been cancelled (for that given series). As such, # since full support for dealing with single instances within # a reocurring event series is not added, right now we just # treat this event as 'malformed'. -cg3 # TODO: Add support for reocurring events (see ways to handle # this generically across providers) if 'status' in event and event['status'] == 'cancelled': raise MalformedEventError() subject = event.get('summary', '') body = event.get('description', None) location = event.get('location', None) all_day = False locked = True start = event['start'] end = event['end'] recurrence = str(event.get('recurrence', None)) busy = event.get('transparency', True) if busy == 'transparent': busy = False reminders = [] if 'dateTime' in start: if event['reminders']['useDefault']: reminder_source = cal_info['defaultReminders'] elif 'overrides' in event['reminders']: reminder_source = event['reminders']['overrides'] else: reminder_source = None if reminder_source: for reminder in reminder_source: reminders.append(reminder['minutes']) start = self._parse_datetime(start['dateTime']) end = self._parse_datetime(end['dateTime']) else: start = date_parser.parse(start['date']) end = date_parser.parse(end['date']) all_day = True reminders = str(reminders) if 'self' in event['creator']: locked = False elif 'guestsCanModify' in event: locked = False time_zone = cal_info['timeZone'] time_zone = 0 # FIXME: this ain't right -cg3 except (KeyError, AttributeError): raise MalformedEventError() return Event(account_id=self.account_id, uid=uid, provider_name=self.PROVIDER_NAME, raw_data=raw_data, subject=subject, body=body, location=location, reminders=reminders, recurrence=recurrence, start=start, end=end, busy=busy, all_day=all_day, locked=locked, time_zone=time_zone, source='remote')
def parse_event(self, event, extra): user_id = extra['user_id'] stored_uids = extra['stored_uids'] try: uid = str(event['id']) if uid in stored_uids: raise MalformedEventError() # The entirety of the raw event data in json representation. raw_data = str(event) title = event.get('name', '') description = event.get('description', None) location = event.get('location', None) all_day = event.get('is_all_day_event', False) read_only = True is_owner = False owner = None start = parse_datetime(event['start_time']) end = parse_datetime(event['end_time']) # See if we made the event if 'from' in event['from']: if event['from'].get('id') == user_id: is_owner = True read_only = False else: is_owner = False owner = event['from'].get('name') recurrence = event['recurrence'] if event['is_recurrent'] else None busy = event['availability'] == 'busy' reminder_time = event.get('reminder_time') reminders = str([reminder_time] if reminder_time else []) participants = [] except (KeyError, AttributeError): raise MalformedEventError() stored_uids.append(uid) return Event(namespace_id=self.namespace_id, uid=uid, provider_name=self.PROVIDER_NAME, raw_data=raw_data, title=title, description=description, location=location, reminders=reminders, recurrence=recurrence, start=start, end=end, busy=busy, all_day=all_day, read_only=read_only, is_owner=is_owner, owner=owner, source='remote', participants=participants)