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

WRC130 Various small changes #34

Merged
merged 20 commits into from
Nov 27, 2024
Merged
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.ropeproject
node_modules
bower_components
.DS_Store
\#*
.#*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
28 changes: 18 additions & 10 deletions ckanext/who_romania/assets/css/who-romania.css
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
/* promoted background */
.promoted-background {
width: 100%;
background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("/images/large_promoted_background.png");
background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
url("/images/small_promoted_background.png");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
color: #FFFFFF;
}

@media only screen and (max-width: 467px) {
@media only screen and (min-width: 467px) {
.promoted-background {
background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.0)), url("/images/small_promoted_background.png");
background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.0)),
url("/images/medium_promoted_background.png");
}
}

@media only screen and (min-width: 468px) and (max-width: 991px) {
@media only screen and min-width: 991px {
.promoted-background {
background-size: cover;
background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.0)), url("/images/medium_promoted_background.png");
background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.0)),
url("/images/large_promoted_background.png");
}
}

.promoted-background .show-categories {
margin-top: 24px;
a {
color: var(--secondary);
}
}

.promoted-background .show-categories a {
color: var(--secondary);
}
/* promoted background */

Expand Down Expand Up @@ -265,4 +268,9 @@
/* tag badges */
.dataset-resources li {
background: var(--primary65);
}
}

.btn-danger {
background-color: #C70039;
border-color: config.$tag-light;
}
74 changes: 41 additions & 33 deletions ckanext/who_romania/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ckan.logic as logic
import ckan.model as model
from ckan.common import request, g
import ckan.plugins.toolkit as toolkit
from datetime import datetime, timedelta


Expand All @@ -13,16 +14,17 @@ def get_user_obj(field=""):

def get_dataset_from_id(id, validate=False):
context = {
'model': model, 'ignore_auth': True,
'validate': validate, 'use_cache': False
"model": model,
"ignore_auth": True,
"validate": validate,
"use_cache": False,
}
package_show_action = logic.get_action('package_show')
return package_show_action(context, {'id': id})
package_show_action = logic.get_action("package_show")
return package_show_action(context, {"id": id})


