Пример #1
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('isoFormatDate', formal.Date(), formal.TextInput)
     form.addField('datePartsSelect', formal.Date(), formal.widgetFactory(formal.DatePartsSelect, dayFirst=True))
     form.addField('monthFirstDate', formal.Date(), formal.DatePartsInput)
     form.addField('dayFirstDate', formal.Date(), formal.widgetFactory(formal.DatePartsInput, dayFirst=True))
     form.addField('monthYearDate', formal.Date(), formal.MMYYDatePartsInput)
     form.addField('twoCharYearDate', formal.Date(), formal.widgetFactory(formal.DatePartsInput, twoCharCutoffYear=70))
     form.addField('time', formal.Time())
     form.addAction(self.submitted)
     return form
Пример #2
0
    def form_example(self, ctx):
        form = formal.Form()
        form.addField('required', formal.String(required=True))
        form.addField('file', formal.File(), formal.FileUploadWidget)
        form.addField(
            'removeableFile', formal.File(),
            formal.widgetFactory(formal.FileUploadWidget, removeable=True))

        form.addAction(self.submitted)
        return form
Пример #3
0
    def form_example(self, ctx):
        form = formal.Form()
        form.addField(
            'myTextArea', formal.String(),
            formal.widgetFactory(TextAreaWithSelect,
                                 values=(('aval', 'alabel'), ('bval',
                                                              'blabel'))))

        form.addAction(self.submitted)
        return form
Пример #4
0
class ToFormalConverter(typesystems.FromSQLConverter):
    """is a converter from SQL types to Formal type specifications.

	The result of the conversion is a tuple of formal type and widget factory.
	"""
    typeSystem = "Formal"
    simpleMap = {
        "smallint": (formal.Integer, formal.TextInput),
        "integer": (formal.Integer, formal.TextInput),
        "int": (formal.Integer, formal.TextInput),
        "bigint": (formal.Integer, formal.TextInput),
        "real": (formal.Float, formal.TextInput),
        "float": (formal.Float, formal.TextInput),
        "boolean": (formal.Boolean, formal.Checkbox),
        "double precision": (formal.Float, formal.TextInput),
        "double": (formal.Float, formal.TextInput),
        "text": (formal.String, formal.TextInput),
        "unicode": (formal.String, formal.TextInput),
        "char": (formal.String, formal.TextInput),
        "date": (formal.Date,
                 formal.widgetFactory(formal.DatePartsInput,
                                      twoCharCutoffYear=50,
                                      dayFirst=True)),
        "time": (formal.Time, formal.TextInput),
        "timestamp": (formal.Date,
                      formal.widgetFactory(formal.DatePartsInput,
                                           twoCharCutoffYear=50,
                                           dayFirst=True)),
        "vexpr-float": (formal.String, customwidgets.NumericExpressionField),
        "vexpr-date": (formal.String, customwidgets.DateExpressionField),
        "vexpr-string": (formal.String, customwidgets.StringExpressionField),
        "vexpr-mjd": (formal.String, customwidgets.DateExpressionField),
        "pql-string": (formal.String, formal.TextInput),
        "pql-int": (formal.String, formal.TextInput),
        "pql-float": (formal.String, formal.TextInput),
        "pql-date": (formal.String, formal.TextInput),
        "file": (formal.File, None),
        "raw": (formal.String, formal.TextInput),
    }

    def mapComplex(self, type, length):
        if type in self._charTypes:
            return formal.String, formal.TextInput
Пример #5
0
    def _addMetaFields(self, form, queryMeta):
        """adds fields to choose output properties to form.
		"""
        try:
            if self.service.core.wantsTableWidget():
                form.addField("_DBOPTIONS",
                              svcs.FormalDict,
                              formal.widgetFactory(svcs.DBOptions,
                                                   self.service, queryMeta),
                              label="Table")
        except AttributeError:  # probably no wantsTableWidget method on core
            pass
Пример #6
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('restString',
                   formal.String(required=True),
                   widgetFactory=formal.ReSTTextArea)
     if docutilsAvailable:
         w = Writer()
         w.translator_class = CustomisedHTMLTranslator
         form.addField(
             'customRestString', formal.String(required=True),
             formal.widgetFactory(formal.ReSTTextArea, restWriter=w))
     form.addAction(self.submitted)
     return form
Пример #7
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('RichTextString',
                   formal.RichTextType(required=True),
                   widgetFactory=formal.widgetFactory(
                       formal.RichTextArea,
                       parsers=[('plain', 'Plain Text'),
                                ('reverseplain', 'Reversed Plain Text')]))
     form.addField('RichTextStringNotRequired',
                   formal.RichTextType(),
                   widgetFactory=formal.widgetFactory(
                       formal.RichTextArea,
                       parsers=[('plain', 'Plain Text'),
                                ('reverseplain', 'Reversed Plain Text'),
                                ('html', 'XHTML')]))
     form.addField('RichTextStringOnlyOneParser',
                   formal.RichTextType(required=True),
                   widgetFactory=formal.widgetFactory(formal.RichTextArea,
                                                      parsers=[('markdown',
                                                                'MarkDown')
                                                               ]))
     form.addAction(self.submitted)
     return form
