Slugs
clean_nav_slugs(before=None)
¶
Delete old/expired navigational slugs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
before
|
a datetime object; slugs created before this time will be removed (defaults to 2 days ago) |
None
|
Returns:
| Type | Description |
|---|---|
int
|
the number of deleted slugs |
Source code in ckanext/versioned_datastore/lib/query/slugs/slugs.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
create_slug(query, pretty_slug=True, attempts=5)
¶
Creates a new slug in the database and returns the saved DatastoreSlug object. If a slug already exists under the query hash then the existing slug entry is returned. In addition to the slug object, also returned is information about whether the slug was new or not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretty_slug
|
whether to generate a pretty slug or just use the uuid id of the slug, by default this is True |
True
|
|
attempts
|
how many times to try creating a pretty slug, default: 5 |
5
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, Optional[DatastoreSlug]]
|
a 2-tuple containing a boolean indicating whether the slug object returned was newly created and the DatastoreSlug object itself. If we couldn't create a slug object for some reason then (False, None) is returned. |
Source code in ckanext/versioned_datastore/lib/query/slugs/slugs.py
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 80 81 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 | |
generate_pretty_slug(word_lists=(list_one, list_two, list_three))
¶
Generate a new slug using the adjective and animal lists available. The default word_lists value is a trio of lists: (adjectives, adjectives, animals). This produces >31,000,000 unique combinations which should be more than enough! This function does have the potential to produce duplicate adjectives (for example, green-green-llama) but the chances are really low and it doesn't really matter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
word_lists
|
a sequence of word lists to choose from |
(list_one, list_two, list_three)
|
Returns:
| Type | Description |
|---|---|
str
|
the slug |
Source code in ckanext/versioned_datastore/lib/query/slugs/slugs.py
40 41 42 43 44 45 46 47 48 49 50 51 | |
generate_query_hash(query)
¶
Given a query and the parameters required to run it, create a unique id for it (a hash) and returns it. The hashing algorithm used is sha1 and the output will be a 40 character hexidecimal string.
Returns:
| Type | Description |
|---|---|
str
|
a unique id for the query, which is a hash of the query and parameters |
Source code in ckanext/versioned_datastore/lib/query/slugs/slugs.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
reserve_slug(reserved_pretty_slug, query)
¶
This function can be used to reserve a slug using a specific string. This should probably only be called during this extension's initialisation via the vds_reserve_slugs interface function.
If a slug already exists in the database with the same reserved pretty slug and the same query parameters then nothing happens.
If a slug already exists in the database with the same reserved pretty slug but a different set of query parameters then a DuplicateSlugException is raised.
If a slug already exists in the database with the same query parameters but no reserved pretty slug then the reserved pretty slug is added to the slug.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reserved_pretty_slug
|
str
|
the slug string to reserve |
required |
Returns:
| Type | Description |
|---|---|
DatastoreSlug
|
a DatastoreSlug object that has either been found (if it already existed), created (if no slug existed) or updated (if a slug existed for the query parameters, but no reserved query string was associated with it). |
Source code in ckanext/versioned_datastore/lib/query/slugs/slugs.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
resolve_slug(slug, allow_nav=True)
¶
Resolves the given slug and returns it if it's found, otherwise None is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
the slug |
required | |
allow_nav
|
allow resolving to a navigational slug |
True
|
Returns:
| Type | Description |
|---|---|
Optional[DatastoreSlug]
|
a DatastoreSlug object or None if the slug couldn't be found |
Source code in ckanext/versioned_datastore/lib/query/slugs/slugs.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |