fix: set log type, status enums for log grids
This commit is contained in:
parent
127ea49d74
commit
f4b5f3960c
3 changed files with 53 additions and 13 deletions
37
src/wuttafarm/util.py
Normal file
37
src/wuttafarm/util.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# WuttaFarm --Web app to integrate with and extend farmOS
|
||||
# Copyright © 2026 Lance Edgar
|
||||
#
|
||||
# This file is part of WuttaFarm.
|
||||
#
|
||||
# WuttaFarm is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# WuttaFarm is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# WuttaFarm. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
misc. utilities
|
||||
"""
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
def get_log_type_enum(config, session=None):
|
||||
app = config.get_app()
|
||||
model = app.model
|
||||
log_types = OrderedDict()
|
||||
with app.short_session(session=session) as sess:
|
||||
query = sess.query(model.LogType).order_by(model.LogType.name)
|
||||
for log_type in query:
|
||||
log_types[log_type.drupal_id] = log_type.name
|
||||
return log_types
|
||||
|
|
@ -32,6 +32,7 @@ from wuttafarm.web.views import WuttaFarmMasterView
|
|||
from wuttafarm.db.model import Asset, Log
|
||||
from wuttafarm.web.forms.schema import AssetParentRefs
|
||||
from wuttafarm.web.forms.widgets import ImageWidget
|
||||
from wuttafarm.util import get_log_type_enum
|
||||
|
||||
|
||||
def get_asset_type_enum(config):
|
||||
|
|
@ -301,7 +302,12 @@ class AssetMasterView(WuttaFarmMasterView):
|
|||
def configure_row_grid(self, grid):
|
||||
g = grid
|
||||
super().configure_row_grid(g)
|
||||
enum = self.app.enum
|
||||
model = self.app.model
|
||||
session = self.Session()
|
||||
|
||||
# status
|
||||
g.set_enum("status", enum.LOG_STATUS)
|
||||
|
||||
# drupal_id
|
||||
g.set_label("drupal_id", "ID", column_only=True)
|
||||
|
|
@ -318,6 +324,7 @@ class AssetMasterView(WuttaFarmMasterView):
|
|||
# log_type
|
||||
g.set_sorter("log_type", model.Log.log_type)
|
||||
g.set_filter("log_type", model.Log.log_type)
|
||||
g.set_enum("log_type", get_log_type_enum(self.config, session=session))
|
||||
|
||||
def get_row_action_url_view(self, log, i):
|
||||
return self.request.route_url(f"logs_{log.log_type}.view", uuid=log.uuid)
|
||||
|
|
|
|||
|
|
@ -34,17 +34,7 @@ from wuttaweb.forms.widgets import WuttaDateTimeWidget
|
|||
from wuttafarm.web.views import WuttaFarmMasterView
|
||||
from wuttafarm.db.model import LogType, Log
|
||||
from wuttafarm.web.forms.schema import LogAssetRefs
|
||||
|
||||
|
||||
def get_log_type_enum(config):
|
||||
app = config.get_app()
|
||||
model = app.model
|
||||
session = Session()
|
||||
log_types = OrderedDict()
|
||||
query = session.query(model.LogType).order_by(model.LogType.name)
|
||||
for log_type in query:
|
||||
log_types[log_type.drupal_id] = log_type.name
|
||||
return log_types
|
||||
from wuttafarm.util import get_log_type_enum
|
||||
|
||||
|
||||
class LogTypeView(WuttaFarmMasterView):
|
||||
|
|
@ -142,6 +132,7 @@ class LogView(WuttaFarmMasterView):
|
|||
def configure_grid(self, grid):
|
||||
g = grid
|
||||
super().configure_grid(g)
|
||||
session = self.Session()
|
||||
|
||||
# drupal_id
|
||||
g.set_label("drupal_id", "ID", column_only=True)
|
||||
|
|
@ -154,7 +145,7 @@ class LogView(WuttaFarmMasterView):
|
|||
g.set_link("message")
|
||||
|
||||
# log_type
|
||||
g.set_enum("log_type", get_log_type_enum(self.config))
|
||||
g.set_enum("log_type", get_log_type_enum(self.config, session=session))
|
||||
|
||||
# assets
|
||||
g.set_renderer("assets", self.render_assets_for_grid)
|
||||
|
|
@ -224,8 +215,10 @@ class LogMasterView(WuttaFarmMasterView):
|
|||
g = grid
|
||||
super().configure_grid(g)
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
||||
# status
|
||||
g.set_enum("status", enum.LOG_STATUS)
|
||||
g.set_sorter("status", model.Log.status)
|
||||
g.set_filter("status", model.Log.status)
|
||||
|
||||
|
|
@ -255,6 +248,7 @@ class LogMasterView(WuttaFarmMasterView):
|
|||
f = form
|
||||
super().configure_form(f)
|
||||
enum = self.app.enum
|
||||
session = self.Session()
|
||||
log = f.model_instance
|
||||
|
||||
# timestamp
|
||||
|
|
@ -280,7 +274,9 @@ class LogMasterView(WuttaFarmMasterView):
|
|||
else:
|
||||
f.set_node(
|
||||
"log_type",
|
||||
WuttaDictEnum(self.request, get_log_type_enum(self.config)),
|
||||
WuttaDictEnum(
|
||||
self.request, get_log_type_enum(self.config, session=session)
|
||||
),
|
||||
)
|
||||
f.set_readonly("log_type")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue