Coverage for /home/runner/work/viur-core/viur-core/viur/src/viur/core/modules/formmailer.py: 0%
43 statements
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-16 22:16 +0000
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-16 22:16 +0000
1from viur.core.skeleton import RelSkel
2from viur.core import errors, utils, securitykey, email
3from viur.core.decorators import *
4from viur.core.bones import BaseBone
5from viur.core.module import Module
8class MailSkel(RelSkel):
9 changedate = None # Changedates won't apply here
12class Formmailer(Module):
13 mailTemplate = None
15 @exposed
16 @skey(allow_empty=True)
17 def index(self, *args, **kwargs):
18 if not self.canUse():
19 raise errors.Forbidden() # Unauthorized
21 skel = self.mailSkel()
23 if len(kwargs) == 0:
24 return self.render.add(skel=skel, failed=False)
26 if not skel.fromClient(kwargs):
27 return self.render.add(skel=skel, failed=True)
29 # Allow bones to perform outstanding "magic" operations before sending the mail
30 for key, _bone in skel.items():
31 if isinstance(_bone, BaseBone):
32 _bone.performMagic(skel, key, isAdd=True)
34 # Get recipients
35 rcpts = self.getRcpts(skel)
37 # Get additional options for sendEMail
38 opts = self.getOptions(skel)
39 if not isinstance(opts, dict):
40 opts = {}
42 # Send the email!
43 email.sendEMail(dests=rcpts, tpl=self.mailTemplate, skel=skel, **opts)
44 self.onAdded(skel)
46 return self.render.addSuccess(skel)
48 @exposed
49 def add(self, *args, **kwargs):
50 return self.index(*args, **kwargs)
52 def canUse(self) -> bool:
53 return False
55 def mailSkel(self):
56 raise NotImplementedError("You must implement the \"mailSkel\" function!")
58 def getRcpts(self, skel):
59 raise NotImplementedError("You must implement the \"getRcpts\" function!")
61 def getOptions(self, skel):
62 return None
64 def onAdded(self, skel):
65 pass
68Formmailer.html = True