Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
netvs-middleware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
scc-net
netvs
netvs-middleware
Commits
b28ac80b
Commit
b28ac80b
authored
1 month ago
by
Alexander Kaschta
Browse files
Options
Downloads
Patches
Plain Diff
UPD: Make template rendering global util
parent
70bb4fa4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#419754
passed
1 month ago
Stage: lint
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/patch_request.py
+1
-9
1 addition, 9 deletions
api/patch_request.py
util/util.py
+8
-0
8 additions, 0 deletions
util/util.py
with
9 additions
and
9 deletions
api/patch_request.py
+
1
−
9
View file @
b28ac80b
...
...
@@ -4,7 +4,6 @@ import pathlib
from
email.mime.application
import
MIMEApplication
from
typing
import
Optional
import
jinja2
from
fastapi
import
APIRouter
,
Depends
,
HTTPException
from
starlette
import
status
...
...
@@ -15,7 +14,7 @@ from model.settings import settings
from
model.wapi.cntl
import
APIToken
,
Mgr
from
model.wapi.nd
import
Port
,
Module
,
Room
,
Bldg
,
Site
from
util.auth
import
check_auth
from
util.util
import
send_email
,
map_array_of_dicts
from
util.util
import
send_email
,
map_array_of_dicts
,
render_jinja_template
from
util.wapi_util
import
execute_wapi_function
router
=
APIRouter
(
...
...
@@ -365,13 +364,6 @@ def validate_patch_request_actions(conn, user, actions: list[APIPatchRequestActi
return
internal_actions
def
render_jinja_template
(
path
,
template
,
**
kwargs
):
template_loader
=
jinja2
.
FileSystemLoader
(
path
)
template_env
=
jinja2
.
Environment
(
loader
=
template_loader
,
autoescape
=
True
)
templ
=
template_env
.
get_template
(
template
)
return
templ
.
render
(
**
kwargs
)
def
send_informal_petch_request
(
message
:
str
,
mgr
:
Mgr
,
receiver
=
settings
.
patch_request_email_receivers
,
reply_to
:
Optional
[
str
]
=
None
)
->
bool
:
try
:
...
...
This diff is collapsed.
Click to expand it.
util/util.py
+
8
−
0
View file @
b28ac80b
...
...
@@ -3,6 +3,7 @@ from email.mime.application import MIMEApplication
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
import
jinja2
import
psycopg.rows
from
model.settings
import
settings
...
...
@@ -12,6 +13,13 @@ def get_cursor(conn):
return
conn
.
cursor
(
row_factory
=
psycopg
.
rows
.
dict_row
)
def
render_jinja_template
(
path
,
template
,
**
kwargs
):
template_loader
=
jinja2
.
FileSystemLoader
(
path
)
template_env
=
jinja2
.
Environment
(
loader
=
template_loader
,
autoescape
=
True
)
templ
=
template_env
.
get_template
(
template
)
return
templ
.
render
(
**
kwargs
)
def
send_email
(
to
:
str
|
list
[
str
],
sender
:
str
,
cc
=
None
,
bcc
=
None
,
reply_to
=
None
,
subject
=
None
,
body
=
None
,
body_type
:
str
=
'
html
'
,
attachments
:
list
[
MIMEApplication
]
=
None
):
if
type
(
to
)
is
not
list
:
...
...
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