-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
176 additions
and
168 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
from ckanext.collection.utils.data.model import ModelData | ||
|
||
from dominate import tags | ||
|
||
import ckan.plugins.toolkit as tk | ||
|
||
from ckanext.collection.types import InputFilter, ButtonFilter, LinkFilter | ||
from ckanext.collection.utils import Filters | ||
|
||
from ckanext.ap_main.collection.base import ( | ||
ApCollection, | ||
ApColumns, | ||
BulkAction, | ||
RowAction, | ||
ApHtmxTableSerializer | ||
) | ||
|
||
from ckanext.tour.model import Tour | ||
|
||
|
||
def tour_row_dictizer(serializer: ApHtmxTableSerializer, row: Tour): | ||
data = row.dictize({}) | ||
data["bulk-action"] = data["id"] | ||
data["steps"] = len(data["steps"]) | ||
|
||
return data | ||
|
||
class TourListCollection(ApCollection[Any]): | ||
SerializerFactory = ApHtmxTableSerializer.with_attributes( | ||
row_dictizer=tour_row_dictizer | ||
) | ||
|
||
ColumnsFactory = ApColumns.with_attributes( | ||
names=[ | ||
"bulk-action", | ||
"title", | ||
"state", | ||
"anchor", | ||
"page", | ||
"created_at", | ||
"modified_at", | ||
"steps", | ||
"author_id", | ||
"row_actions", | ||
], | ||
sortable={"created_at", "modified_at"}, | ||
searchable={"title", "page"}, | ||
labels={ | ||
"bulk-action": tk.literal( | ||
tags.input_( | ||
type="checkbox", | ||
name="bulk_check", | ||
id="bulk_check", | ||
data_module="ap-bulk-check", | ||
data_module_selector='input[name="entity_id"]', | ||
) | ||
), | ||
"title": "Title", | ||
"state": "State", | ||
"anchor": "Anchor", | ||
"page": "Page", | ||
"created_at": "Created At", | ||
"modified_at": "Modified At", | ||
"steps": "Steps", | ||
"author_id": "Author", | ||
"row_actions": "Actions", | ||
}, | ||
width={}, | ||
serializers={ | ||
"created_at": [("date", {})], | ||
"modified_at": [("date", {})], | ||
"author_id": [("user_link", {})], | ||
}, | ||
) | ||
|
||
DataFactory = ModelData.with_attributes( | ||
model=Tour, | ||
is_scalar=True, | ||
use_naive_search=True, | ||
use_naive_filters=True, | ||
) | ||
|
||
FiltersFactory = Filters.with_attributes( | ||
static_actions=[ | ||
BulkAction( | ||
name="bulk-action", | ||
type="bulk_action", | ||
options={ | ||
"label": "Action", | ||
"options": [ | ||
{"value": "1", "text": "Disable selected tour(s)"}, | ||
{"value": "2", "text": "Enable selected tour(s)"}, | ||
{"value": "3", "text": "Remove selected tour(s)"}, | ||
], | ||
}, | ||
), | ||
RowAction( | ||
name="view", | ||
type="row_action", | ||
options={ | ||
"endpoint": "tour.delete", | ||
"label": "Delete", | ||
"params": { | ||
"tour_id": "$id", | ||
}, | ||
}, | ||
), | ||
RowAction( | ||
name="view", | ||
type="row_action", | ||
options={ | ||
"endpoint": "tour.edit", | ||
"label": "Edit", | ||
"params": { | ||
"tour_id": "$id", | ||
}, | ||
}, | ||
) | ||
], | ||
static_filters=[ | ||
InputFilter( | ||
name="q", | ||
type="input", | ||
options={ | ||
"label": "Search", | ||
"placeholder": "Search", | ||
}, | ||
), | ||
ButtonFilter( | ||
name="type", | ||
type="button", | ||
options={ | ||
"label": "Clear", | ||
"type": "button", | ||
"attrs": { | ||
"onclick": "$(this).closest('form').find('input,select').val('').prevObject[0].requestSubmit()" | ||
}, | ||
}, | ||
), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.