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
07cc9c1a
Verified
Commit
07cc9c1a
authored
2 months ago
by
!! Julian Keck (old Account; do not use) !!
Browse files
Options
Downloads
Patches
Plain Diff
UPD: attach patch_request raw json to email instead of printing it
parent
26629c94
No related branches found
No related tags found
No related merge requests found
Pipeline
#400044
passed
2 months ago
Stage: lint
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/patch_request.py
+6
-2
6 additions, 2 deletions
api/patch_request.py
templates/patch_request_template.j2
+0
-6
0 additions, 6 deletions
templates/patch_request_template.j2
util/util.py
+5
-2
5 additions, 2 deletions
util/util.py
with
11 additions
and
10 deletions
api/patch_request.py
+
6
−
2
View file @
07cc9c1a
import
html
import
json
import
pathlib
from
email.mime.application
import
MIMEApplication
from
typing
import
Optional
import
jinja2
...
...
@@ -356,11 +357,13 @@ def send_patch_request(actions: list[PatchRequestAction], mgr: Mgr, receiver=set
raw_data
.
append
(
json
.
loads
(
action
.
model_dump_json
()))
raw_action_json
=
json
.
dumps
(
raw_data
,
indent
=
2
)
json_attachment
=
MIMEApplication
(
raw_action_json
,
_subtype
=
'
json
'
)
json_attachment
.
add_header
(
'
Content-Disposition
'
,
'
attachment
'
,
filename
=
'
request.json
'
)
body
=
render_jinja_template
(
path
,
TEMPLATE
,
actions
=
actions
,
mgr
=
mgr
,
host_mode
=
host_mode
,
raw_action_json
=
raw_action_json
,
)
building_numbers
=
"
,
"
.
join
(
set
([
action
.
building
.
number
for
action
in
actions
]))
...
...
@@ -378,7 +381,8 @@ def send_patch_request(actions: list[PatchRequestAction], mgr: Mgr, receiver=set
sender
=
settings
.
patch_request_email_sender
,
reply_to
=
reply_to
or
mgr
.
email
,
subject
=
subject
,
body
=
body
body
=
body
,
attachments
=
[
json_attachment
],
)
return
True
except
Exception
as
e
:
...
...
This diff is collapsed.
Click to expand it.
templates/patch_request_template.j2
+
0
−
6
View file @
07cc9c1a
...
...
@@ -90,10 +90,4 @@
{% endfor %}
<p>Have a nice day!</p>
<br><br>
Raw request:
<pre>
{{ raw_action_json | default('[]') }}
</pre>
</body>
This diff is collapsed.
Click to expand it.
util/util.py
+
5
−
2
View file @
07cc9c1a
import
smtplib
from
email.mime.application
import
MIMEApplication
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
...
...
@@ -12,13 +13,13 @@ def get_cursor(conn):
def
send_email
(
to
:
str
|
list
[
str
],
sender
:
str
,
cc
=
None
,
bcc
=
None
,
reply_to
=
None
,
subject
=
None
,
body
=
None
,
body_type
:
str
=
'
html
'
):
body_type
:
str
=
'
html
'
,
attachments
:
list
[
MIMEApplication
]
=
None
):
if
type
(
to
)
is
not
list
:
to
=
to
.
split
(
'
,
'
)
to_list
=
[
x
for
x
in
to
if
x
is
not
None
]
msg
=
MIMEMultipart
(
'
alternative
'
)
msg
=
MIMEMultipart
()
msg
[
'
From
'
]
=
sender
msg
[
'
Subject
'
]
=
subject
msg
[
'
To
'
]
=
'
,
'
.
join
(
to_list
)
...
...
@@ -32,6 +33,8 @@ def send_email(to: str | list[str], sender: str, cc=None, bcc=None, reply_to=Non
# msg['Auto-Submitted'] = 'auto-generated'
msg
[
'
Reply-To
'
]
=
reply_to
msg
.
attach
(
MIMEText
(
body
,
body_type
))
for
attachment
in
attachments
or
[]:
msg
.
attach
(
attachment
)
with
smtplib
.
SMTP
(
settings
.
mail_smarthost
)
as
server
:
server
.
sendmail
(
sender
,
to_list
,
msg
.
as_string
())
...
...
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