Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
B
bmon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
energy
bmon
Commits
7a866357
Commit
7a866357
authored
Nov 08, 2019
by
Alan Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Sensor related to Alerts present.
parent
171e6cdb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
1 deletion
+54
-1
bmsapp/admin.py
bmsapp/admin.py
+54
-1
No files found.
bmsapp/admin.py
View file @
7a866357
...
...
@@ -150,12 +150,65 @@ class BuildingSensorListFilter(admin.SimpleListFilter):
sensor_ids
=
[
b_to_s
.
sensor
.
pk
for
b_to_s
in
BldgToSensor
.
objects
.
filter
(
building_id
=
bldg_pk
)]
return
queryset
.
filter
(
pk__in
=
sensor_ids
)
class
SensorAlertExistsListFilter
(
admin
.
SimpleListFilter
):
'''List Filter used to select sensors that have alerts present.
See https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter
for info on how this built.
'''
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
# NOTE: the underbar is a function imported from django.utils.translation
title
=
_
(
'Alerts Present'
)
# Parameter for the filter that will be used in the URL query.
parameter_name
=
'alerts_present'
def
lookups
(
self
,
request
,
model_admin
):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
"""
return
(
(
'active'
,
_
(
'Have Active Alerts'
)),
(
'inactive'
,
_
(
'Have Inactive Alerts'
)),
(
'none'
,
_
(
'Have No Alerts'
)),
)
def
queryset
(
self
,
request
,
queryset
):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
# get the requested alert presence.
alert_presence
=
self
.
value
()
if
alert_presence
is
None
:
# This case occurs when 'All' is selected
return
queryset
elif
alert_presence
==
'none'
:
sensor_ids
=
[
alert
.
sensor
.
pk
for
alert
in
AlertCondition
.
objects
.
all
()]
sensor_ids
=
list
(
set
(
sensor_ids
))
return
queryset
.
exclude
(
pk__in
=
sensor_ids
)
elif
alert_presence
==
'inactive'
:
sensor_ids
=
[
alert
.
sensor
.
pk
for
alert
in
AlertCondition
.
objects
.
filter
(
active
=
False
)]
sensor_ids
=
list
(
set
(
sensor_ids
))
return
queryset
.
filter
(
pk__in
=
sensor_ids
)
elif
alert_presence
==
'active'
:
sensor_ids
=
[
alert
.
sensor
.
pk
for
alert
in
AlertCondition
.
objects
.
filter
(
active
=
True
)]
sensor_ids
=
list
(
set
(
sensor_ids
))
return
queryset
.
filter
(
pk__in
=
sensor_ids
)
else
:
return
queryset
@
admin
.
register
(
Sensor
)
class
SensorAdmin
(
admin
.
ModelAdmin
):
inlines
=
(
BldgToSensorInline2
,
AlertAdminInline
)
search_fields
=
[
'sensor_id'
,
'title'
,
'tran_calc_function'
]
list_filter
=
[
'is_calculated'
,
BuildingSensorListFilter
]
list_filter
=
[
BuildingSensorListFilter
,
SensorAlertExistsListFilter
,
'is_calculated'
]
formfield_overrides
=
{
models
.
TextField
:
{
'widget'
:
Textarea
(
attrs
=
{
'rows'
:
6
,
'cols'
:
80
})},
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment