class TwoWayNewTasksState4(BaseState): def init(self): super(TwoWayNewTasksState4, self).init('ssddfz[s]', self.newTasksCount) def handleNewObject(self, (subject, description, startDate, dueDate, completionDateTime, parentId, categories)): parent = self.taskMap[parentId] if parentId and self.taskMap.has_key( parentId) else None if self.version < 5: startDateTime = DateTime() if startDate == Date() else DateTime( year=startDate.year, month=startDate.month, day=startDate.day, hour=self.disp().settings.getint('view', 'efforthourstart')) dueDateTime = DateTime() if dueDate == Date() else DateTime( year=dueDate.year, month=dueDate.month, day=dueDate.day, hour=self.disp().settings.getint('view', 'efforthourend')) task = Task(subject=subject, description=description, startDateTime=startDateTime, dueDateTime=dueDateTime, completionDateTime=completionDateTime, parent=parent) self.disp().window.addIPhoneTask(task, [self.categoryMap[catId] for catId in categories \ if self.categoryMap.has_key(catId)]) self.disp().log(_('New task %s'), task.id()) self.taskMap[task.id()] = task self.pack('s', task.id())
def pack(self, value): if value == DateTime(): value = None if value is not None: value = value.replace(microsecond=0, tzinfo=None).isoformat(sep=' ') return super(InfiniteDateTimeItem, self).pack(value)
def feed(self, data): super(InfiniteDateTimeItem, self).feed(data) if self.state == 2: if self.value is None: self.value = DateTime() else: self.value = parseDateTime(self.value)
def handleNewObject(self, args): reminderDateTime = None recurrence = None priority = 0 if self.version < 2: subject, taskId, description, startDate, dueDate, completionDate = args categories = None elif self.version < 5: subject, taskId, description, startDate, dueDate, completionDate, categories = args categories = [self.categoryMap[catId] for catId in categories] else: (subject, taskId, description, startDate, dueDate, completionDate, reminderDateTime, priority, hasRecurrence, recPeriod, recRepeat, recSameWeekday, categories) = args categories = [self.categoryMap[catId] for catId in categories] if hasRecurrence: recurrence = Recurrence(unit={ 0: 'daily', 1: 'weekly', 2: 'monthly', 3: 'yearly' }[recPeriod], amount=recRepeat, sameWeekday=recSameWeekday) if self.version < 5: startDateTime = DateTime( startDate.year, startDate.month, startDate.day, self.disp().settings.getint( 'view', 'efforthourstart')) if startDate != Date() else DateTime() dueDateTime = DateTime( dueDate.year, dueDate.month, dueDate.day, self.disp().settings.getint( 'view', 'efforthourend')) if dueDate != Date() else DateTime() completionDateTime = DateTime( completionDate.year, completionDate.month, completionDate.day ) if completionDate != Date() else DateTime() else: startDateTime = startDate dueDateTime = dueDate completionDateTime = completionDate try: task = self.taskMap[taskId] except KeyError: if self.version >= 5: self.pack('s', '') else: self.disp().log(_('Modify task %s'), task.id()) self.disp().window.modifyIPhoneTask(task, subject, description, startDateTime, dueDateTime, completionDateTime, reminderDateTime, recurrence, priority, categories) if self.version >= 5: self.pack('s', task.id())
class TwoWayNewTasksState(BaseState): def init(self): super(TwoWayNewTasksState, self).init('ssddd[s]', self.newTasksCount) def handleNewObject(self, (subject, description, startDate, dueDate, completionDate, categories)): task = Task(subject=subject, description=description, startDateTime=DateTime(startDate.year, startDate.month, startDate.day), dueDateTime=DateTime(dueDate.year, dueDate.month, dueDate.day), completionDateTime=DateTime(completionDate.year, completionDate.month, completionDate.day)) self.disp().window.addIPhoneTask(task, [self.categoryMap[catId] for catId in categories \ if self.categoryMap.has_key(catId)]) self.disp().log(_('New task %s'), task.id()) self.taskMap[task.id()] = task self.pack('s', task.id())
class FullFromDeviceTaskState(BaseState): def init(self): super(FullFromDeviceTaskState, self).init('ssddd[s]', self.taskCount) def handleNewObject(self, (subject, description, startDate, dueDate, completionDate, categories)): task = Task(subject=subject, description=description, startDateTime=DateTime(startDate.year, startDate.month, startDate.day), dueDateTime=DateTime(dueDate.year, dueDate.month, dueDate.day), completionDateTime=DateTime(completionDate.year, completionDate.month, completionDate.day)) self.disp().window.addIPhoneTask( task, [self.categoryMap[id_] for id_ in categories]) self.count += 1 self.ui.SetProgress(self.count, self.total) self.pack('s', task.id())
def parseDateTime(self, fieldValue, defaultHour=0, defaultMinute=0, defaultSecond=0, dayfirst=False): if not fieldValue: return None try: dateTime = dparser.parse(fieldValue.decode('UTF-8'), dayfirst=dayfirst, fuzzy=True).replace(tzinfo=None) hour, minute, second = dateTime.hour, dateTime.minute, dateTime.second if 0 == hour == minute == second: hour = defaultHour minute = defaultMinute second = defaultSecond return DateTime(dateTime.year, dateTime.month, dateTime.day, hour, minute, second) except: # pylint: disable=W0702 return None