示例#1
0
文件: submit.py 项目: gitGNU/gnu_qsos
 def bind_submitYourContribution(self, ctx):
     "Bind the proper action to perform when submit action is invoked"
     return [('Author', annotate.String()), ('E-mail', annotate.String()),
             ('Description', annotate.Text()),
             ('Type', annotate.Choice(['Evaluation', 'Template',
                                       'Family'])),
             ('File', annotate.FileUpload(required=False))]
示例#2
0
 def bind_add(self, ctx):
     return annotate.MethodBinding(
         'add',
         annotate.Method(arguments=[
             annotate.Argument('context', annotate.Context()),
             annotate.Argument('smartObjectClass',
                               annotate.Choice(choices=self.plugins)),
         ],
                         label=_('Add')),
         action=_('Add'))
示例#3
0
 def insert(
     ctx = annotate.Context(),
     title = annotate.String(strip=True, required=True, \
                             requiredFailMessage="Title must be provided", tabindex='1'),
     author = annotate.String(strip=True, default="Anonymous", tabindex='2'),
     id = annotate.String(hidden=True),
     category = annotate.Choice(categories, tabindex='3'),
     content = annotate.Text(required=True, \
                             requiredFailMessage="Posts with no content are not allowed", tabindex='4'),
     ):
     pass
示例#4
0
    def __init__(self, objectClasses):
        super(AddOCForm, self).__init__(None)
        structural = []
        auxiliary = []
        for oc in objectClasses:
            if oc.type == 'STRUCTURAL':
                structural.append(oc)
            elif oc.type == 'AUXILIARY':
                auxiliary.append(oc)
        structural.sort()
        auxiliary.sort()

        class KludgeNevowChoice(object):
            """
            A kludge that allows using Choice with both Nevow 0.3 and
            newer.
            """
            def __init__(self, oc):
                self.name = oc.name
                self.desc = oc.desc

            def __str__(self):
                """
                For Choice in Nevow 0.4 and newer. Nevow 0.3 will use
                integer indexes. Actual stringification for display
                purposes happens in strObjectClass.
                """
                return self.name[0]

        formFields = [
            annotate.Argument('ctx', annotate.Context()),
            annotate.Argument('request', annotate.Request()),
            annotate.Argument(
                'structuralObjectClass',
                annotate.Choice(
                    label=_('Object type to create'),
                    choices=[KludgeNevowChoice(x) for x in structural],
                    stringify=strObjectClass)),
        ]
        for oc in auxiliary:
            formFields.append(
                annotate.Argument(
                    'auxiliary_%s' % oc.name[0],
                    annotate.Boolean(label=oc.name[0],
                                     description=oc.desc or '')))
        self.formFields = formFields
示例#5
0
文件: search.py 项目: Jbran77/ldaptor
    def bind_search(self, ctx):
        l = []
        l.append(annotate.Argument('ctx', annotate.Context()))
        for field in config.getSearchFieldNames():
            l.append(annotate.Argument('search_%s' % field,
                                       annotate.String(label=field)))
        l.append(annotate.Argument('searchfilter',
                                   annotate.String(label=_("Advanced search"))))
        l.append(annotate.Argument(
            'scope',
            annotate.Choice(label=_("Search depth"),
                            choices=[ pureldap.LDAP_SCOPE_wholeSubtree,
                                      pureldap.LDAP_SCOPE_singleLevel,
                                      pureldap.LDAP_SCOPE_baseObject,
                                      ],
                            stringify=strScope,
                            default=pureldap.LDAP_SCOPE_wholeSubtree)))

        return annotate.MethodBinding(
            name='search',
            action=_("Search"),
            typeValue=annotate.Method(arguments=l,
                                      label=_('Search')))
示例#6
0
        return annotate.MethodBinding(
            'action', annotate.Method(arguments=self.formElements))

    def action(self, **kw):
        print "ACTION!", kw

    def addElement(self, name, type):
        self.formElements.append(annotate.Argument(name, type()))


allTypes = [
    annotate.String, annotate.Text, annotate.Integer, annotate.Real,
    annotate.Password
]
typeChoice = annotate.Choice(choices=allTypes,
                             valueToKey=reflect.qual,
                             keyToValue=reflect.namedAny,
                             stringify=lambda x: x.__name__)


class IFormBuilder(annotate.TypedInterface):
    def addElement(name=annotate.String(required=True), type=typeChoice):
        """Add Element
        
        Add an element to this form.
        """
        pass

    addElement = annotate.autocallable(addElement)

    def clearForm():
        """Clear Form
示例#7
0
文件: prefs.py 项目: xregist/shtoom
class IWizardConfiguration(annotate.TypedInterface):
    currentConfiguration = annotate.Choice(getConfigurationChoices)
示例#8
0
from nevow import rend
from nevow import tags
from nevow import inevow
from nevow import url

from formless import annotate
from formless import webform

from twisted.internet import defer


#oldChoicesWay = annotate.Choice(choicesAttribute='theChoices') # Doing this gives you a DeprecationWarning now

# If you still want to use an attribute or method of some other object, you should use a function as shown below,
# but look up IResource(ctx) or IConfigurable(ctx), whichever is more appropriate.
newChoicesWay = annotate.Choice(lambda c, d: list(range(30)))
deferChoicesWay = annotate.Choice(lambda c, d: defer.succeed(['abcd', 'efgh', 'ijkl']))
radioChoices = annotate.Radio(["Old", "Tyme", "Radio"])

## An example of using custom valueToKey and keyToValue functions to serialize/deserialize items
values = {0: dict(name="Zero", stuff=1234), 1: dict(name="One", stuff=1234), 2: dict(name="Two", stuff=2345435)}
customValueToKey = annotate.Choice(
    [0, 1, 2], # Perhaps these are primary keys in a database
    stringify=lambda x: values[x]['name'], # Do a database lookup to render a nice label in the ui
    valueToKey=str,                                  # Convert the primary key to a value suitable for sending across the web
    keyToValue=lambda x: values[int(x)]) # Do a database lookup to get the actual value to pass to the binding


class IMyForm(annotate.TypedInterface):
    foo = annotate.Integer()
示例#9
0
 def bind_quest(self, ctx):
     return [('quest',
              annotate.Choice([
                  'Find the Grail', 'Get laid', 'Earn twenty bucks',
                  'Destroy the sun'
              ]))]
示例#10
0
 def sendLogMessage(ctx=annotate.Context(),
                    level=annotate.Choice(LogLevels,
                                          required=True,
                                          label=_("Log message level")),
                    message=annotate.String(label=_("Message text"))):
     pass