def create_task(self, parsed, data, splitnames=None): """Create a repository Task object. @param parsed: parsed information from HTML @type parsed: dict with fields name, source, description, type, files @param data: Data object @type data: repository.Data @param splitnames: names of splitfiles related to this task @type splitnames: list of strings @return: a repository Task object @rtype: repository.Task """ if not data: return None name = 'task_' + parsed['name'] obj = Task( pub_date=datetime.datetime.now(), name=name, description=parsed['description'], summary=parsed['summary'], version=1, is_public=False, is_current=True, user_id=1, license_id=1, performance_measure_id=1, data=data, tags=self._get_tags(parsed['tags']), ) try: obj = self._add_slug(obj) except IntegrityError: self.warn('Slug already exists, skipping Task item ' + name + '!') self.problematic.append(name) return None self.progress('Creating Task item ' + obj.name + '.', 4) if parsed['task'] in ('Binary', 'MultiClass'): ttype = 'Classification' else: ttype = parsed['task'] obj.type=ttype obj.save() self._add_taskdata(obj, splitnames) # obj needs pk first for many-to-many self._add_publications(obj, parsed['publications']) obj.is_public = True obj.save() return obj
def create_task(self, parsed, data, splitnames=None): """Create a repository Task object. @param parsed: parsed information from HTML @type parsed: dict with fields name, source, description, type, files @param data: Data object @type data: repository.Data @param splitnames: names of splitfiles related to this task @type splitnames: list of strings @return: a repository Task object @rtype: repository.Task """ if not data: return None name = 'task_' + parsed['name'] obj = Task( pub_date=datetime.datetime.now(), name=name, description=parsed['description'], summary=parsed['summary'], version=1, is_public=False, is_current=True, user_id=1, license_id=1, performance_measure_id=1, data=data, tags=self._get_tags(parsed['tags']), ) try: obj = self._add_slug(obj) except IntegrityError: self.warn('Slug already exists, skipping Task item ' + name + '!') self.problematic.append(name) return None self.progress('Creating Task item ' + obj.name + '.', 4) if parsed['task'] in ('Binary', 'MultiClass'): ttype = 'Classification' else: ttype = parsed['task'] obj.type = ttype obj.save() self._add_taskdata(obj, splitnames) # obj needs pk first for many-to-many self._add_publications(obj, parsed['publications']) obj.is_public = True obj.save() return obj