-
Notifications
You must be signed in to change notification settings - Fork 7
adminInfo in List modules
This section of the adminInfo describes only adminInfo options relating to the list handler. The list handler is the richest of all handlers in relation to customizability. A full-grown adminInfo for a list module can look like this:
columns = ["creator", "order_no", "organization", "creationdate", "finishdate", "positions",
"stat_duration", "stat_totaltime", "stat_timediff", "stat_task_total", "stat_task_complete"]
adminInfo = {
"name": "Order",
"handler": "list.order",
"icon": "/static/images/order.svg",
"columns": columns,
"filter": {"orderby": "finishdate", "orderdir": "1"},
"preview": "/{{module}}/view/{{key}}",
"actions": ["exportcsv"],
"sortIndex": 4,
"views": [{
"name": u"Open",
"icon": "icons/modules/recently-edited.svg",
"columns": columns,
"filter": {"state": "open", "orderby": "finishdate"}
},
{
"name": u"Finished",
"icon": "icons/modules/billing.svg",
"columns": columns,
"filter": {"state": "finished", "orderby": "finishdate"}
},
{
"name": u"Archived",
"icon": "icons/modules/archived.svg",
"columns": columns,
"filter": {"state": "archived", "orderby": "finishdate", "orderdir": "1"}
}]
}
By default, this option is True. It can be configured to False to avoid auto-loading the list. This is necessary when loading data is performed or initiated by another task, e.g. a plugin that filters data.
By default, a list module shows all available, visible bones in the order as they are defined in the underlying skeleton. This behavior can be entirely changed to a pre-defined selection and order using the columns flag, which contains a list of bone names.
"columns": ["creationdate", "age", "name"]
Like shown on top, a variable can also be used to specify the list of columns.
Is like columns but can be used in views to append columns to the columns defined in the previous view.
todo
Is like context but can be used in views to merge another filter with the context defined in the previous view.
Using filter, a more specific filtering passed to the list-function of the handled list module can be specified. It requires for a dict providing parameters which are later passed to the mergeExternalFilter() function of the server's query API to build the desired filtering query.
"filter": {"status": "active", "orderby": "creationdate", "orderdir": 1} #order active persons descending by creationdate
Please note, that changing the filter may require the creation and rebuilding of a new index. The best way to do it is first run the app with the filter locally, then later on deploy the index file as described in the server's wiki.
Is like filter but can be used in views to merge another filter with the filter defined in the previous view.
Same as mode="hidden".
Allows to view the list module in different modes. Allowed values are
- "normal" just show the module,
- "hidden" to hide the entire module in the main menu (same as
"hideInMainBar": True
) - "group" use the main entry of the module only as grouper for subsequent views. This is only useful when views are used.
Is like name but can be used in views to append a name to the name defined in the previous view.
Configures the preview (eye) button. This button is used in list modules to open or view an database entry in another context, e.g. as rendered HTML page in the front-end or in other ways.
It requires either for a string with an URL, where placeholders can be used in the form {{placeholder}}. Any value from the underlying dataset can be used, and {{module}} will be replaced by the module's name.
"preview": "/{{module}}/view/{{key}}" # this is a simple preview
To provide multiple previews, a dict can be specified, where every entry is presented by a key-value pair (key is the name in the dropdown-list that is shown in case of more than one entries, the value represents the URL to be called, with the same placeholer notation as described above.
# A preview configuration providing three options.
"preview": {
"Edit with App": "/{{module}}/app/{{key}}",
"Web-Preview": "/{{module}}/view/{{key}}",
"PDF-File": "/{{module}}/showPDF/{{key}}"
}
Same as preview.
Allows to specify different views onto the table, e.g. sorted or filtered by different aspects. views
is specified as a list of dicts, and allows for further views inside. All elements from the main adminInfo level are allowed and can be overridden in the particular view. The attributes icon
, columns
, filter
and context
are inherited from the previous level, if not explicitly overridden.
adminInfo = {
"name": u"Pages",
"handler": "list.pages",
"icon": "icons/modules/pages.svg",
"views": [
{
"name": "by date",
"icon": "icons/modules/calendar.svg",
"filter": {"orderby": "creationdate", "orderdir": 1}
},
{
"name": "inactive pages",
"icon": "icons/modules/pages.svg",
"filter": {"active": "0"}
}]
}
This is a special addition to the above "views" option. If "views.request" is specified with an adminInfo or even another, subsequent view info, the vi calls the specified function on the module to request the views. This feature can be used when there are many generated views or when views are built using queried data from the database.
Let's have an example. We have a module "order" that should also provide views for those customer with the highest purchasing power. This module can be defined this way:
class Orders(List):
# This is the usual adminInfo
adminInfo = {
"name": u"Orders",
"handler": "list.order",
"icon": "/static/images/order.svg",
"filter": {"orderby": "orderdate"},
"views.request": "getPowerCustomerViews" #Here we define, which function to call
#within the module to request further
#views
}
@exposed
def getPowerCustomerViews(self, *args, **kwargs):
# This function is then called on demand when the views are needed.
q = conf["viur.mainApp"].customer.viewSkel().all()
q = conf["viur.mainApp"].customer.listFilter(q)
if not q:
return None
q.order(("totalorders", db.DESCENDING))
views = []
for customer in q.fetch(limit=12):
view = {
"name": customer["name"],
"icon": customer["logo"]["dest"]["servingurl"] if customer["logo"] else "/static/images/order.svg",
"filter": {"customer.dest.key": str(customer["key"]), "orderby": "orderdate"},
}
views.append(view)
return json.dumps(views)