Пример #8
0
def EnumeratedWidget(ik):
	"""is a widget factory for input keys over enumerated columns.

	This probably contains a bit too much magic, but let's see.  The current
	rules are:

	If values.multiOk is true, render a MultiSelectChoice, else
	render a SelectChoice or a RadioChoice depending on how many
	items there are.
	
	If ik is not required, add an ANY key evaluating to None.  For
	MultiSelectChoices we don't need this since for them, you can
	simply leave it all unselected.

	If there is a default, it becomes the NoneOption.
	"""
	if not ik.isEnumerated():
		raise base.StructureError("%s is not enumerated"%ik.name)
	noneOption, options = _getDisplayOptions(ik)
	moreArgs = {"noneOption": noneOption}
	if ik.values.multiOk or ik.multiplicity=="multiple":
		if ik.showItems==-1 or len(options)<4:
			baseWidget = CheckboxMultiChoice
			del moreArgs["noneOption"]
		else:
			baseWidget = MultiSelectChoice
			moreArgs["size"] = ik.showItems
			moreArgs["noneOption"] = None
	else:
		if len(options)<4:
			baseWidget = RadioChoice
		else:
			baseWidget = SelectChoice
	res = formal.widgetFactory(baseWidget, options=options,
		**moreArgs)
	return res
Пример #9
0
    def form_genForm(self, ctx=None, data=None):
        # this is an accumulator for defaultForForm items processed; this
        # is used below to pre-fill forms without influencing service
        # behaviour in the absence of parameters.
        self._defaultsForForm = {}

        queryMeta = svcs.QueryMeta.fromContext(ctx)
        form = formal.Form()
        self._addQueryFields(form)
        self._addMetaFields(form, queryMeta)
        self._addDefaults(ctx, form, self._defaultsForForm)

        if (self.name == "form"
                and not hasattr(self.service.core, "HACK_RETURNS_DOC")):
            form.addField("_OUTPUT",
                          formal.String,
                          formal.widgetFactory(serviceresults.OutputFormat,
                                               self.service, queryMeta),
                          label="Output format")

        form.addAction(self.submitAction, label="Go")
        form.actionMaterial = self._getFormLinks()
        self.form = form
        return form
Пример #10
0
    def form_example(self, ctx):
        form = formal.Form()
        form.addField('required', formal.String(required=True))
        form.addField(
            'oneString', formal.String(),
            formal.widgetFactory(formal.SelectChoice, options=strings))
        form.addField(
            'anotherString', formal.String(),
            formal.widgetFactory(formal.SelectChoice, options=data_strings))
        form.addField(
            'oneMoreString', formal.String(required=True),
            formal.widgetFactory(formal.RadioChoice, options=data_strings))
        form.addField('oneDate', formal.Date(),
                      formal.widgetFactory(formal.SelectChoice, options=dates))
        form.addField(
            'multipleStrings', formal.Sequence(formal.String()),
            formal.widgetFactory(formal.CheckboxMultiChoice,
                                 options=data_strings))
        form.addField(
            'multipleDates', formal.Sequence(formal.Date()),
            formal.widgetFactory(formal.CheckboxMultiChoice, options=dates))

        form.addField(
            'multipleTuples', formal.Sequence(formal.Sequence()),
            formal.widgetFactory(formal.CheckboxMultiChoice, options=tuples))

        form.addField(
            'differentNoneSelect', formal.String(),
            formal.widgetFactory(formal.SelectChoice,
                                 options=strings,
                                 noneOption=differentNone))
        form.addField(
            'differentNoneRadios', formal.String(),
            formal.widgetFactory(formal.RadioChoice,
                                 options=data_strings,
                                 noneOption=differentNone))
        form.addField(
            'selectOther', formal.String(),
            formal.widgetFactory(formal.SelectOtherChoice,
                                 options=['Mr', 'Mrs']))
        form.addField(
            'selectOtherCustomOther', formal.String(),
            formal.widgetFactory(formal.SelectOtherChoice,
                                 options=['Mr', 'Mrs'],
                                 otherOption=('...', 'Other (Please Enter)')))
        form.addField(
            'selectOtherRequired', formal.String(required=True),
            formal.widgetFactory(formal.SelectOtherChoice,
                                 options=['Mr', 'Mrs']))
        form.addField(
            'multiselect', formal.String(),
            formal.widgetFactory(formal.MultiselectChoice, options=strings))
        form.addAction(self.submitted)
        return form