Example #1
0
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:
        valid_event(data)
    except InputError as e:
        return err(404, e.message)

    subject = data.get('subject', '')
    body = data.get('body')
    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_contact = events.crud.create(g.namespace, g.db_session, subject, body,
                                     location, reminders, recurrence, when,
                                     participants)
    return g.encoder.jsonify(new_contact)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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:
        valid_event(data)
    except InputError as e:
        return err(404, e.message)

    start = datetime.utcfromtimestamp(int(data.get("start")))
    end = datetime.utcfromtimestamp(int(data.get("end")))
    subject = data.get("subject", "")
    body = data.get("body")
    location = data.get("location")
    reminders = data.get("reminders")
    recurrence = data.get("recurrence")
    busy = int(data.get("busy"))
    all_day = int(data.get("all_day"))
    participants = data.get("participants", [])
    for p in participants:
        if "status" not in p:
            p["status"] = "noreply"

    new_contact = events.crud.create(
        g.namespace,
        g.db_session,
        subject,
        body,
        location,
        reminders,
        recurrence,
        start,
        end,
        busy,
        all_day,
        participants,
    )
    return g.encoder.jsonify(new_contact)
Example #7
0
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:
        valid_event(data)
    except InputError as e:
        return err(404, e.message)

    start = datetime.utcfromtimestamp(int(data.get('start')))
    end = datetime.utcfromtimestamp(int(data.get('end')))
    subject = data.get('subject', '')
    body = data.get('body')
    location = data.get('location')
    reminders = data.get('reminders')
    recurrence = data.get('recurrence')
    busy = int(data.get('busy'))
    all_day = int(data.get('all_day'))
    participants = data.get('participants', [])
    for p in participants:
        if 'status' not in p:
            p['status'] = 'noreply'

    new_contact = events.crud.create(g.namespace, g.db_session,
                                     subject,
                                     body,
                                     location,
                                     reminders,
                                     recurrence,
                                     start,
                                     end,
                                     busy,
                                     all_day,
                                     participants)
    return g.encoder.jsonify(new_contact)
Example #8
0
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)
Example #9
0
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)