annotate data/plugin/macro/FormField.py @ 654:8c828d7b6cd4 tip

PDFList: check for pyPdf.utils.PdfReadError
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 07 Dec 2016 14:27:25 +0100
parents 819c4121f9a0
children
rev   line source
628
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
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: 618
diff changeset
2 """
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
3 MoinMoin - FormField Macro
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
4
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
5 Base stuff for field macros. All form fields should
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
6 be derived from FormField class.
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
7
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
8 @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: 618
diff changeset
9 @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: 618
diff changeset
10 """
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
11
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
12 from MoinMoin import wikiutil
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
13
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
14 from FormBase import FormBase, FormValidationError
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
15
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
16
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
17 class FormField(FormBase):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
18
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
19 def __init__(self, macro, args):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
20 FormBase.__init__(self, macro, args)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
21
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
22 self.label = ""
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
23 self.width = ""
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
24 self.height = ""
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
25
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
26 #if not hasattr(self.request, "fieldindex"):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
27 # self.request.fieldindex = 0
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
28 #else:
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
29 # self.request.fieldindex += 1
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
30 #self.index = str(self.request.fieldindex)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
31
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
32 def parse_args(self):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
33 FormBase.parse_args(self)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
34 self.label = self._main[0]
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
35
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
36 def validate(self):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
37 FormBase.validate(self)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
38 if not self.label:
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
39 self.msg = self._("Field label is not defined")
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
40 raise FormValidationError(self.msg)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
41
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
42 def build(self):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
43 if not hasattr(self.request, "labels"):
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
44 self.request.labels = []
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
45 self.request.labels.append(self.label)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
46 else:
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
47 if self.request.labels.count(self.label) == 0:
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
48 self.request.labels.append(self.label)
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
49
819c4121f9a0 FormCreate/FormSubmit: change to LF-only line endings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
50 #self.output += self._build_input("hidden", self.label+"_index", {'value':self.index})