Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csentry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ICS Control System Infrastructure
csentry
Commits
b5df54e5
Commit
b5df54e5
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Fix items table display
parent
a5c97386
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/main/views.py
+12
-11
12 additions, 11 deletions
app/main/views.py
app/templates/index.html
+2
-0
2 additions, 0 deletions
app/templates/index.html
app/utils.py
+10
-0
10 additions, 0 deletions
app/utils.py
with
24 additions
and
11 deletions
app/main/views.py
+
12
−
11
View file @
b5df54e5
...
@@ -9,10 +9,10 @@ This module implements the main blueprint.
...
@@ -9,10 +9,10 @@ This module implements the main blueprint.
:license: BSD 2-Clause, see LICENSE for more details.
:license: BSD 2-Clause, see LICENSE for more details.
"""
"""
from
flask
import
(
Blueprint
,
render_template
,
jsonify
)
from
flask
import
Blueprint
,
render_template
,
jsonify
from
flask_login
import
login_required
from
flask_login
import
login_required
from
..extensions
import
db
from
..extensions
import
db
from
..models
import
Action
,
Vendor
,
Model
,
Location
,
Status
from
..models
import
Action
,
Vendor
,
Model
,
Location
,
Status
,
Item
from
..
import
utils
from
..
import
utils
bp
=
Blueprint
(
'
main
'
,
__name__
)
bp
=
Blueprint
(
'
main
'
,
__name__
)
...
@@ -39,15 +39,16 @@ def handle_inventory_error(error):
...
@@ -39,15 +39,16 @@ def handle_inventory_error(error):
@bp.route
(
'
/_retrieve_items
'
)
@bp.route
(
'
/_retrieve_items
'
)
@login_required
@login_required
def
retrieve_items
():
def
retrieve_items
():
sql
=
"""
SELECT item.id, item.name, vendor.name, model.name, location.name, status.name
items
=
Item
.
query
.
order_by
(
Item
.
_created
)
FROM item
data
=
[[
item
.
id
,
INNER JOIN vendor ON vendor.id = item.vendor_id
item
.
serial_number
,
INNER JOIN model ON model.id = item.model_id
item
.
name
,
INNER JOIN location ON location.id = item.location_id
utils
.
format_field
(
item
.
vendor
),
INNER JOIN status ON status.id = item.status_id
utils
.
format_field
(
item
.
model
),
"""
utils
.
format_field
(
item
.
location
),
result
=
db
.
engine
.
execute
(
sql
)
utils
.
format_field
(
item
.
status
),
data
=
[[
item
for
item
in
row
]
for
row
in
result
]
utils
.
format_field
(
item
.
_updated
),
]
for
item
in
items
]
return
jsonify
(
data
=
data
)
return
jsonify
(
data
=
data
)
...
...
This diff is collapsed.
Click to expand it.
app/templates/index.html
+
2
−
0
View file @
b5df54e5
...
@@ -9,11 +9,13 @@
...
@@ -9,11 +9,13 @@
<thead>
<thead>
<tr>
<tr>
<th>
Id
</th>
<th>
Id
</th>
<th>
Serial number
</th>
<th>
name
</th>
<th>
name
</th>
<th>
Vendor
</th>
<th>
Vendor
</th>
<th>
Model
</th>
<th>
Model
</th>
<th>
Location
</th>
<th>
Location
</th>
<th>
Status
</th>
<th>
Status
</th>
<th>
Last updated
</th>
</tr>
</tr>
</thead>
</thead>
</table>
</table>
...
...
This diff is collapsed.
Click to expand it.
app/utils.py
+
10
−
0
View file @
b5df54e5
...
@@ -10,6 +10,7 @@ This module implements utility functions.
...
@@ -10,6 +10,7 @@ This module implements utility functions.
"""
"""
import
base64
import
base64
import
datetime
import
io
import
io
import
hashlib
import
hashlib
import
uuid
import
uuid
...
@@ -55,3 +56,12 @@ def image_to_base64(img, format='PNG'):
...
@@ -55,3 +56,12 @@ def image_to_base64(img, format='PNG'):
buf
=
io
.
BytesIO
()
buf
=
io
.
BytesIO
()
img
.
save
(
buf
,
format
=
format
)
img
.
save
(
buf
,
format
=
format
)
return
base64
.
b64encode
(
buf
.
getvalue
()).
decode
(
'
ascii
'
)
return
base64
.
b64encode
(
buf
.
getvalue
()).
decode
(
'
ascii
'
)
def
format_field
(
field
):
"""
Format the given field to a string or None
"""
if
field
is
None
:
return
None
if
isinstance
(
field
,
datetime
.
datetime
):
return
field
.
strftime
(
'
%Y-%m-%d %H:%M
'
)
return
str
(
field
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment