Helpers
accessible_gravatar(email_hash, size=100, default=None, userobj=None)
¶
Port of ckan helper gravatar Adds title text to the image so it passes accessibility checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email_hash
|
|
required | |
default
|
(optional, default: None) |
None
|
|
size
|
(optional, default: 100) |
100
|
|
userobj
|
(optional, default: None) |
None
|
Source code in ckanext/nhm/lib/helpers.py
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 | |
add_url_filter(field, value, extras=None)
¶
The CKAN built in functions remove_url_param / add_url_param cannot handle multiple filters which are concatenated with |, not separate query params This replaces add_url_param for filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
|
required | |
extras
|
|
None
|
|
value
|
|
required |
Source code in ckanext/nhm/lib/helpers.py
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 | |
api_doc_link()
¶
Link to API documentation.
Source code in ckanext/nhm/lib/helpers.py
423 424 425 426 427 428 429 430 | |
build_nav_main(*menu_items)
¶
Build a set of menu items. Overrides core CKAN method to add "nav-item" class to li elements and allow endpoint keyword args.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
menu_items
|
tuples of (endpoint_details, title) e.g. ('home.index', ('Home')) or (('search.view', {'slug': 'everything'}), ('Search')) |
()
|
Returns:
| Type | Description |
|---|---|
|
literal - |
Source code in ckanext/nhm/lib/helpers.py
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 | |
build_specimen_nav_items(package_name, resource_id, record_id, version=None)
¶
Creates the specimen nav items allowing the user to navigate to different views of the specimen record data. A list of nav items is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
the package name (or id) |
required | |
resource_id
|
the resource id |
required | |
record_id
|
the record id |
required | |
version
|
the version of the record, or None if no version is present |
None
|
Returns:
| Type | Description |
|---|---|
|
a list of nav items |
Source code in ckanext/nhm/lib/helpers.py
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 | |
camel_case_to_string(camel_case_string)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camel_case_string
|
|
required |
Source code in ckanext/nhm/lib/helpers.py
672 673 674 675 676 677 678 679 | |
collection_stats()
¶
Get collection stats, including collection codes and collection totals.
Source code in ckanext/nhm/lib/helpers.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
dataset_author_truncate(author_str)
¶
For author strings with lots of authors need to shorten for display insert et al as abbreviation tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
author_str
|
dataset author |
required |
Returns:
| Type | Description |
|---|---|
|
shortened author str, full text in abbr tag |
Source code in ckanext/nhm/lib/helpers.py
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 | |
dataset_categories()
¶
Return list of dataset category terms.
Returns:
| Type | Description |
|---|---|
|
list |
Source code in ckanext/nhm/lib/helpers.py
189 190 191 192 193 194 195 196 197 198 199 200 | |
delimit_number(num)
¶
Separate long number into thousands 1000000 => 1,000,000.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
|
required |
Source code in ckanext/nhm/lib/helpers.py
414 415 416 417 418 419 420 | |
downloadable(resource)
¶
Is a resource downloadable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
|
required |
Returns:
| Type | Description |
|---|---|
|
bool |
Source code in ckanext/nhm/lib/helpers.py
852 853 854 855 856 857 858 859 860 861 862 | |
field_is_link(value)
¶
Is a field a link (starts with http and is a valid URL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
|
required |
Returns:
| Type | Description |
|---|---|
|
boolean |
Source code in ckanext/nhm/lib/helpers.py
827 828 829 830 831 832 833 834 835 836 837 838 | |
field_name_label(field_name)
¶
Convert a field name into a label - replacing _s and upper casing first character.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
|
required |
Returns:
| Type | Description |
|---|---|
|
str label |
Source code in ckanext/nhm/lib/helpers.py
814 815 816 817 818 819 820 821 822 823 824 | |
filter_and_format_resource_items(resource)
¶
Given a resource, return the items from it that are whitelisted for display and format them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
the resource dict |
required |
Returns:
| Type | Description |
|---|---|
|
a list of made up of 2-tuples containing formatted keys and values from the resource |
Source code in ckanext/nhm/lib/helpers.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
form_select_datastore_field_options(resource, allow_empty=True)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
|
required | |
allow_empty
|
(optional, default: True) |
True
|
Source code in ckanext/nhm/lib/helpers.py
1272 1273 1274 1275 1276 1277 1278 1279 1280 | |
form_select_update_frequency_options()
¶
Get update frequencies as a form list.
Source code in ckanext/nhm/lib/helpers.py
171 172 173 174 175 | |
get_allowed_view_types(resource, package)
¶
Overwrite ckan.lib.helpers.get_allowed_view_types.
We want to edit some of the options - remove Image and change Tiled Map to Map
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
|
required | |
package
|
|
required |
Source code in ckanext/nhm/lib/helpers.py
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 | |
get_beetle_iiif_resource_id()
¶
Get the ID for the beetle IIIF resource.
Returns:
| Type | Description |
|---|---|
|
the resource id |
Source code in ckanext/nhm/lib/helpers.py
333 334 335 336 337 338 339 340 | |
get_contact_form_department_options()
¶
Contact form category.
Source code in ckanext/nhm/lib/helpers.py
841 842 843 844 845 846 847 848 849 | |
get_contributor_count()
¶
Get the total number of authors listed on packages, calculated using Solr facets.
Source code in ckanext/nhm/lib/helpers.py
67 68 69 70 71 72 73 74 75 | |
get_creator_id_facet_label(facet)
¶
Return display name for the creator_id facet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
facet
|
A dictionary representing a single value for the facet |
required |
Returns:
| Type | Description |
|---|---|
|
A string to use for display name |
Source code in ckanext/nhm/lib/helpers.py
799 800 801 802 803 804 805 806 807 808 809 810 811 | |
get_department(collection_code)
¶
Return a department name for collection code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_code
|
BOT, PAL etc., |
required |
Returns:
| Type | Description |
|---|---|
|
Full department name - Entomology |
Source code in ckanext/nhm/lib/helpers.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
get_external_sites(record)
¶
Helper called on collection record pages (i.e. records in the specimens, indexlots or artefacts resources) which is expected to return a list of Site objects. From these sites, links can be generated which are relevant to the record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
dict
|
a record dict |
required |
Returns:
| Type | Description |
|---|---|
List[Site]
|
a list of Site objects |
Source code in ckanext/nhm/lib/helpers.py
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 | |
get_facet_label_function(facet_name, multi=False)
¶
For a given facet, return the function used to fetch the facet's items labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
facet_name
|
Facet name |
required | |
multi
|
If True, the function returned should take a list of facets and a filter value to find the matching facet on the name field (optional, default: False) |
False
|
Returns:
| Type | Description |
|---|---|
|
A function or None |
Source code in ckanext/nhm/lib/helpers.py
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 | |
get_image_licence_options()
¶
Return list of image licences Currently this is the same list as dataset licences.
Source code in ckanext/nhm/lib/helpers.py
903 904 905 906 907 908 909 910 911 | |
get_indexlot_resource_id()
¶
Get the ID for the index lots dataset.
Returns:
| Type | Description |
|---|---|
|
ID for indexlot resource |
Source code in ckanext/nhm/lib/helpers.py
319 320 321 322 323 324 325 326 | |
get_latest_update_for_package(pkg_dict, date_format=None)
¶
Returns the most recent update datetime (formatted as a string) for the package and its resources. If there is no update time found then 'unknown' is returned. If there is datetime found then it is rendered using the standard ckan helper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_dict
|
the package dict |
required | |
date_format
|
date format for the return datetime |
None
|
Returns:
| Type | Description |
|---|---|
|
'unknown' or a string containing the rendered datetime |
Source code in ckanext/nhm/lib/helpers.py
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 | |
get_latest_update_for_package_resources(pkg_dict, date_format=None)
¶
Returns the most recent update datetime (formatted as a string) across all resources in this package. If there is no update time found then 'unknown' is returned. If there is datetime found then it is rendered using the standard ckan helper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_dict
|
the package dict |
required | |
date_format
|
date format for the return datetime |
None
|
Returns:
| Type | Description |
|---|---|
|
'unknown' or a string containing the rendered datetime and the resource name |
Source code in ckanext/nhm/lib/helpers.py
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 | |
get_map_styles()
¶
New map config overriding the marker point img.
Source code in ckanext/nhm/lib/helpers.py
487 488 489 490 491 492 493 494 495 496 497 | |
get_nhm_organisation_id()
¶
Get the organisation ID for the NHM.
Returns:
| Type | Description |
|---|---|
|
ID for the NHM organisation |
Source code in ckanext/nhm/lib/helpers.py
282 283 284 285 286 287 288 289 | |
get_object_url(resource_id, guid, version=None, include_version=True)
¶
Retrieves the object url for the given guid in the given resource with the given version. If the version is None then the latest version of the resource is used.
The version passed (if one is passed) is not used verbatim, a call to the versioned search extension is put in to retrieve the rounded version of the resource so that the object url we create is always correct.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_id
|
the resource id |
required | |
guid
|
the guid of the object |
required | |
version
|
the version (default: None which means use the latest version) |
None
|
|
include_version
|
whether to include the version in the object URL or not. If this is False the version parameter is ignored (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
|
the object url |
Source code in ckanext/nhm/lib/helpers.py
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 | |
get_package(package_id)
¶
Get data for the given package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_id
|
the ID of the package |
required |
Source code in ckanext/nhm/lib/helpers.py
140 141 142 143 144 145 146 | |
get_query_params()
¶
Helper function to build a dict of query params To be used in urls for persistent filters.
Returns:
| Type | Description |
|---|---|
|
dict |
Source code in ckanext/nhm/lib/helpers.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | |
get_record(resource_id, record_id)
¶
Get data for the given record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_id
|
the ID of the resource holding the record |
required | |
record_id
|
the ID of the record |
required |
Source code in ckanext/nhm/lib/helpers.py
158 159 160 161 162 163 164 165 166 167 168 | |
get_record_count()
¶
Get the current total number of records in the collections dataset.
Source code in ckanext/nhm/lib/helpers.py
83 84 85 86 87 88 89 90 91 92 93 94 95 | |
get_record_iiif_manifest_url(resource_id, record_id)
¶
Given a resource ID and a record ID, a fully qualified URL to the IIIF manifest for the record's images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_id
|
str
|
the resource ID |
required |
record_id
|
int
|
the record ID |
required |
Returns:
| Type | Description |
|---|---|
str
|
the fully qualified URL |
Source code in ckanext/nhm/lib/helpers.py
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 | |
get_record_stats()
¶
Returns a list of dictionaries containing statistics about the number of records available each week starting from 01/08/2017 and ending now.
Returns:
| Type | Description |
|---|---|
List[dict]
|
a list of dicts |
Source code in ckanext/nhm/lib/helpers.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
get_resource(resource_id)
¶
Get data for the given resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_id
|
the ID of the resource |
required |
Source code in ckanext/nhm/lib/helpers.py
149 150 151 152 153 154 155 | |
get_resource_facets(resource)
¶
Return a list of facets for a particular resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
|
required |
Source code in ckanext/nhm/lib/helpers.py
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 | |
get_resource_fields(resource, version=None, use_request_version=False)
¶
Retrieves the fields for the given resource. This is done using the datastore_search action. By default, the field names from the latest version of the resource are returned. However, this can be altered by either passing a version (must be an integer) or by having a version filter in the request and then passing use_request_version=True. The version is extracted from the version filter as defined by the versioned-datastore plugin. If we can start passing the version as a parameter in its own right rather than as part of the filters then we can change this code.
If the resource isn't a datastore resource then an empty list is returned.
Because the versioned_datastore plugin guarantees that the fields returned in its datastore_search responses will be in the order they were when they were ingested or sorted alphabetically if no ingestion ordering is available, no field sorting occurs in this function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
the resource dict |
required | |
version
|
the version to request (default: None) |
None
|
|
use_request_version
|
whether to look in the request parameters to find a version in the filters (default: False) |
False
|
Returns:
| Type | Description |
|---|---|
|
a list of field names |
Source code in ckanext/nhm/lib/helpers.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
get_resource_filter_options(resource, resource_view)
¶
Return the available filter options for the given resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
Dictionary representing a resource |
required | |
resource_view
|
|
required |
Returns:
| Type | Description |
|---|---|
|
A dictionary associating each option's name to a dict defining: - label: The label to display to users; - checked: True if the option is currently applied. |
Source code in ckanext/nhm/lib/helpers.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
get_resource_filter_pills(package, resource, resource_view=None)
¶
Get filter pills.
We don't want the field group pills - these are handled separately in get_resource_field_groups
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
|
required | |
package
|
|
required | |
resource_view
|
(optional, default: None) |
None
|
Source code in ckanext/nhm/lib/helpers.py
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 | |
get_resource_gbif_errors(resource)
¶
Return GBIF errors applicable for this resource i.e. if this the specimen resource, return the gbif errors dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
return: |
required |
Source code in ckanext/nhm/lib/helpers.py
722 723 724 725 726 727 728 729 730 731 732 733 734 | |
get_sample_voucher_guid(associated_occurrence_value)
¶
Given an associatedOccurrence value from a Sample record, returns the associated specimen GUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
associated_occurrence_value
|
str
|
the associatedOccurrence value |
required |
Returns:
| Type | Description |
|---|---|
str
|
the voucher specimen GUID |
Source code in ckanext/nhm/lib/helpers.py
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 | |
get_site_statistics()
¶
Get statistics for the site.
Source code in ckanext/nhm/lib/helpers.py
56 57 58 59 60 61 62 63 64 | |
get_specimen_jsonld(uuid, version=None)
¶
Returns the rdf representation of the given specimen uuid. The returned data is a string of json-ld data. If something goes wrong, an empty string is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
the uuid of the specimen record |
required | |
version
|
optional version for the record data |
None
|
Returns:
| Type | Description |
|---|---|
|
string of dumped json-ld data |
Source code in ckanext/nhm/lib/helpers.py
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 | |
get_specimen_resource_id()
¶
Get the ID for the specimens dataset.
Returns:
| Type | Description |
|---|---|
|
ID for the specimen resource |
Source code in ckanext/nhm/lib/helpers.py
309 310 311 312 313 314 315 316 | |
get_status_indicator()
¶
Check if we need to display a status indicator, and if so what type.
Returns:
| Type | Description |
|---|---|
|
'red', 'amber', or None (if no alerts) |
Source code in ckanext/nhm/lib/helpers.py
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 | |
group_fields_have_data(record_dict, fields)
¶
Are any of the fields in the group populated Return true if they are; false if not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record_dict
|
record data |
required | |
fields
|
fields to test |
required |
Returns:
| Type | Description |
|---|---|
|
bool |
Source code in ckanext/nhm/lib/helpers.py
889 890 891 892 893 894 895 896 897 898 899 900 | |
indexlot_count()
¶
Get the total number of index lots.
Source code in ckanext/nhm/lib/helpers.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
is_collection_resource_id(resource_id)
¶
Given a resource ID, returns True if the resource ID is one of the designated collection IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_id
|
str
|
the resource ID |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the resource ID is one of the collection resource IDs, False if not |
Source code in ckanext/nhm/lib/helpers.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
is_sysadmin()
¶
Is user a sysadmin user.
Source code in ckanext/nhm/lib/helpers.py
865 866 867 868 869 870 | |
parse_request_filters()
¶
Get the filters from the request object.
Source code in ckanext/nhm/lib/helpers.py
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 | |
persistent_follow_button(obj_type, obj_id)
¶
Replaces ckan.lib.follow_button which returns an empty string for anonymous users.
For anon users this function outputs a follow button which links through to the login page.
Source code in ckanext/nhm/lib/helpers.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
record_display_field(field_name, value)
¶
Decide whether to display a field Evaluates whether a field has value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
|
required | |
value
|
|
required |
Returns:
| Type | Description |
|---|---|
|
bool - true to display field; false not to |
Source code in ckanext/nhm/lib/helpers.py
873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |
remove_url_filter(field, value, extras=None)
¶
The CKAN built in functions remove_url_param / add_url_param cannot handle multiple filters which are concatenated with |, not separate query params This replaces remove_url_param for filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
the field to remove the filter for |
required | |
value
|
the value of the field to remove the filter for |
required | |
extras
|
extra parameters to include in the created URL |
None
|
Returns:
| Type | Description |
|---|---|
|
a URL |
Source code in ckanext/nhm/lib/helpers.py
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 | |
render_epoch(epoch_timestamp, in_milliseconds=True, date_format='%Y-%m-%d %H:%M:%S (UTC)')
¶
Renders an epoch timestamp in the given date format. The timestamp is rendered in UTC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch_timestamp
|
the timestamp, represented as the number of seconds (or milliseconds if in_milliseconds is True) since the UNIX epoch |
required | |
in_milliseconds
|
whether the timestamp is in milliseconds or seconds. By default this is True and therefore the timestamp is expected to be in milliseconds |
True
|
|
date_format
|
the output format. This will be passed straight to datetime's strftime function and therefore uses its keywords etc. Defaults to: %Y-%m-%d %H:%M:%S (UTC) |
'%Y-%m-%d %H:%M:%S (UTC)'
|
Returns:
| Type | Description |
|---|---|
|
a string rendering of the timestamp using the |
Source code in ckanext/nhm/lib/helpers.py
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 | |
resource_is_dwc(resource)
¶
Is the resource format DwC?
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
return: |
required |
Source code in ckanext/nhm/lib/helpers.py
663 664 665 666 667 668 669 | |
resource_view_get_field_groups(resource)
¶
Return dictionary of field groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
resource dict |
required |
Returns:
| Type | Description |
|---|---|
|
OrderedDict of fields |
Source code in ckanext/nhm/lib/helpers.py
517 518 519 520 521 522 523 524 525 526 | |
resource_view_get_filterable_fields(resource)
¶
Retrieves the fields that can be filtered on.
Returns:
| Type | Description |
|---|---|
|
a list of sorted fields |
Source code in ckanext/nhm/lib/helpers.py
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 | |
resource_view_state(resource_view_json, resource_json)
¶
Alter the recline view resource, adding in state info.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_view_json
|
|
required | |
resource_json
|
|
required |
Source code in ckanext/nhm/lib/helpers.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
route_exists(route)
¶
Simple helper for checking if a flask route exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route
|
endpoint name, as passed to url_for |
required |
Returns:
| Type | Description |
|---|---|
|
bool |
Source code in ckanext/nhm/lib/helpers.py
1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 | |
social_share_text(pkg_dict=None, res_dict=None, rec_dict=None)
¶
Generate social share text for a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_dict
|
|
None
|
Returns:
| Type | Description |
|---|---|
|
|
Source code in ckanext/nhm/lib/helpers.py
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | |
update_frequency_get_label(value)
¶
Get the label for this update frequency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
return: |
required |
Source code in ckanext/nhm/lib/helpers.py
178 179 180 181 182 183 184 185 186 | |
url_for_collection_view(view_type=None, filters={})
¶
Return URL to link through to specimen dataset view, with optional search params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_type
|
grid to link to - grid or map (optional, default: None) |
None
|
|
kwargs
|
search filter params |
required | |
filters
|
(optional, default: {}) |
{}
|
Returns:
| Type | Description |
|---|---|
|
url |
Source code in ckanext/nhm/lib/helpers.py
203 204 205 206 207 208 209 210 211 212 213 | |
url_for_indexlot_view()
¶
Return URL to link through to index lot resource view.
Returns:
| Type | Description |
|---|---|
|
url |
Source code in ckanext/nhm/lib/helpers.py
216 217 218 219 220 221 222 223 | |
url_for_resource_view(resource_id, view_type=None, filters={})
¶
Get URL to link to resource view. If no view type is specified, the first view will be used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_id
|
|
required | |
filters
|
(optional, default: {}) |
{}
|
|
view_type
|
(optional, default: None) |
None
|
Source code in ckanext/nhm/lib/helpers.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |