예제 #1
0
def todo_add(caldav_conn, args):
    ## TODO: copied from calendar_add, should probably be consolidated
    if args.icalendar or args.nocaldav:
        niy(feature="add todo item by icalendar raw stdin data or create raw icalendar data to stdout")
    if args.todo_uid:
        uid = args.todo_uid
    else:
        uid = uuid.uuid1()
    cal = Calendar()
    cal.add('prodid', '-//{author_short}//{product}//{language}'.format(author_short=__author_short__, product=__product__, language=args.language))
    cal.add('version', '2.0')
    todo = Todo()
    todo.add('dtstamp', _now())

    for setarg in ('due', 'dtstart'):
        if getattr(args, 'set_'+setarg):
            if type(getattr(args, 'set_'+setarg)) == str:
                val = dateutil.parser.parse(getattr(args, 'set_'+setarg))
            else:
                val = getattr(args, 'set_'+setarg)
            todo.add(setarg, val)
    todo.add('uid', str(uid))
    todo.add('summary', ' '.join(args.summaryline))
    todo.add('status', 'NEEDS-ACTION')

    if args.is_child:
        for t in todo_select(caldav_conn, args):
            todo.add('related-to', t.instance.vtodo.uid.value)
            rt = t.instance.vtodo.add('related-to')
            rt.params['RELTYPE']=['CHILD']
            rt.value = str(uid)
            t.save()

    for attr in vtodo_txt_one:
        if attr == 'summary':
            continue
        val = getattr(args, 'set_'+attr)
        if val:
            todo.add(attr, val)
    ## TODO: this doesn't currently work quite the way we'd like it to
    ## work (it adds to lines to the ical, and vobject cares only
    ## about one of them), and if we do get it to work, we'd like to
    ## refactor and get the same logic in the edit-function
    for attr in vtodo_txt_many:
        val = getattr(args, 'set_'+attr)
        if val:
            vals = val.split(',')
            todo.add(attr, vals)

    if args.alarm is not None:
        alarm = create_alarm(' '.join(args.summaryline), parse_time_delta(args.alarm))
        todo.add_component(alarm)

    cal.add_component(todo)
    _calendar_addics(caldav_conn, cal.to_ical(), uid, args)
    print("Added todo item with uid=%s" % uid)
예제 #2
0
def todo_add(caldav_conn, args):
    ## TODO: copied from calendar_add, should probably be consolidated
    if args.icalendar or args.nocaldav:
        niy(feature="add todo item by icalendar raw stdin data or create raw icalendar data to stdout")
    if args.todo_uid:
        uid = args.todo_uid
    else:
        uid = uuid.uuid1()
    cal = Calendar()
    cal.add('prodid', '-//{author_short}//{product}//{language}'.format(author_short=__author_short__, product=__product__, language=args.language))
    cal.add('version', '2.0')
    todo = Todo()
    todo.add('dtstamp', _now())

    for setarg in ('due', 'dtstart'):
        if getattr(args, 'set_'+setarg):
            if type(getattr(args, 'set_'+setarg)) == str:
                val = dateutil.parser.parse(getattr(args, 'set_'+setarg))
            else:
                val = getattr(args, 'set_'+setarg)
        todo.add(setarg, val)
    todo.add('uid', str(uid))
    todo.add('summary', ' '.join(args.summaryline))
    todo.add('status', 'NEEDS-ACTION')

    if args.is_child:
        for t in todo_select(caldav_conn, args):
            todo.add('related-to', t.instance.vtodo.uid.value)
            rt = t.instance.vtodo.add('related-to')
            rt.params['RELTYPE']=['CHILD']
            rt.value = str(uid)
            t.save()

    for attr in vtodo_txt_one:
        if attr == 'summary':
            continue
        val = getattr(args, 'set_'+attr)
        if val:
            todo.add(attr, val)
    ## TODO: this doesn't currently work quite the way we'd like it to
    ## work (it adds to lines to the ical, and vobject cares only
    ## about one of them), and if we do get it to work, we'd like to
    ## refactor and get the same logic in the edit-function
    for attr in vtodo_txt_many:
        val = getattr(args, 'set_'+attr)
        if val:
            vals = val.split(',')
            todo.add(attr, vals)

    if args.alarm is not None:
        alarm = create_alarm(' '.join(args.summaryline), parse_time_delta(args.alarm))
        todo.add_component(alarm)

    cal.add_component(todo)
    _calendar_addics(caldav_conn, cal.to_ical(), uid, args)
    print("Added todo item with uid=%s" % uid)
