Skip to content

Instantly share code, notes, and snippets.

@roc

roc/actions.py Secret

Created Jan 6, 2022
Embed
What would you like to do?
trying to query by extras in ckan pages actions
def _pages_list(context, data_dict):
print('data_dict')
print(data_dict)
search = {}
org_id = data_dict.get('org_id')
ordered = data_dict.get('order')
order_publish_date = data_dict.get('order_publish_date')
page_type = data_dict.get('page_type')
private = data_dict.get('private', True)
if ordered:
search['order'] = True
if page_type:
search['page_type'] = page_type
if order_publish_date:
search['order_publish_date'] = True
if not org_id:
search['group_id'] = None
try:
p.toolkit.check_access('ckanext_pages_update', context, data_dict)
if not private:
search['private'] = False
except p.toolkit.NotAuthorized:
search['private'] = False
else:
group = context['model'].Group.get(org_id)
user = context['user']
member = authz.has_user_permission_for_group_or_org(
group.id, user, 'read')
search['group_id'] = org_id
if not member:
search['private'] = False
schema = default_pages_schema()
items = ['title', 'content', 'name', 'private',
'order', 'page_type', 'publish_date']
extras = {}
extra_keys = set(schema.keys()) - set(items + ['id', 'created'])
for key in extra_keys:
if key in data_dict:
extras[key] = data_dict.get(key)
search['extras'] = json.dumps(extras)
search['extras'] = u'{"add_to_home_page": true}'
print('search is', search)
out = db.Page.pages(**search)
out_list = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment