Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple select sublists and rendering hyperlinks #10

Open
wants to merge 15 commits into
base: sigma2-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ docs/_build/

test.ini
settings.json

# IDE
.ipynb
47 changes: 47 additions & 0 deletions ckanext/datasetapproval/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from ckan.plugins import toolkit as tk
from ckanext.datasetapproval import mailer
from ckanext.scheming.logic import scheming_dataset_schema_show
from ckan import model

log = logging.getLogger()

Expand Down Expand Up @@ -53,23 +55,68 @@ def publishing_check(context, data_dict):
data_dict["state"] = old_data_dict.get("state")
return data_dict

def get_dataset_schema():
context = {
'model': model,
'session': model.Session,
'user': None,
'ignore_auth': True
}

data_dict = {
'type': 'dataset',
'expanded': True
}

try:
schema_data = scheming_dataset_schema_show(context, data_dict)
return schema_data
except Exception as e:
print(f"Error retrieving dataset schema: {e}")
return None

def clean_dictionary(data_dict):
schema = get_dataset_schema()
keys = []

for field_info in schema.get('dataset_fields', []):
if "repeating_subfields" in field_info.keys():
keys.append(field_info['field_name'])

cleaned_dict = dict(data_dict)

for key in keys:
if key in cleaned_dict:
remove_key = True
for entry in cleaned_dict[key]:
for value in entry.values():
if value != "":
remove_key = False
break
if remove_key:
del cleaned_dict[key]

return cleaned_dict

@tk.chained_action
def package_create(up_func, context, data_dict):
data_dict = clean_dictionary(data_dict)
publishing_check(context, data_dict)
result = up_func(context, data_dict)
return result


@tk.chained_action
def package_update(up_func, context, data_dict):
data_dict = clean_dictionary(data_dict)
publishing_check(context, data_dict)
result = up_func(context, data_dict)
return result


@tk.chained_action
def package_patch(up_func, context, data_dict):
data_dict = clean_dictionary(data_dict)
publishing_check(context, data_dict)
result = up_func(context, data_dict)
return result
Expand Down
Loading
Loading