annotate data/plugin/action/submitemail.py @ 624:bdebdc59b057

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