コード例 #1
0
ファイル: slurper.py プロジェクト: arjunpola/mldata
    def create_data(self, parsed, fname):
        """Create a repository Data object.

        @param parsed: parsed information from HTML
        @type parsed: dict with fields name, source, description, type, files
        @param fname: filename of data file (often != parsed['files'])
        @type fname: string
        @return: a repository Data object
        @rtype: repository.Data
        """
        if self.options.convert_exist:
            return self._convert_exist(parsed['name'], fname)

        obj = Data(
            pub_date=datetime.datetime.now(),
            name=parsed['name'],
            source=parsed['source'],
            description=parsed['description'],
            summary=parsed['summary'],
            version=1,
            is_public=False,
            is_current=True,
            is_approved=True,
            user_id=1,
            license_id=parsed['license'],
            format=ml2h5.fileformat.get(fname),
        )
        try:
            obj = self._add_slug(obj)
            self.progress('Creating Data item ' + obj.name + '.', 4)
        except IntegrityError:
            self.warn('Slug already exists, skipping Data item ' + obj.name + '!')
            slug=slugify(parsed['name'])
            try:
                obj=Data.objects.get(slug=slug)
                if obj.name != parsed['name']:
                    raise DoesNotExist
                self.progress('Updating Data item ' + obj.name + '.', 4)
                
                obj.pub_date=datetime.datetime.now()
                obj.name=parsed['name']
                obj.source=parsed['source']
                obj.description=parsed['description']
                obj.summary=parsed['summary']
                obj.version=1
                obj.is_public=False
                obj.is_current=True
                obj.is_approved=True
                obj.user_id=1
                obj.license_id=parsed['license']
                obj.format=ml2h5.fileformat.get(fname)

            except DoesNotExist:
                self.problematic.append(parsed['name'])
                return None

        obj.tags = self._get_tags(parsed['tags'], obj)
        obj.save() # need to save before publications can be added
        self._add_publications(obj, parsed['publications'])
        obj = self._handle_file(obj, fname)

        # make it available after everything went alright
        obj.is_public = True
        obj.save()

        parsed['name'] = obj.name # in case it changed due to slug
        return obj
コード例 #2
0
ファイル: slurper.py プロジェクト: joskid/mldata
    def create_data(self, parsed, fname):
        """Create a repository Data object.

        @param parsed: parsed information from HTML
        @type parsed: dict with fields name, source, description, type, files
        @param fname: filename of data file (often != parsed['files'])
        @type fname: string
        @return: a repository Data object
        @rtype: repository.Data
        """
        if self.options.convert_exist:
            return self._convert_exist(parsed['name'], fname)

        obj = Data(
            pub_date=datetime.datetime.now(),
            name=parsed['name'],
            source=parsed['source'],
            description=parsed['description'],
            summary=parsed['summary'],
            version=1,
            is_public=False,
            is_current=True,
            is_approved=True,
            user_id=1,
            license_id=parsed['license'],
            format=ml2h5.fileformat.get(fname),
        )
        try:
            obj = self._add_slug(obj)
            self.progress('Creating Data item ' + obj.name + '.', 4)
        except IntegrityError:
            self.warn('Slug already exists, skipping Data item ' + obj.name +
                      '!')
            slug = slugify(parsed['name'])
            try:
                obj = Data.objects.get(slug=slug)
                if obj.name != parsed['name']:
                    raise DoesNotExist
                self.progress('Updating Data item ' + obj.name + '.', 4)

                obj.pub_date = datetime.datetime.now()
                obj.name = parsed['name']
                obj.source = parsed['source']
                obj.description = parsed['description']
                obj.summary = parsed['summary']
                obj.version = 1
                obj.is_public = False
                obj.is_current = True
                obj.is_approved = True
                obj.user_id = 1
                obj.license_id = parsed['license']
                obj.format = ml2h5.fileformat.get(fname)

            except DoesNotExist:
                self.problematic.append(parsed['name'])
                return None

        obj.tags = self._get_tags(parsed['tags'], obj)
        obj.save()  # need to save before publications can be added
        self._add_publications(obj, parsed['publications'])
        obj = self._handle_file(obj, fname)

        # make it available after everything went alright
        obj.is_public = True
        obj.save()

        parsed['name'] = obj.name  # in case it changed due to slug
        return obj