Ejemplo n.º 1
0
 def bind_test5(self, ctx):
     return annotate.MethodBinding(
         'test5',
         annotate.Method(arguments=[
             annotate.Argument('foo', annotate.String()),
             annotate.Argument('bar', annotate.Integer())
         ]))
Ejemplo n.º 2
0
 def _getFormFields(self):
     r = []
     r.append(annotate.Argument('request', annotate.Request()))
     for dn, e in self.ldapObjects.items():
         r.append(
             annotate.Argument('dn_%s' % dn,
                               annotate.Boolean(label=dn, description=e)))
     return r
Ejemplo n.º 3
0
 def bind_animals(self, ctx, ):
     """Add Animal"""
     return annotate.MethodBinding(
             'animals',
             annotate.Method(arguments=
                 [annotate.Argument('animal', annotate.String()),
                  annotate.Argument('description', annotate.Text())]),
             action="Add Animal",
                                   )
Ejemplo n.º 4
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'))
Ejemplo n.º 5
0
 def bind_go(self, ctx):
     return annotate.MethodBinding(
         'go',
         annotate.Method(arguments=[
             annotate.Argument('ctx', annotate.Context()),
             annotate.Argument(
                 'baseDN',
                 LDAPDN(label=_('Base DN'),
                        description=_(
                            "The top-level LDAP DN you want"
                            " to browse, e.g. dc=example,dc=com"))),
         ],
                         label=_('Go')),
         action=_('Go'))
Ejemplo n.º 6
0
 def bind_setServicePassword(self, ctx):
     return annotate.MethodBinding(
         'setServicePassword',
         annotate.Method(arguments=[
             annotate.Argument('ctx', annotate.Context()),
             annotate.Argument(
                 'newPassword',
                 annotate.PasswordEntry(required=True,
                                        label=_('New password'))),
             annotate.Argument(
                 'again',
                 annotate.PasswordEntry(required=True, label=_('Again'))),
         ],
                         label=_('Set password')),
         action=_('Set password'))
Ejemplo n.º 7
0
    def _one_formfield(self, attr, result, must=False):
        attrtype = self._get_attrtype(attr)
        name = attr
        if must:
            name = name + "*"
        if attrtype.uiHint_multiline:
            if attrtype.single_value:
                typed = annotate.Text(label=name,
                                      description=attrtype.desc or '',
                                      required=must)
            else:
                typed = annotate.Text(label=name,
                                      description=attrtype.desc or '',
                                      required=must)
        else:
            if attrtype.single_value:
                typed = annotate.String(label=name,
                                        description=attrtype.desc or '',
                                        required=must)
            else:
                # TODO maybe use a string field+button to add entries,
                # multiselection list+button to remove entries?
                typed = annotate.Text(label=name,
                                      description=attrtype.desc or '',
                                      required=must)

        result.append(annotate.Argument('add_' + attr, typed))
Ejemplo n.º 8
0
        class FormPage(rend.Page):
            bind_test1 = defer.succeed([('foo', annotate.String()),
                                        ('bar', annotate.Integer())])
            bind_test2 = defer.succeed(
                annotate.MethodBinding(
                    'test2',
                    annotate.Method(arguments=[
                        annotate.Argument('foo', annotate.String())
                    ])))

            bind_test3 = defer.succeed(
                annotate.Property('test3', annotate.Integer()))

            def bind_test4(self, ctx):
                return defer.succeed([('foo', annotate.String()),
                                      ('bar', annotate.Integer())])

            def bind_test5(self, ctx):
                return defer.succeed(
                    annotate.MethodBinding(
                        'test5',
                        annotate.Method(arguments=[
                            annotate.Argument('foo', annotate.String()),
                            annotate.Argument('bar', annotate.Integer())
                        ])))

            docFactory = loaders.stan(html[freeform.renderForms()])
Ejemplo n.º 9
0
 def _convert_list(binding):
     if isinstance(binding, list):
         binding = annotate.MethodBinding(
             name, annotate.Method(arguments=[
             annotate.Argument(n, v, v.id)
             for (n, v) in binding]))
     return binding
