def event_create_api(): g.parser.add_argument('notify_participants', type=strict_bool, location='args') args = strict_parse_args(g.parser, request.args) notify_participants = args['notify_participants'] data = request.get_json(force=True) calendar = get_calendar(data.get('calendar_id'), g.namespace, g.db_session) if calendar.read_only: raise InputError("Can't create events on read_only calendar.") valid_event(data) title = data.get('title', '') description = data.get('description') location = data.get('location') when = data.get('when') busy = data.get('busy') # client libraries can send explicit key = None automagically if busy is None: busy = True participants = data.get('participants') if participants is None: participants = [] for p in participants: if 'status' not in p: p['status'] = 'noreply' event = Event(calendar=calendar, namespace=g.namespace, uid=uuid.uuid4().hex, provider_name=g.namespace.account.provider, raw_data='', title=title, description=description, location=location, busy=busy, when=when, read_only=False, is_owner=True, participants=participants, sequence_number=0, source='local') g.db_session.add(event) g.db_session.flush() schedule_action('create_event', event, g.namespace.id, g.db_session, calendar_uid=event.calendar.uid, notify_participants=notify_participants) return g.encoder.jsonify(event)
def calendar_delete_api(public_id): calendar = get_calendar(public_id, g.namespace, g.db_session) if calendar.read_only: raise InputError("Cannot delete a read_only calendar.") result = events.crud.delete_calendar(g.namespace, g.db_session, public_id) return g.encoder.jsonify(result)
def event_create_api(): g.parser.add_argument('notify_participants', type=strict_bool, location='args') args = strict_parse_args(g.parser, request.args) notify_participants = args['notify_participants'] data = request.get_json(force=True) calendar = get_calendar(data.get('calendar_id'), g.namespace, g.db_session) if calendar.read_only: raise InputError("Can't create events on read_only calendar.") valid_event(data) title = data.get('title', '') description = data.get('description') location = data.get('location') when = data.get('when') busy = data.get('busy') # client libraries can send explicit key = None automagically if busy is None: busy = True participants = data.get('participants') if participants is None: participants = [] for p in participants: if 'status' not in p: p['status'] = 'noreply' event = Event( calendar=calendar, namespace=g.namespace, uid=uuid.uuid4().hex, provider_name=g.namespace.account.provider, raw_data='', title=title, description=description, location=location, busy=busy, when=when, read_only=False, is_owner=True, participants=participants, sequence_number=0, source='local') g.db_session.add(event) g.db_session.flush() schedule_action('create_event', event, g.namespace.id, g.db_session, calendar_uid=event.calendar.uid, notify_participants=notify_participants) return g.encoder.jsonify(event)
def calendar_delete_api(public_id): try: calendar = get_calendar(public_id, g.namespace, g.db_session) except InputError as e: return err(404, e.message) if calendar.read_only: return err(400, "Cannot delete a read_only calendar.") result = events.crud.delete_calendar(g.namespace, g.db_session, public_id) return g.encoder.jsonify(result)
def calendar_update_api(public_id): calendar = get_calendar(public_id, g.namespace, g.db_session) if calendar.read_only: raise InputError("Cannot update a read_only calendar.") data = request.get_json(force=True) result = events.crud.update_calendar(g.namespace, g.db_session, public_id, data) if result is None: raise NotFoundError("Couldn't find calendar {0}".format(public_id)) return g.encoder.jsonify(result)
def event_create_api(): # Handle ical uploads if request.headers['content-type'] == 'text/calendar': ics_str = request.data new_events = events.crud.create_from_ics(g.namespace, g.db_session, ics_str) if not new_events: return err(400, "Couldn't parse .ics file.") return g.encoder.jsonify(new_events) data = request.get_json(force=True) try: calendar = get_calendar(data.get('calendar_id'), g.namespace, g.db_session) except InputError as e: return err(404, e.message) if calendar.read_only: return err(400, "Can't create events on read_only calendar.") try: valid_event(data) except InputError as e: return err(404, e.message) title = data.get('title', '') description = data.get('description') location = data.get('location') reminders = data.get('reminders') recurrence = data.get('recurrence') when = data.get('when') participants = data.get('participants', []) for p in participants: if 'status' not in p: p['status'] = 'noreply' new_event = events.crud.create(g.namespace, g.db_session, calendar, title, description, location, reminders, recurrence, when, participants) schedule_action('create_event', new_event, g.namespace.id, g.db_session) return g.encoder.jsonify(new_event)
def event_create_api(): # Handle ical uploads if request.headers.get('content-type') == 'text/calendar': ics_str = request.data new_events = events.crud.create_from_ics(g.namespace, g.db_session, ics_str) if not new_events: return err(400, "Couldn't parse .ics file.") return g.encoder.jsonify(new_events) data = request.get_json(force=True) try: calendar = get_calendar(data.get('calendar_id'), g.namespace, g.db_session) except InputError as e: return err(404, str(e)) if calendar.read_only: return err(400, "Can't create events on read_only calendar.") try: valid_event(data) except InputError as e: return err(404, str(e)) title = data.get('title', '') description = data.get('description') location = data.get('location') reminders = data.get('reminders') recurrence = data.get('recurrence') when = data.get('when') participants = data.get('participants', []) for p in participants: if 'status' not in p: p['status'] = 'noreply' new_event = events.crud.create(g.namespace, g.db_session, calendar, title, description, location, reminders, recurrence, when, participants) schedule_action('create_event', new_event, g.namespace.id, g.db_session) return g.encoder.jsonify(new_event)
def calendar_update_api(public_id): try: calendar = get_calendar(public_id, g.namespace, g.db_session) except InputError as e: return err(404, e.message) if calendar.read_only: return err(400, "Cannot update a read_only calendar.") data = request.get_json(force=True) result = events.crud.update_calendar(g.namespace, g.db_session, public_id, data) if result is None: return err(404, "Couldn't find calendar with id {0}".format(public_id)) return g.encoder.jsonify(result)
def calendar_update_api(public_id): try: calendar = get_calendar(public_id, g.namespace, g.db_session) except InputError as e: return err(404, e.message) if calendar.read_only: return err(400, "Cannot update a read_only calendar.") data = request.get_json(force=True) result = events.crud.update_calendar(g.namespace, g.db_session, public_id, data) if result is None: return err(404, "Couldn't find calendar with id {0}". format(public_id)) return g.encoder.jsonify(result)
def event_create_api(): data = request.get_json(force=True) calendar = get_calendar(data.get('calendar_id'), g.namespace, g.db_session) if calendar.read_only: raise InputError("Can't create events on read_only calendar.") valid_event(data) title = data.get('title', '') description = data.get('description') location = data.get('location') when = data.get('when') busy = data.get('busy', True) participants = data.get('participants', []) for p in participants: if 'status' not in p: p['status'] = 'noreply' event = Event(calendar=calendar, namespace=g.namespace, uid=uuid.uuid4().hex, provider_name=g.namespace.account.provider, raw_data='', title=title, description=description, location=location, busy=busy, when=when, read_only=False, is_owner=True, participants=participants, source='local') g.db_session.add(event) g.db_session.flush() schedule_action('create_event', event, g.namespace.id, g.db_session, calendar_uid=event.calendar.uid) return g.encoder.jsonify(event)
def event_create_api(): data = request.get_json(force=True) calendar = get_calendar(data.get('calendar_id'), g.namespace, g.db_session) if calendar.read_only: raise InputError("Can't create events on read_only calendar.") valid_event(data) title = data.get('title', '') description = data.get('description') location = data.get('location') when = data.get('when') busy = data.get('busy', True) participants = data.get('participants', []) for p in participants: if 'status' not in p: p['status'] = 'noreply' event = Event( calendar=calendar, namespace=g.namespace, uid=uuid.uuid4().hex, provider_name=g.namespace.account.provider, raw_data='', title=title, description=description, location=location, busy=busy, when=when, read_only=False, is_owner=True, participants=participants, source='local') g.db_session.add(event) g.db_session.flush() schedule_action('create_event', event, g.namespace.id, g.db_session, calendar_uid=event.calendar.uid) return g.encoder.jsonify(event)