mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-07-08 13:43:18 +00:00
integrate nopaque repo
This commit is contained in:
.env.tpl.gitignore.gitlab-ci.ymlREADME.md
daemon
Dockerfiledecorators.pydocker-entrypoint.sh
docker-compose.ymlnopaque.env.tpllogger
nopaqued.bak.pynopaqued.pynotify
requirements.txttasks
web
Dockerfile
app
__init__.py
config.pydocker-entrypoint.shadmin
auth
corpora
decorators.pyemail.pyevents.pyjobs
main
models.pyprofile
services
static
css
fonts
Material_design_icons
images
logo_-_dfg.giflogo_-_sfb_1288.pngnopaque_logo.png
parallax_hq
book_text_read_paper.jpgbooks_antique_book_old.jpgconcept_document_focus_letter.jpgtext_data_wide.png
parallax_lq
01_books_antique_book_old.jpg02_concept_document_focus_letter.jpg03_text_data_wide.png04_german_text_book_paper.jpg05_chapter_book_text_tale.jpgbible_text.jpgtext_data.png
qr_-_inf.svgserver_activity.pngsfb_background.jpegjs
templates
migrations
READMEalembic.inienv.pyscript.py.mako
nopaque.pyrequirements.txtversions
099037c4aa06_.py0aa38a7973c5_.py10a92d8f4616_.py1210adfe1e34_.py3d9a20b8b26c_.py421ba4373e50_.py4638e6509e13_.py471aa04c1a92_.py4886241e0f5d_.py49a42c69e523_.py5ba6786a847e_.py62233e0cb2c7_.py6227310c2112_.py66253783654f_.py68772b6560c3_.py7378391345fa_.py776761fb7466_.pyabf60427ff84_.pyda9fd175af8c_.pyded5a37f8a7b_.py
tests
0
daemon/notify/__init__.py
Normal file
0
daemon/notify/__init__.py
Normal file
27
daemon/notify/notification.py
Normal file
27
daemon/notify/notification.py
Normal file
@ -0,0 +1,27 @@
|
||||
from email.message import EmailMessage
|
||||
|
||||
|
||||
class Notification(EmailMessage):
|
||||
"""docstring for Email."""
|
||||
|
||||
def set_notification_content(self,
|
||||
subject_template,
|
||||
subject_template_values_dict,
|
||||
body_txt_template_path,
|
||||
body_html_template_path,
|
||||
body_template_values_dict):
|
||||
# Create subject with subject_template_values_dict
|
||||
self['subject'] = subject_template.format(**subject_template_values_dict)
|
||||
# Open template files and insert values from body_template_values_dict
|
||||
with open(body_txt_template_path) as nfile:
|
||||
self.body_txt = nfile.read().format(**body_template_values_dict)
|
||||
with open(body_html_template_path) as nfile:
|
||||
self.body_html = nfile.read().format(**body_template_values_dict)
|
||||
# Set txt of email
|
||||
self.set_content(self.body_txt)
|
||||
# Set html alternative
|
||||
self.add_alternative(self.body_html, subtype='html')
|
||||
|
||||
def set_addresses(self, sender, recipient):
|
||||
self['From'] = sender
|
||||
self['to'] = recipient
|
41
daemon/notify/service.py
Normal file
41
daemon/notify/service.py
Normal file
@ -0,0 +1,41 @@
|
||||
import os
|
||||
import smtplib
|
||||
|
||||
|
||||
class NotificationService(object):
|
||||
"""This is a nopaque notifcation service object."""
|
||||
|
||||
def __init__(self, execute_flag):
|
||||
super(NotificationService, self).__init__()
|
||||
self.execute_flag = execute_flag # If True mails are sent normaly
|
||||
# If False mails are not sent. Used to avoid sending mails for jobs that
|
||||
# have been completed a long time ago. Use this if you implement notify
|
||||
# into an already existing nopaque instance. Change it to True after the
|
||||
# daemon has run one time with the flag set to False
|
||||
self.not_sent = {} # Holds due to an error unsent email notifications
|
||||
self.mail_limit_exceeded = False # Bool to show if the mail server
|
||||
# stoped sending mails due to exceeding its sending limit
|
||||
|
||||
def get_smtp_configs(self):
|
||||
self.password = os.environ.get('MAIL_PASSWORD')
|
||||
self.port = os.environ.get('MAIL_PORT')
|
||||
self.server_str = os.environ.get('MAIL_SERVER')
|
||||
self.tls = os.environ.get('MAIL_USE_TLS')
|
||||
self.username = os.environ.get('MAIL_USERNAME').split("@")[0]
|
||||
self.email_address = os.environ.get('MAIL_USERNAME')
|
||||
|
||||
def set_server(self):
|
||||
self.smtp_server = smtplib.SMTP(host=self.server_str, port=self.port)
|
||||
|
||||
def login(self):
|
||||
self.smtp_server.starttls()
|
||||
self.smtp_server.login(self.username, self.password)
|
||||
|
||||
def send(self, email):
|
||||
if self.execute_flag:
|
||||
self.smtp_server.send_message(email)
|
||||
else:
|
||||
return
|
||||
|
||||
def quit(self):
|
||||
self.smtp_server.quit()
|
@ -0,0 +1,15 @@
|
||||
<html>
|
||||
<body>
|
||||
<p>Dear <b>{username}</b>,</p>
|
||||
|
||||
<p>The status of your Job/Corpus({id}) with the title <b>"{title}"</b> has changed!</p>
|
||||
<p>It is now <b>{status}</b>!</p>
|
||||
<p>Time of this status update was: <b>{time} UTC</b></p>
|
||||
|
||||
<p>You can access your Job/Corpus here: <a href="{url}">{url}</a>
|
||||
</p>
|
||||
|
||||
<p>Kind regards!<br>
|
||||
Your nopaque team</p>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,10 @@
|
||||
Dear {username},
|
||||
|
||||
The status of your Job/Corpus({id}) with the title "{title}" has changed!
|
||||
It is now {status}!
|
||||
Time of this status update was: {time} UTC
|
||||
|
||||
You can access your Job/Corpus here: {url}
|
||||
|
||||
Kind regards!
|
||||
Your nopaque team
|
Reference in New Issue
Block a user