def get_facet_items_dict(
facet, search_facets=None, limit=None, exclude_active=False):
'''
def get_facet_items_dict(facet, search_facets=None, limit=None, exclude_active=False):
"""
Overwrite of core CKAN helper in order to get custom sorting order
on some of the facets.

Expand All @@ -32,23 +34,25 @@ def get_facet_items_dict(
limit -- the max. number of facet items to return.
exclude_active -- only return unselected facets.

'''
if not search_facets \
or not isinstance(search_facets, dict) \
or not search_facets.get(facet, {}).get('items'):
"""
if (
not search_facets
or not isinstance(search_facets, dict)
or not search_facets.get(facet, {}).get("items")
):
return []
facets = []
for facet_item in search_facets[facet]['items']:
if not len(facet_item['name'].strip()):
for facet_item in search_facets[facet]["items"]:
if not len(facet_item["name"].strip()):
continue
params_items = request.args.items(multi=True)
if not (facet, facet_item['name']) in params_items:
if not (facet, facet_item["name"]) in params_items:
facets.append(dict(active=False, **facet_item))
elif not exclude_active:
facets.append(dict(active=True, **facet_item))
# Replace CKAN default sort method
facets = _facet_sort_function(facet, facets)
if hasattr(g, 'search_facets_limits'):
if hasattr(g, "search_facets_limits"):
if g.search_facets_limits and limit is None:
limit = g.search_facets_limits.get(facet)
# zero treated as infinite for hysterical raisins
Expand All @@ -59,44 +63,47 @@ def get_facet_items_dict(

def _facet_sort_function(facet_name, facet_items):

if facet_name == 'year':
if facet_name == "year":
# Custom sort of year facet
facet_items.sort(key=lambda it: it['display_name'].lower(), reverse=True)
facet_items.sort(key=lambda it: it["display_name"].lower(), reverse=True)
else:
# Default CKAN sort
# Descendingly by count and ascendingly by case-sensitive display name
facet_items.sort(key=lambda it: (-it['count'], it['display_name'].lower()))
facet_items.sort(key=lambda it: (-it["count"], it["display_name"].lower()))

return facet_items


def get_all_groups():
return logic.get_action('group_list')(
data_dict={'sort': 'title asc', 'all_fields': True})
return logic.get_action("group_list")(
data_dict={"sort": "title asc", "all_fields": True}
)


def get_featured_datasets():
featured_datasets = logic.get_action('package_search')(
data_dict={'fq': 'tags:featured', 'sort': 'metadata_modified desc', 'rows': 3})['results']
recently_updated = logic.get_action('package_search')(
data_dict={'q': '*:*', 'sort': 'metadata_modified desc', 'rows': 3})['results']
featured_datasets = logic.get_action("package_search")(
data_dict={"fq": "tags:featured", "sort": "metadata_modified desc", "rows": 3}
)["results"]
recently_updated = logic.get_action("package_search")(
data_dict={"q": "*:*", "sort": "metadata_modified desc", "rows": 3}
)["results"]
datasets = featured_datasets + recently_updated
return datasets[:3]


def get_user_from_id(userid):
user_show_action = logic.get_action('user_show')
user_show_action = logic.get_action("user_show")
user_info = user_show_action({}, {"id": userid})
return user_info['fullname']
return user_info["fullname"]


def comma_swap_formatter(input):
"""
Swaps the parts of a string around a single comma.
Use to format e.g. "Tanzania, Republic of" as "Republic of Tanzania"
"""
if input.count(',') == 1:
parts = input.split(',')
if input.count(",") == 1:
parts = input.split(",")
stripped_parts = list(map(lambda x: x.strip(), parts))
reversed_parts = reversed(stripped_parts)
joined_parts = " ".join(reversed_parts)
Expand All @@ -115,7 +122,7 @@ def month_formatter(month):

def get_dates_of_weekday_in_month(month, weekday=4, format="%d %b %Y"):
month_start = datetime.strptime(month, "%Y-%m")
date = month_start + timedelta((weekday-month_start.weekday())%7)
date = month_start + timedelta((weekday - month_start.weekday()) % 7)
week = timedelta(weeks=1)
dates = []
while date.month == month_start.month:
Expand All @@ -129,8 +136,9 @@ def get_week_options(month):
dates = get_dates_of_weekday_in_month(month, format="%Y-%m-%d")
options = []
for i, date in enumerate(textual_dates):
options.append({
"text": f"Week {i+1} (ending {date})",
"value": dates[i]
})
options.append({"text": f"Week {i+1} (ending {date})", "value": dates[i]})
return options


def get_login_view():
return toolkit.config.get("ckan.auth.login_view", "user.login")
1 change: 1 addition & 0 deletions ckanext/who_romania/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def get_helpers(self):
"month_formatter": who_romania_helpers.month_formatter,
"get_dates_of_weekday_in_month": who_romania_helpers.get_dates_of_weekday_in_month,
"get_week_options": who_romania_helpers.get_week_options,
"get_login_view": who_romania_helpers.get_login_view,
}

# IConfigurer
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 55 additions & 16 deletions ckanext/who_romania/schemas/dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@ dataset_fields:
- field_name: notes
label: Description
form_snippet: markdown.html
form_placeholder: eg. Some useful notes about the data
form_placeholder: eg. Some useful notes about the data or the document

- field_name: program_area
label: Program Area
preset: select
choices:
- value: Sexual and Reproductive Health
label: Sexual and Reproductive Health
- value: HIV & TB
label: HIV & TB
- value: Mental Health and Psychosocial Support
label: Mental Health and Psychosocial Support
- value: E-Health
label: E-Health
- value: Family Medicine
label: Family Medicine
- value: Gender Based Violence
label: Gender Based Violence
- value: General
label: General
- value: Admin
label: Admin
- value: Emergencies Program
label: Emergencies Program
- value: National Recovery and Resilience Plan (NRRP)
label: National Recovery and Resilience Plan (NRRP)
- value: Biennial Collaborative Agreement (BCA)
label: Biennial Collaborative Agreement (BCA)
- value: DTRA One Health
label: DTRA One Health
- value: DTRA Laboratory
label: DTRA Laboratory
- value: DTRA Emergency Coordination
label: DTRA Emergency Coordination

- field_name: tag_string
label: Tags
Expand Down Expand Up @@ -67,6 +71,7 @@ dataset_fields:
label: English
- value: ro
label: Română
default: en

- field_name: owner_org
label: Organization
Expand All @@ -81,22 +86,56 @@ dataset_fields:
- value: false
label: Public
- value: true
label: Private
label: Internal
default: true
validators: boolean_validator
output_validators: boolean_validator

- field_name: approval
label: Approved
help_text: Is this an approved dataset
help_inline: true
preset: select
choices:
- value: false
label: Unapproved
- value: true
label: Approved
default: false
validators: boolean_validator
output_validators: boolean_validator

- field_name: approved_by
label: Approved by

resource_fields:

- field_name: name
label: Name
form_placeholder: eg. Malawi HTC Scale Up Plan
form_placeholder: Name of the document

- field_name: description
label: Description
form_snippet: markdown.html
form_placeholder: Some useful notes about the data
form_placeholder: Some useful notes about the document/data

- field_name: format
label: Format
preset: resource_format_autocomplete

- field_name: approval
label: Approved
help_text: Is this an approved file
help_inline: true
preset: select
choices:
- value: false
label: Unapproved
- value: true
label: Approved
default: false
validators: boolean_validator
output_validators: boolean_validator

- field_name: approved_by
label: Approved by
12 changes: 12 additions & 0 deletions ckanext/who_romania/templates/group/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "group/base_form_page.html" %}

{% block breadcrumb_content %}
<li>{% link_for h.humanize_entity_type('group', group_type, 'breadcrumb') or _('Categories'), named_route=group_type+'.index' %}</li>
{% block breadcrumb_content_inner %}
<li>{% link_for group.display_name|truncate(35), named_route=group_type+'.read', id=group.name, title=group.display_name %}</li>
<li class="active">{% link_for _('Manage'), named_route=group_type+'.edit', id=group.name %}</li>
{% endblock %}
{% endblock %}

{% block page_heading_class %}hide-heading{% endblock %}
{% block page_heading %}{{ h.humanize_entity_type('group', group_type, 'edit label') or _('Edit Category') }}{% endblock %}
25 changes: 25 additions & 0 deletions ckanext/who_romania/templates/group/new.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "group/base_form_page.html" %}

{% set label = h.humanize_entity_type('group', group_type, 'create title') or _('Create a Category') %}


{% block subtitle %}{{ label }}{% endblock %}

{% block page_heading %}{{ label }}{% endblock %}

{% block breadcrumb_content %}
<li>{{ h.nav_link(
h.humanize_entity_type('group', group_type, 'breadcrumb') or _('Categories'),
named_route=group_type+'.index') }}</li>
<li class="active">
{{ h.nav_link(
label,
named_route=group_type~'.new') }}
</li>
{% endblock %}

{% block page_header %}{% endblock %}

{% block secondary_content %}
{% snippet "group/snippets/helper.html", group_type=group_type %}
{% endblock %}
Loading