Coverage for .tox / coverage / lib / python3.11 / site-packages / sideshow / web / util.py: 100%
38 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-15 17:10 -0600
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-15 17:10 -0600
1# -*- coding: utf-8; -*-
2################################################################################
3#
4# Sideshow -- Case/Special Order Tracker
5# Copyright © 2024-2025 Lance Edgar
6#
7# This file is part of Sideshow.
8#
9# Sideshow is free software: you can redistribute it and/or modify it
10# under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# Sideshow is distributed in the hope that it will be useful, but
15# WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with Sideshow. If not, see <http://www.gnu.org/licenses/>.
21#
22################################################################################
23"""
24Web Utility Functions
25"""
28def make_new_order_batches_grid(request, **kwargs):
29 """
30 Make and return the grid for the New Order Batches field.
31 """
32 config = request.wutta_config
33 app = config.get_app()
34 model = app.model
35 web = app.get_web_handler()
37 if "key" not in kwargs:
38 route_prefix = kwargs.pop("route_prefix")
39 kwargs["key"] = f"{route_prefix}.view.new_order_batches"
41 kwargs.setdefault("model_class", model.NewOrderBatch)
42 kwargs.setdefault(
43 "columns",
44 [
45 "id",
46 "total_price",
47 "created",
48 "created_by",
49 "executed",
50 ],
51 )
52 kwargs.setdefault("labels", {"id": "Batch ID"})
53 kwargs.setdefault("renderers", {"id": "batch_id", "total_price": "currency"})
54 grid = web.make_grid(request, **kwargs)
56 if request.has_perm("neworder_batches.view"):
58 def view_url(batch, i): # pylint: disable=unused-argument
59 return request.route_url("neworder_batches.view", uuid=batch.uuid)
61 grid.add_action("view", icon="eye", url=view_url)
62 grid.set_link("id")
64 return grid
67def make_orders_grid(request, **kwargs):
68 """
69 Make and return the grid for the Orders field.
70 """
71 config = request.wutta_config
72 app = config.get_app()
73 model = app.model
74 web = app.get_web_handler()
76 if "key" not in kwargs:
77 route_prefix = kwargs.pop("route_prefix")
78 kwargs["key"] = f"{route_prefix}.view.orders"
80 kwargs.setdefault("model_class", model.Order)
81 kwargs.setdefault(
82 "columns",
83 [
84 "order_id",
85 "total_price",
86 "created",
87 "created_by",
88 ],
89 )
90 kwargs.setdefault("labels", {"order_id": "Order ID"})
91 kwargs.setdefault("renderers", {"total_price": "currency"})
92 grid = web.make_grid(request, **kwargs)
94 if request.has_perm("orders.view"):
96 def view_url(order, i): # pylint: disable=unused-argument
97 return request.route_url("orders.view", uuid=order.uuid)
99 grid.add_action("view", icon="eye", url=view_url)
100 grid.set_link("order_id")
102 return grid