Ejemplo n.º 10
0
 def bind_delete(self, ctx):
     return annotate.MethodBinding(
         'delete',
         annotate.Method(arguments=[
             annotate.Argument('ctx', annotate.Context()),
         ],
                         label=_('Confirm delete')),
         action=_('Delete'))
Ejemplo n.º 11
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
Ejemplo n.º 12
0
 def bind_cancel(self, ctx):
     return annotate.MethodBinding(
         'cancel',
         annotate.Method(arguments=[
         annotate.Argument('context', annotate.Context()),
         ],
                         label=_('Cancel')),
         action=_('Cancel'))
Ejemplo n.º 13
0
 def _bind(ctx):
     return annotate.MethodBinding('action_' + name,
                                   annotate.Method(arguments=[
                                       annotate.Argument(*field)
                                       for field in fields
                                   ],
                                                   label=desc),
                                   action=btnlabel)
Ejemplo n.º 14
0
 def bind_remove(self, ctx):
     return annotate.MethodBinding('remove',
                                   annotate.Method(arguments=[
                                       annotate.Argument(
                                           'ctx', annotate.Context()),
                                   ],
                                                   label=_('Remove')),
                                   action=_('Remove'))
Ejemplo n.º 15
0
 def bind_generateRandom(self, ctx):
     return annotate.MethodBinding(
         'generateRandom',
         annotate.Method(arguments=[
             annotate.Argument('ctx', annotate.Context()),
         ],
                         label=_('Generate random')),
         action=_('Generate random'))
Ejemplo n.º 16
0
    def _getFormFields(self):
        r = []
        r.append(annotate.Argument('context', annotate.Context()))

        process = {}

        # TODO sort objectclasses somehow?
        objectClasses = list(self.chosenObjectClasses)
        objectClassesSeen = {}

        self.nonUserEditableAttributes = []
        while objectClasses:
            objectClass = objectClasses.pop()
            objclassName = objectClass.name[0]

            if objectClassesSeen.has_key(objclassName):
                continue
            objectClassesSeen[objclassName] = 1

            for ocName in objectClass.sup or []:
                objclass = mapNameToObjectClass(self.objectClasses, ocName)
                assert objclass, "Objectclass %s must have schema" % objclassName
                objectClasses.append(objclass)

            for attr_alias in objectClass.must:
                real_attr = self._get_attrtype(str(attr_alias))

                if hasattr(self, 'nonUserEditableAttributeType_' +
                           real_attr.name[0]):
                    self.nonUserEditableAttributes.append(real_attr.name[0])
                else:
                    for attr in real_attr.name:
                        if not process.has_key(attr.upper()):
                            process[attr.upper()] = 0
                        if not process[attr.upper()]:
                            self._one_formfield(attr, result=r, must=True)
                        for name in real_attr.name:
                            process[name.upper()] = 1

            for attr_alias in objectClass.may:
                real_attr = self._get_attrtype(str(attr_alias))

                if hasattr(self, 'nonUserEditableAttributeType_' +
                           real_attr.name[0]):
                    self.nonUserEditableAttributes.append(real_attr.name[0])
                else:
                    for attr in real_attr.name:
                        if not process.has_key(attr.upper()):
                            process[attr.upper()] = 0
                        if not process[attr.upper()]:
                            self._one_formfield(attr, result=r)
                        for name in real_attr.name:
                            process[name.upper()] = 1

        assert [v == 1 for k, v in process.items()], "TODO: %s" % process
        return r
Ejemplo n.º 17
0
 def bind_add(self, ctx):
     return annotate.MethodBinding(
         'add',
         annotate.Method(arguments=[
             annotate.Argument('ctx', annotate.Context()),
             annotate.Argument(
                 'serviceName',
                 annotate.String(required=True, label=_('Service name'))),
             annotate.Argument(
                 'newPassword',
                 annotate.PasswordEntry(
                     required=False,
                     label=_('New password'),
                     description=_(
                         "Leave empty to generate random password."))),
             annotate.Argument(
                 'again',
                 annotate.PasswordEntry(required=False, label=_('Again'))),
         ],
                         label=_('Add')),
         action=_('Add'))
Ejemplo n.º 18
0
    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')))
Ejemplo n.º 19
0
 def addElement(self, name, type):
     self.formElements.append(annotate.Argument(name, type()))