예제 #3
0
def task_create(task=None, title='Task title', due=None, alarm=None, note='', sequence=0, uid=None, priority=None, next_action=None):
  from uuid import uuid4
  from icalendar import Calendar, Todo, Alarm
  if task is not None:
    title = task.name
    due = task.due
    alarm = task.alarm
    note = task.note
    sequence = task.sequence
    priority = task.priority
    next_action = task.next_action
  if (due is not None and alarm is None):
    # Should not arrive here, this should have already have been handled
    alarm = due
    if is_same_time(due, universe.defaulttime.due):
      # Warning for day events 1800 - 1000 = 8 hours
      alarm = due + universe.defaulttime.alldaydiff
    else: 
      # Default warning of an hour
      alarm = due + universe.defaulttime.diff
  if (alarm is not None and due is None):
    due = alarm
  # alarm now defunct - just use due
  cal = Calendar()
  cal.add('prodid', '-//enoky//v0.1//EN')
  cal.add('version', '2.0')

  todo = Todo()
  todo.add('summary', title)
  if priority is not None:
    todo.add('priority', priority)
  if due is not None:
    todo.add('due', due)
    todo.add('dtstart', due)
  todo.add('status', 'NEEDS-ACTION')
  todo.add('dtstamp', universe.now)
  todo.add('created', universe.now)
  if uid is None:
    uid = uuid4()
  todo['uid'] = uid
  todo.add('sequence', sequence)
  notenext = note
  if (next_action is not None) and (len(next_action) > 0):
    if len(notenext) > 0:
      notenext = notenext + '\n'
    notenext = notenext + universe.next_char + ' ' + next_action.lstrip()
  if len(notenext) > 0:
    todo.add('description', notenext)

  if alarm is not None:
    valarm = Alarm()
    valarm['uid'] = uuid4()
    valarm.add('trigger', alarm)
    # Possibly not needed. How add due date?!
    valarm.add('description', 'Event reminder')
    valarm.add('action', 'DISPLAY')
    todo.add_component(valarm)

  cal.add_component(todo)
  vcal = cal.to_ical()
  return vcal
예제 #4
0
def TodoFromJSON(cal, data):
    tz = pytz.timezone("Europe/Budapest")
    if 'dynalist_info' in data:
        if data['note'] == '':
            description = data['dynalist_info']
        else:
            description = data['note'] + '\n' + data['dynalist_info']
    else:
        description = data['note']
    duedate = data['date'].replace('-', '')
    time = data['time'].replace(':', '')
    if not duedate == '':
        Y = int(duedate[:4])
        m = int(duedate[4:6])
        D = int(duedate[6:8])
        if not time == '':
            H = int(time[:2])
            M = int(time[2:4])

    if cal is None:
        cal = Calendar()
        cal.add('prodid', '-//Dynatask//')
        cal.add('version', '2.0')
        todo = Todo()
        if 'dynalist_id' in data:
            todo.add('uid', data['caldav_uid'])
            todo.add('X-DYNATASK-DYNALISTID', data['dynalist_id'])
        elif 'caldav_uid' in data:
            todo.add('uid', data['caldav_uid'])
        todo.add('summary', data['name'])
        now = datetime.now(pytz.utc)
        todo.add('dtstamp', now)
        todo.add('created', now)
        todo.add('last-modified', now)
        if not duedate == '':
            if not time == '':
                todo.add('due', datetime(Y, m, D, H, M, tzinfo=tz))
            else:
                todo.add('due', datetime(Y, m, D).date())
        todo.add('description', description)

        if 'checked' in data:
            if data['checked']:
                todo.add('status', 'COMPLETED')
                todo.add('completed', datetime.now(pytz.utc))
                todo.add('percent-complete', '100')
            else:
                todo.add('status', 'NEEDS-ACTION')
                todo.add('percent-complete', '0')

        if 'caldav_parent' in data:
            todo.add('related-to', data['caldav_parent'])

        if 'alarm' in data and not data['alarm'] == '':
            alarm = Alarm()
            alarm.add('action', 'DISPLAY')
            alarm.add('trigger', timedelta(minutes=-int(data['alarm'])))
            todo.add_component(alarm)

        cal.add_component(todo)
        return (cal)