def get_pkg_dict(cls, resource, ldr):
        from ckan import model

        pkg_dict = OrderedDict()
        extras = OrderedDict()
        uri = str(resource.identifier)
        pkg_dict['title'] = unicode(resource[RDFS.label].next())
        extras['registry_uri'] = uri

        # Create or update?
        pkg = model.Session.query(model.Package) \
                .filter_by(state='active') \
                .join(model.PackageExtra) \
                .filter_by(state='active') \
                .filter_by(key='registry_uri') \
                .filter_by(value=uri).first()
        if pkg:
            pkg_dict['id'] = pkg.id
            pkg_dict['name'] = pkg.name
            action = 'update'
        else:
            pkg_dict['id'] = unicode(uuid.uuid4())
            pkg_dict['name'] = cls._gen_new_name(pkg_dict['title'])
            action = 'new'

        dgu_type = cls.get_dgu_type(resource)
        extras['data_standard_type'] = dgu_type

        resources = []
        for format_display, format_extension, format_dgu in (
                ('RDF ttl', 'ttl', 'RDF'),
                ('RDF/XML', 'rdf', 'RDF'),
                ('JSON-LD', 'jsonld', 'JSON')):
            url = uri + '?_format=%s' % format_extension
            resources.append({'description': '%s as %s' % (dgu_type, format_display),
                              'url': url,
                              'format': format_dgu,
                              'resource_type': 'file'})
            resources.append({'description': '%s and metadata as %s' % (dgu_type, format_display),
                              'url': url + METADATA_PARAM,
                              'format': format_dgu,
                              'resource_type': 'file'})

        pkg_dict['notes'] = unicode(resource[DCT.description].next())
        licence_url = str(resource[DCT.license].next())
        if 'open-government-licence' in licence_url:
            pkg_dict['licence_id'] = 'uk-ogl'
        else:
            extras['licence_url'] = licence_url
            # not sure how this will display as just as URL
        pkg_dict['owner_org'] = cls.get_publisher(resource).id
        resources.append({'description': 'Web page for this %s on a Linked Data Registry' % dgu_type,
                          'url': uri,
                          'format': 'HTML',
                          'resource_type': 'documentation'})
        metadata = cls.get_resource_metadata(uri)
        status = metadata[REG.status].next()
        extras['status'] = str(status).split('#')[-1]
        extras['harvested_version'] = str(metadata[OWL.versionInfo].next())
        extras['data_standard_type'] = dgu_type
        pkg_dict['type'] = 'data-standard'

        pkg_dict['extras'] = [{'key': k, 'value': v} for k, v in extras.items()]
        pkg_dict['resources'] = resources
        return pkg_dict, action
    def get_pkg_dict(cls, resource, ldr):
        from ckan import model

        pkg_dict = OrderedDict()
        extras = OrderedDict()
        uri = str(resource.identifier)
        pkg_dict['title'] = unicode(resource[RDFS.label].next())
        extras['registry_uri'] = uri

        # Create or update?
        pkg = model.Session.query(model.Package) \
                .filter_by(state='active') \
                .join(model.PackageExtra) \
                .filter_by(state='active') \
                .filter_by(key='registry_uri') \
                .filter_by(value=uri).first()
        if pkg:
            pkg_dict['id'] = pkg.id
            pkg_dict['name'] = pkg.name
            action = 'update'
        else:
            pkg_dict['id'] = unicode(uuid.uuid4())
            pkg_dict['name'] = cls._gen_new_name(pkg_dict['title'])
            action = 'new'

        dgu_type = cls.get_dgu_type(resource)
        extras['data_standard_type'] = dgu_type

        resources = []
        for format_display, format_extension, format_dgu in (('RDF ttl', 'ttl',
                                                              'RDF'),
                                                             ('RDF/XML', 'rdf',
                                                              'RDF'),
                                                             ('JSON-LD',
                                                              'jsonld',
                                                              'JSON')):
            url = uri + '?_format=%s' % format_extension
            resources.append({
                'description':
                '%s as %s' % (dgu_type, format_display),
                'url':
                url,
                'format':
                format_dgu,
                'resource_type':
                'file'
            })
            resources.append({
                'description':
                '%s and metadata as %s' % (dgu_type, format_display),
                'url':
                url + METADATA_PARAM,
                'format':
                format_dgu,
                'resource_type':
                'file'
            })

        pkg_dict['notes'] = unicode(resource[DCT.description].next())
        licence_url = str(resource[DCT.license].next())
        if 'open-government-licence' in licence_url:
            pkg_dict['licence_id'] = 'uk-ogl'
        else:
            extras['licence_url'] = licence_url
            # not sure how this will display as just as URL
        pkg_dict['owner_org'] = cls.get_publisher(resource).id
        resources.append({
            'description':
            'Web page for this %s on a Linked Data Registry' % dgu_type,
            'url':
            uri,
            'format':
            'HTML',
            'resource_type':
            'documentation'
        })
        metadata = cls.get_resource_metadata(uri)
        status = metadata[REG.status].next()
        extras['status'] = str(status).split('#')[-1]
        extras['harvested_version'] = str(metadata[OWL.versionInfo].next())
        extras['data_standard_type'] = dgu_type
        pkg_dict['type'] = 'data-standard'

        pkg_dict['extras'] = [{
            'key': k,
            'value': v
        } for k, v in extras.items()]
        pkg_dict['resources'] = resources
        return pkg_dict, action