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

SXDEDPCXZIC-387 / Fix activity logic #410

Open
wants to merge 1 commit into
base: master
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
18 changes: 18 additions & 0 deletions ckanext/datavic_iar_theme/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ckan.plugins.toolkit as tk
import ckan.lib.helpers as h

import ckanext.activity.model.activity as model_activity
from ckanext.toolbelt.decorators import Collector

import ckanext.datavic_iar_theme.config as conf
Expand Down Expand Up @@ -417,3 +418,20 @@ def get_package_title(package_id: str) -> str:
except (tk.ObjectNotFound, tk.NotAuthorized):
tk.abort(403)
return pkg.get("title", "")


@helper
def check_last_activity(activity):
# Taken originally fron action.py for acitivies
prev_activity = (
model.Session.query(model_activity.Activity.id)
.filter_by(object_id=activity["object_id"])
.filter(model_activity.Activity.timestamp < activity["timestamp"])
.order_by(
# type_ignore_reason: incomplete SQLAlchemy types
model_activity.Activity.timestamp.desc() # type: ignore
)
.first()
)

return prev_activity if prev_activity else None
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% set dataset_type = activity.data.package.type or 'dataset' %}
{% set previous_acitivity = h.vic_iar_check_last_activity(activity) %}

<li class="item {{ activity.activity_type|replace(' ', '-')|lower }}">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x icon"></i>
<i class="fa fa-sitemap fa-stack-1x fa-inverse"></i>
</span>
{{ _('{actor} updated the {dataset_type} {dataset}').format(
actor=ah.actor(activity),
dataset_type=h.humanize_entity_type('package', dataset_type, 'activity_record') or _('dataset'),
dataset=ah.dataset(activity)
)|safe }}
<br />
<span class="date" title="{{ h.render_datetime(activity.timestamp, with_hours=True) }}">
{{ h.time_ago_from_timestamp(activity.timestamp) }}
{% if can_show_activity_detail %}
&nbsp;|&nbsp;
<a href="{{ h.url_for('activity.package_history', id=activity.object_id, activity_id=activity.id) }}">
{{ _('View this version') }}
</a>
{% if previous_acitivity %}
&nbsp;|&nbsp;
<a href="{{ h.url_for('activity.package_changes', id=activity.id) }}">
{{ _('Changes') }}
</a>
{% endif %}
{% endif %}
</span>
</li>
73 changes: 73 additions & 0 deletions ckanext/datavic_iar_theme/templates/snippets/changes/license.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<li>
<p>
{% set pkg_link = (h.url_for('dataset.read', id=change.pkg_id)) %}
{% if change.old_title %}
{% set old_title = change.old_title %}
{% else %}
{% set old_title = 'Unknown' %}
{% endif %}
{# if both of them have URLs #}
{% if change.new_url != "" and change.old_url != "" %}

{{ _('Changed the license of ') }}
<a href="{{pkg_link}}">
{{ change.title }}
<a>

{{ _('to') }}

<a href="{{change.new_url}}">
{{change.new_title}}
</a>

{{ _('( previously') }}
<a href="{{change.old_url}}">
{{old_title}}
</a>
{{_(')')}}

{# if only the new one has a URL #}
{% elif change.new_url != "" and change.old_url == "" %}
{{ _('Changed the license of') }}
<a href="{{pkg_link}}">
{{change.title}}
</a>

{{ _('to') }}

<a href="{{change.new_url}}">
{{change.new_title}}
</a>

{{ _('(previously') + ' ' + old_title + ' )'}}

{# if only the old one has a URL #}
{% elif change.new_url == "" and change.old_url != "" %}
{{ _('Changed the license of') }}
<a href="{{pkg_link}}">
{{change.title}}
</a>

{{ _('to') + ' ' + change.new_title }}

{{ _('( previously') }}
<a href="{{change.old_url}}">
{{old_title}}
</a>
{{_(')')}}

{# otherwise neither has a URL #}
{% else %}

{{ _('Changed the license of') }}
<a href="{{pkg_link}}">
{{change.title}}
</a>

{{ _('to') + ' ' + change.new_title}}

{{ _('(previously') + ' ' + old_title + _(')')|safe }}

{% endif %}
</p>
</li>