def handle_command(self, args=None): if args is None: raise ValueError('args can\'t be None') if args.sub_command == self.COMMAND_NAME: project = None tagdocuments = [] if args.project is not None and args.project != '': # check for Project try: project = ProjectDocument.objects.get(title=args.project) except ProjectDocument.DoesNotExist as e: raise ProjectNotKnown('{0} is not in the Project List. Add it first'.format(args.project)) if args.tags is not None and args.tags != '': taglist = args.tags.split(',') for i in taglist: tagdoc = TagDocument(tag=i).save() tagdocuments.append(tagdoc) task = TaskDocument() task.title = args.tasktitle task.project = project task.status = 'new' task.created_at = datetime.datetime.utcnow() task.updated_at = task.created_at task.tags = tagdocuments task.user = self._username task.save() print('Task \'{0}\' (ID: {1}) added'.format(task.title, task.counter))
def _generate_list(self, listtype='short', status='all'): format = '' if listtype == 'short': format = '{0:>10} {1:<10} {2:<40}' print(format.format('ID', 'Status', 'Task')) if listtype == 'long': format = '{0:>10} {1:<10} {2:<40} {3:^20} {4:^20}' print( format.format('ID', 'Status', 'Task', 'Created at', 'Updated At')) if listtype == 'detail': format = '{0:>10} {1:<10} {2:<40} {3:<20} {4:^20} {5:^20} {6:<30}' print( format.format('ID', 'Status', 'Task', 'Project', 'Created at', 'Updated At', 'Tags')) print('{0:=<{1}}'.format('', self.screen_cols)) if status != 'all' and status not in self.STATUS_CHOICES: raise ValueError( '{0} is not a valid status. Valid states are {1}'.format( status, self.STATUS_CHOICES)) tasklist = [] if status == 'all': tasklist = TaskDocument.objects else: tasklist = TaskDocument.objects(status=status) for task in tasklist: self._output(listtype, format, task) print('{0:=<{1}}'.format('', self.screen_cols)) print('Number of Tasks: {0:>10}'.format(len(tasklist)))
def _generate_list(self, listtype='short', status='all'): format = '' if listtype == 'short': format = '{0:>10} {1:<10} {2:<40}' print(format.format('ID', 'Status', 'Task')) if listtype == 'long': format = '{0:>10} {1:<10} {2:<40} {3:^20} {4:^20}' print(format.format('ID', 'Status', 'Task', 'Created at', 'Updated At')) if listtype == 'detail': format = '{0:>10} {1:<10} {2:<40} {3:<20} {4:^20} {5:^20} {6:<30}' print(format.format('ID', 'Status', 'Task', 'Project', 'Created at', 'Updated At', 'Tags')) print('{0:=<{1}}'.format('', self.screen_cols)) if status != 'all' and status not in self.STATUS_CHOICES: raise ValueError('{0} is not a valid status. Valid states are {1}'.format(status, self.STATUS_CHOICES)) tasklist = [] if status == 'all': tasklist = TaskDocument.objects else: tasklist = TaskDocument.objects(status=status) for task in tasklist: self._output(listtype, format, task) print('{0:=<{1}}'.format('', self.screen_cols)) print('Number of Tasks: {0:>10}'.format(len(tasklist)))
def handle_command(self, args=None): if args is None: raise ValueError('args can\'t be None') if args.sub_command == self.COMMAND_NAME: project = None tagdocuments = [] if args.project is not None and args.project != '': # check for Project try: project = ProjectDocument.objects.get(title=args.project) except ProjectDocument.DoesNotExist as e: raise ProjectNotKnown( '{0} is not in the Project List. Add it first'.format( args.project)) if args.tags is not None and args.tags != '': taglist = args.tags.split(',') for i in taglist: tagdoc = TagDocument(tag=i).save() tagdocuments.append(tagdoc) task = TaskDocument() task.title = args.tasktitle task.project = project task.status = 'new' task.created_at = datetime.datetime.utcnow() task.updated_at = task.created_at task.tags = tagdocuments task.user = self._username task.save() print('Task \'{0}\' (ID: {1}) added'.format( task.title, task.counter))