annotate data/plugin/action/submitemail.py @ 628:819c4121f9a0

FormCreate/FormSubmit: change to LF-only line endings
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 25 Mar 2013 19:48:31 +0100
parents f64779d5d500
children
rev   line source
628
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
1 # -*- coding: iso-8859-1 -*-
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
2 """
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
3 MoinMoin - submitemail Action
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
4
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
5 Send submited data email address specified in targetemail CGI parameter
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
6
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
7 @copyright: 2008 by Peter Bodi <petrdll@centrum.sk>
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
8 @license: GNU GPL, see COPYING for details.
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
9 """
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
10
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
11 from MoinMoin import wikiutil
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
12 from MoinMoin.action import ActionBase
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
13 from MoinMoin.Page import Page
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
14 from MoinMoin.mail.sendmail import sendmail
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
15
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
16 from submitbase import SubmitBase
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
17
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
18
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
19 def execute(pagename, request):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
20 submitemail(pagename, request).render()
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
21
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
22
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
23 class submitemail(SubmitBase):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
24
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
25 def __init__(self, pagename, request):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
26 SubmitBase.__init__(self, pagename, request)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
27
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
28 self.subject = "MoinMoin mail"
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
29 self.targetemail = request.form.get("targetemail", "")
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
30
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
31 def build_content(self):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
32 """ Builds simple 'label: value' string """
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
33 text = ""
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
34 for label in self.labels:
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
35 index = self.labels.index(label)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
36 label = label.decode('utf-8')
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
37 value = self.values[index]
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
38 text += "%(label)s: %(value)s \n" % {'label': label, 'value': value}
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
39 return text
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
40
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
41 def submit(self):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
42 SubmitBase.submit(self)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
43 text = self.build_content()
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
44 status, msg = sendmail(self.request, self.targetemail, self.subject, text, mail_from=self.targetemail)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
45 self.msg = self._(msg)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
46 if status != 1:
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 626
diff changeset
47 raise Exception(self.msg)