Skip to content

Slugs

DatastoreSlug

Bases: DomainObject

Object for a datastore slug row.

Source code in ckanext/versioned_datastore/model/slugs.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class DatastoreSlug(DomainObject):
    """
    Object for a datastore slug row.
    """

    def get_slug_string(self):
        """
        Returns the slug string to be used for this slug. This will be the first non-
        None value from the following attributes in this order: reserved_pretty_slug,
        pretty_slug or id.

        :returns: the slug string
        """
        if self.reserved_pretty_slug is not None:
            return self.reserved_pretty_slug
        elif self.pretty_slug is not None:
            return self.pretty_slug
        else:
            return self.id

    @staticmethod
    def on_slug(slug_string):
        """
        Returns an or query that can be used to find the slug in the database with the
        passed slug string.

        :param slug_string: the slug string
        :returns: an or filter
        """
        return or_(
            DatastoreSlug.id == slug_string,
            DatastoreSlug.pretty_slug == slug_string,
            DatastoreSlug.reserved_pretty_slug == slug_string,
        )

get_slug_string()

Returns the slug string to be used for this slug. This will be the first non- None value from the following attributes in this order: reserved_pretty_slug, pretty_slug or id.

Returns:

Type Description

the slug string

Source code in ckanext/versioned_datastore/model/slugs.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def get_slug_string(self):
    """
    Returns the slug string to be used for this slug. This will be the first non-
    None value from the following attributes in this order: reserved_pretty_slug,
    pretty_slug or id.

    :returns: the slug string
    """
    if self.reserved_pretty_slug is not None:
        return self.reserved_pretty_slug
    elif self.pretty_slug is not None:
        return self.pretty_slug
    else:
        return self.id

on_slug(slug_string) staticmethod

Returns an or query that can be used to find the slug in the database with the passed slug string.

Parameters:

Name Type Description Default
slug_string

the slug string

required

Returns:

Type Description

an or filter

Source code in ckanext/versioned_datastore/model/slugs.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@staticmethod
def on_slug(slug_string):
    """
    Returns an or query that can be used to find the slug in the database with the
    passed slug string.

    :param slug_string: the slug string
    :returns: an or filter
    """
    return or_(
        DatastoreSlug.id == slug_string,
        DatastoreSlug.pretty_slug == slug_string,
        DatastoreSlug.reserved_pretty_slug == slug_string,
    )

NavigationalSlug

Bases: DomainObject

Object for a navigational slug.

Source code in ckanext/versioned_datastore/model/slugs.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
class NavigationalSlug(DomainObject):
    """
    Object for a navigational slug.
    """

    prefix = 'nav-'
    version = None

    @property
    def query_version(self):
        return get_latest_query_version()

    def get_slug_string(self):
        """
        Returns the slug string to be used for this slug.

        :returns: the slug string
        """
        return NavigationalSlug.prefix + self.id

    @staticmethod
    def on_slug(slug_string):
        """
        Returns an or query that can be used to find the slug in the database with the
        passed slug string.

        :param slug_string: the slug string
        :returns: a filter
        """
        return NavigationalSlug.id == slug_string[len(NavigationalSlug.prefix) :]

get_slug_string()

Returns the slug string to be used for this slug.

Returns:

Type Description

the slug string

Source code in ckanext/versioned_datastore/model/slugs.py
 94
 95
 96
 97
 98
 99
100
def get_slug_string(self):
    """
    Returns the slug string to be used for this slug.

    :returns: the slug string
    """
    return NavigationalSlug.prefix + self.id

on_slug(slug_string) staticmethod

Returns an or query that can be used to find the slug in the database with the passed slug string.

Parameters:

Name Type Description Default
slug_string

the slug string

required

Returns:

Type Description

a filter

Source code in ckanext/versioned_datastore/model/slugs.py
102
103
104
105
106
107
108
109
110
111
@staticmethod
def on_slug(slug_string):
    """
    Returns an or query that can be used to find the slug in the database with the
    passed slug string.

    :param slug_string: the slug string
    :returns: a filter
    """
    return NavigationalSlug.id == slug_string[len(NavigationalSlug.prefix) :]