Skip to content

Commit

Permalink
LIKA-631: Remove frontpage news
Browse files Browse the repository at this point in the history
  • Loading branch information
Zharktas committed Nov 13, 2024
1 parent 1e5da34 commit 378b009
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 123 deletions.
5 changes: 0 additions & 5 deletions ansible/roles/ckan/templates/ckan.ini.j2
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ ckanext.apicatelog.harvester_instruction_url = {{ ckan_harvester_instruction_url

ckanext.apicatalog.test_environment = {{ ckan_test_environment | default(False) }}

ckanext.apicatalog.news.endpoint_url = {{ content.news.endpoint_url }}
ckanext.apicatalog.news.ssl_verify = {{ content.news.ssl_verify | default(True) }}
ckanext.apicatalog.news.tags = palveluvaeylae
ckanext.apicatalog.news.url_template = {{ content.news.url_template }}

ckanext.apicatalog.harvester_status_zulip_stream = {{ harvester_status.zulip_stream }}
ckanext.apicatalog.harvester_status_zulip_topic = {{ harvester_status.zulip_topic }}
ckanext.apicatalog.zulip.api_url = {{ zulip.api_url }}
Expand Down
6 changes: 1 addition & 5 deletions ansible/vars/environment-specific/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ elk:
- "kapalogprod02.csc.fi:5044"
- "kapalogprod03.csc.fi:5044"

content:
news:
endpoint_url: "https://palveluhallinta.suomi.fi/api/articles/importantTopical?newsTypes"
url_template: "https://palveluhallinta.suomi.fi/{language}/ajankohtaista/uutiset/{id}"
ssl_verify: true


debug_enabled: false

Expand Down
5 changes: 0 additions & 5 deletions ansible/vars/environment-specific/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ elk:
- "kapalogtest02.csc.fi:5044"
- "kapalogtest03.csc.fi:5044"

content:
news:
endpoint_url: "https://palveluhallinta.suomi.fi/api/articles/importantTopical?newsTypes"
url_template: "https://palveluhallinta.suomi.fi/{language}/ajankohtaista/uutiset/{id}"
ssl_verify: true

debug_enabled: false

Expand Down
5 changes: 0 additions & 5 deletions ansible/vars/environment-specific/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ elk:
- "kapalogtest02.csc.fi:5044"
- "kapalogtest03.csc.fi:5044"

content:
news:
endpoint_url: "https://palveluhallinta.suomi.fi/api/articles/importantTopical?newsTypes"
url_template: "https://palveluhallinta.suomi.fi/{language}/ajankohtaista/uutiset/{id}"
ssl_verify: true

debug_enabled: false

Expand Down
5 changes: 0 additions & 5 deletions ansible/vars/environment-specific/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ elk:
logstash:
hosts: ["localhost"]

content:
news:
endpoint_url: "https://palveluhallinta.suomi.fi/api/articles/importantTopical?newsTypes"
url_template: "https://palveluhallinta.suomi.fi/{language}/ajankohtaista/uutiset/{id}"
ssl_verify: true

debug_enabled: true

Expand Down
58 changes: 0 additions & 58 deletions ckanext/ckanext-apicatalog/ckanext/apicatalog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,63 +213,6 @@ def criteria(dataset):
return list(itertools.islice(filter(criteria, datasets), count))


NEWS_CACHE = None


def get_homepage_news(count=3, cache_duration=timedelta(days=1), language=None):
global NEWS_CACHE
log.debug('Fetching homepage news')
if NEWS_CACHE is None or datetime.now() - NEWS_CACHE[0] > cache_duration:
log.debug('Updating news cache')
news_endpoint_url = config.get('ckanext.apicatalog.news.endpoint_url')
news_ssl_verify = toolkit.asbool(config.get('ckanext.apicatalog.news.ssl_verify', True))
news_tags = config.get('ckanext.apicatalog.news.tags')
news_url_template = config.get('ckanext.apicatalog.news.url_template')

if not news_endpoint_url:
log.warning('ckanext.apicatalog.news.endpoint_url not set')
news = []
else:
log.debug('Fetching from %s', news_endpoint_url)
try:
news_items = requests.get(news_endpoint_url, verify=news_ssl_verify).json()
log.debug('Received %i news items', len(news_items))

tags = set(t.strip() for t in news_tags.split(',')) if news_tags else None
if tags:
log.debug('Filtering with tags: %s', repr(tags))
news_items = [n for n in news_items if any(t.get('slug') in tags for t in n.get('tags', []))]

news = [{'title': {tl: t for tl, t in list(item.get('title', {}).items()) if t != 'undefined'},
'content': {tl: t for tl, t in list(item.get('content', {}).items()) if t != 'undefined'},
'published': parse_datetime(item.get('publishedAt')),
'brief': item.get('brief', {}),
'image': '',
'image_alt': '',
'url': {lang: news_url_template.format(**{'id': item.get('id'), 'language': lang})
for lang in list(item.get('title').keys())}}
for item in news_items]
news.sort(key=lambda x: x['published'], reverse=True)

log.debug('Updating news cache with %i news', len(news))
news_cache_timestamp = datetime.now()
NEWS_CACHE = (news_cache_timestamp, news)

except Exception as e:
# Fetch failed for some reason, keep old value until cache invalidates
log.error(e)
news = [] if NEWS_CACHE is None else NEWS_CACHE[1]

else:
log.debug('Returning cached news')
news_cache_timestamp, news = NEWS_CACHE

if language:
news = [n for n in news if language in n.get('title', {}) and language in n.get('content', {})]

return news[:count]


ANNOUNCEMENT_CACHE = None


Expand Down Expand Up @@ -771,7 +714,6 @@ def update_config_schema(self, schema):
def get_helpers(self):
return {'get_homepage_organizations': get_homepage_organizations,
'get_homepage_datasets': get_homepage_datasets,
'get_homepage_news': get_homepage_news,
'get_homepage_announcements': get_homepage_announcements,
'service_alerts': service_alerts,
'info_message': info_message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,6 @@
{% endblock %}
</div>
</div>
<div class="row homepage-section">
<div class="col-sm-12">
{% block news %}
{% set news_lang = h.lang() %}
{% set note = None %}
{% if news_lang in ('en', 'en_GB') %}
{% set note = _('This content is not available in English. If you have any questions about this topic, please contact our customer service at <a href="mailto:[email protected]">[email protected]</a>.') %}
{% set news_lang = 'fi' %}
{% endif %}
{% snippet 'home/snippets/news.html', news=h.get_homepage_news(count=3, language=news_lang), language=news_lang, note=note %}
{% endblock %}
</div>
</div>
</div>
</div>
</div>
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions ckanext/ckanext-apicatalog/less/homepage.less
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
}
}

.news, .announcements {
.announcements {
background-color: white;
border: 1px solid @suomifi-border;
padding: 14px 44px;
Expand All @@ -303,7 +303,7 @@
}
}

.news-list, .announcements-list {
.announcements-list {
list-style: none;
margin: 0;
padding: 0;
Expand Down

0 comments on commit 378b009

Please sign in to comment.