Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09ece3f

Browse files
committed
Add plugin
1 parent 9d17022 commit 09ece3f

258 files changed

Lines changed: 5665 additions & 7042 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.test_durations

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

changes/6790.misc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Activites extracted into `activity` plugin:
2+
3+
Import changes:
4+
5+
* `ckan.model.Activity` -> `ckanext.activity.model.Activity`

ckan/cli/generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def migration(plugin: str, message: str):
204204

205205

206206
_factories = {
207-
"activity": "ckan.tests.factories:Activity",
207+
"activity": "ckanext.activity.tests.conftest:ActivityFactory",
208208
"api-token": "ckan.tests.factories:APIToken",
209209
"dataset": "ckan.tests.factories:Dataset",
210210
"group": "ckan.tests.factories:Group",

ckan/cli/notify.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ckan.model import Session, Package, DomainObjectOperation
66
from ckan.model.modification import DomainObjectModificationExtension
77
from ckan.logic import NotAuthorized, ValidationError
8-
8+
from ckan.cli import error_shout
99

1010
log = getLogger(__name__)
1111

@@ -41,4 +41,6 @@ def send_emails():
4141
try:
4242
logic.get_action("send_email_notifications")(context, {})
4343
except (NotAuthorized, ValidationError, mailer.MailerException) as e:
44-
log.error(e)
44+
error_shout(e)
45+
except KeyError:
46+
error_shout("`activity` plugin is not enabled")

ckan/config/config_declaration.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,8 +1152,9 @@ groups:
11521152
This is ordinarily the home page, but specific sites may prefer somewhere else.
11531153
11541154
- key: ckan.route_after_login
1155-
default: dashboard.index
1155+
default: dashboard.datasets
11561156

1157+
# TODO: move to activity extension
11571158
- annotation: Activity Streams Settings
11581159
options:
11591160
- key: ckan.activity_streams_enabled

ckan/lib/create_test_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ def create(cls, auth_profile: str = "",
476476

477477
# Create activities for packages
478478
for item in [pkg1, pkg2]:
479-
activity = item.activity_stream_item('new', 'not logged in')
479+
from ckanext.activity.model import Activity
480+
activity = Activity.activity_stream_item(item, 'new', 'not logged in')
480481
model.Session.add(activity)
481482

482483
model.repo.commit_and_remove()

ckan/lib/dictization/model_dictize.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -626,17 +626,6 @@ def vocabulary_list_dictize(vocabulary_list: list[model.Vocabulary],
626626
return [vocabulary_dictize(vocabulary, context)
627627
for vocabulary in vocabulary_list]
628628

629-
def activity_dictize(activity: model.Activity,
630-
context: Context) -> dict[str, Any]:
631-
return d.table_dictize(activity, context)
632-
633-
634-
def activity_list_dictize(
635-
activity_list: list[model.Activity], context: Context,
636-
include_data: bool=False) -> list[dict[str, Any]]:
637-
return [activity_dictize(activity, context)
638-
for activity in activity_list]
639-
640629
def user_following_user_dictize(follower: model.UserFollowingUser,
641630
context: Context) -> dict[str, Any]:
642631
return d.table_dictize(follower, context)

ckan/lib/dictization/model_save.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -528,25 +528,6 @@ def task_status_dict_save(task_status_dict: dict[str, Any],
528528
task_status_dict, model.TaskStatus, context)
529529
return task_status
530530

531-
def activity_dict_save(activity_dict: dict[str, Any],
532-
context: Context) -> 'model.Activity':
533-
534-
model = context['model']
535-
session = context['session']
536-
user_id = activity_dict['user_id']
537-
object_id = activity_dict['object_id']
538-
activity_type = activity_dict['activity_type']
539-
if 'data' in activity_dict:
540-
data = activity_dict['data']
541-
else:
542-
data = None
543-
activity_obj = model.Activity(user_id, object_id,
544-
activity_type, data)
545-
session.add(activity_obj)
546-
547-
# TODO: Handle activity details.
548-
549-
return activity_obj
550531

551532
def vocabulary_tag_list_save(
552533
new_tag_dicts: list[dict[str, Any]],

ckan/lib/helpers.py

Lines changed: 18 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
urlencode, quote, unquote, urlparse, urlunparse
4141
)
4242

43-
import jinja2
44-
4543
import ckan.config
4644
import ckan.exceptions
4745
import ckan.model as model
@@ -82,16 +80,31 @@
8280
'about': 'home.about',
8381
'search': 'dataset.search',
8482
'dataset_read': 'dataset.read',
85-
'dataset_activity': 'dataset.activity',
83+
'dataset_activity': 'activity.package_activity',
8684
'dataset_groups': 'dataset.groups',
8785
'group_index': 'group.index',
8886
'group_about': 'group.about',
8987
'group_read': 'group.read',
90-
'group_activity': 'group.activity',
88+
'group_activity': 'activity.group_activity',
9189
'organizations_index': 'organization.index',
92-
'organization_activity': 'organization.activity',
90+
'organization_activity': 'activity.organization_activity',
9391
'organization_read': 'organization.read',
9492
'organization_about': 'organization.about',
93+
# TODO: add activity routes
94+
"user.activity": "activity.user_activity",
95+
"dashboard.index": "activity.dashboard",
96+
97+
"dataset.changes_multiple": "activity.package_changes_multiple",
98+
"dataset.changes": "activity.package_changes",
99+
"dataset.history": "activity.package_history",
100+
101+
"group.changes_multiple": "activity.group_changes_multiple",
102+
"group.changes": "activity.group_changes",
103+
"group.history": "activity.group_history",
104+
"organization.changes_multiple": "activity.organization_changes_multiple",
105+
"organization.changes": "activity.organization_changes",
106+
"organization.history": "activity.organization_history",
107+
95108
}
96109

97110

@@ -2000,57 +2013,6 @@ def user_in_org_or_group(group_id: str) -> bool:
20002013
return len(query.all()) != 0
20012014

20022015

2003-
@core_helper
2004-
def dashboard_activity_stream(user_id: str,
2005-
filter_type: Optional[str] = None,
2006-
filter_id: Optional[str] = None,
2007-
offset: int = 0) -> list[dict[str, Any]]:
2008-
'''Return the dashboard activity stream of the current user.
2009-
2010-
:param user_id: the id of the user
2011-
:type user_id: string
2012-
2013-
:param filter_type: the type of thing to filter by
2014-
:type filter_type: string
2015-
2016-
:param filter_id: the id of item to filter by
2017-
:type filter_id: string
2018-
2019-
:returns: an activity stream as an HTML snippet
2020-
:rtype: string
2021-
2022-
'''
2023-
context = cast(
2024-
Context, {'model': model, 'session': model.Session, 'user': g.user})
2025-
2026-
if filter_type:
2027-
action_functions = {
2028-
'dataset': 'package_activity_list',
2029-
'user': 'user_activity_list',
2030-
'group': 'group_activity_list',
2031-
'organization': 'organization_activity_list',
2032-
}
2033-
action_function = logic.get_action(action_functions[filter_type])
2034-
return action_function(context, {'id': filter_id, 'offset': offset})
2035-
else:
2036-
return logic.get_action('dashboard_activity_list')(
2037-
context, {'offset': offset})
2038-
2039-
2040-
@core_helper
2041-
def recently_changed_packages_activity_stream(
2042-
limit: Optional[int] = None) -> list[dict[str, Any]]:
2043-
if limit:
2044-
data_dict = {'limit': limit}
2045-
else:
2046-
data_dict = {}
2047-
context = cast(
2048-
Context, {'model': model, 'session': model.Session, 'user': g.user}
2049-
)
2050-
return logic.get_action('recently_changed_packages_activity_list')(
2051-
context, data_dict)
2052-
2053-
20542016
@core_helper
20552017
def escape_js(str_to_escape: str) -> str:
20562018
'''Escapes special characters from a JS string.
@@ -2415,20 +2377,6 @@ def SI_number_span(number: int) -> Markup: # noqa
24152377
localised_filesize = formatters.localised_filesize
24162378

24172379

2418-
@core_helper
2419-
def new_activities() -> Optional[int]:
2420-
'''Return the number of activities for the current user.
2421-
2422-
See :func:`logic.action.get.dashboard_new_activities_count` for more
2423-
details.
2424-
2425-
'''
2426-
if not g.userobj:
2427-
return None
2428-
action = logic.get_action('dashboard_new_activities_count')
2429-
return action({}, {})
2430-
2431-
24322380
@core_helper
24332381
def uploads_enabled() -> bool:
24342382
if uploader.get_storage_path():
@@ -2693,95 +2641,6 @@ def sanitize_id(id_: str) -> str:
26932641
return str(uuid.UUID(id_))
26942642

26952643

2696-
@core_helper
2697-
def compare_pkg_dicts(old: dict[str, Any], new: dict[str, Any],
2698-
old_activity_id: str) -> list[dict[str, Any]]:
2699-
'''
2700-
Takes two package dictionaries that represent consecutive versions of
2701-
the same dataset and returns a list of detailed & formatted summaries of
2702-
the changes between the two versions. old and new are the two package
2703-
dictionaries. The function assumes that both dictionaries will have
2704-
all of the default package dictionary keys, and also checks for fields
2705-
added by extensions and extra fields added by the user in the web
2706-
interface.
2707-
2708-
Returns a list of dictionaries, each of which corresponds to a change
2709-
to the dataset made in this revision. The dictionaries each contain a
2710-
string indicating the type of change made as well as other data necessary
2711-
to form a detailed summary of the change.
2712-
'''
2713-
from ckan.lib.changes import check_metadata_changes, check_resource_changes
2714-
change_list: list[dict[str, Any]] = []
2715-
2716-
check_metadata_changes(change_list, old, new)
2717-
2718-
check_resource_changes(change_list, old, new, old_activity_id)
2719-
2720-
# if the dataset was updated but none of the fields we check were changed,
2721-
# display a message stating that
2722-
if len(change_list) == 0:
2723-
change_list.append({u'type': 'no_change'})
2724-
2725-
return change_list
2726-
2727-
2728-
@core_helper
2729-
def compare_group_dicts(
2730-
old: dict[str, Any], new: dict[str, Any], old_activity_id: str):
2731-
'''
2732-
Takes two package dictionaries that represent consecutive versions of
2733-
the same organization and returns a list of detailed & formatted summaries
2734-
of the changes between the two versions. old and new are the two package
2735-
dictionaries. The function assumes that both dictionaries will have
2736-
all of the default package dictionary keys, and also checks for fields
2737-
added by extensions and extra fields added by the user in the web
2738-
interface.
2739-
2740-
Returns a list of dictionaries, each of which corresponds to a change
2741-
to the dataset made in this revision. The dictionaries each contain a
2742-
string indicating the type of change made as well as other data necessary
2743-
to form a detailed summary of the change.
2744-
'''
2745-
from ckan.lib.changes import check_metadata_org_changes
2746-
change_list: list[dict[str, Any]] = []
2747-
2748-
check_metadata_org_changes(change_list, old, new)
2749-
2750-
# if the organization was updated but none of the fields we check
2751-
# were changed, display a message stating that
2752-
if len(change_list) == 0:
2753-
change_list.append({u'type': 'no_change'})
2754-
2755-
return change_list
2756-
2757-
2758-
@core_helper
2759-
def activity_list_select(pkg_activity_list: list[dict[str, Any]],
2760-
current_activity_id: str) -> list[Markup]:
2761-
'''
2762-
Builds an HTML formatted list of options for the select lists
2763-
on the "Changes" summary page.
2764-
'''
2765-
select_list = []
2766-
template = jinja2.Template(
2767-
u'<option value="{{activity_id}}" {{selected}}>'
2768-
'{{timestamp}}</option>',
2769-
autoescape=True)
2770-
for activity in pkg_activity_list:
2771-
entry = render_datetime(activity['timestamp'],
2772-
with_hours=True,
2773-
with_seconds=True)
2774-
select_list.append(Markup(
2775-
template
2776-
.render(activity_id=activity['id'], timestamp=entry,
2777-
selected='selected'
2778-
if activity['id'] == current_activity_id
2779-
else '')
2780-
))
2781-
2782-
return select_list
2783-
2784-
27852644
@core_helper
27862645
def get_collaborators(package_id: str) -> list[tuple[str, str]]:
27872646
'''Return the collaborators list for a dataset

ckan/lib/signals.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def _request_started_listener(*args: Any, **kwargs: Any):
6868
6969
"""
7070

71+
72+
action_succeeded = ckan.signal(u"action_succeed")
73+
"""This signal is sent when an action finished without an exception.
74+
"""
75+
76+
7177
datastore_upsert = ckanext.signal(u"datastore_upsert")
7278
"""This signal is sent after datasetore records inserted/updated via
7379
`datastore_upsert`.

0 commit comments

Comments
 (0)