示例#1
0
    def productForm(self, request, tag):
        """
        Render a L{liveform.LiveForm} -- the main purpose of this fragment --
        which will allow the administrator to endow or deprive existing users
        using Products.
        """

        def makeRemover(i):
            def remover(s3lected):
                if s3lected:
                    return self.products[i]
                return None
            return remover

        f = liveform.LiveForm(
            self._endow,
            [liveform.Parameter(
                    'products' + str(i),
                    liveform.FORM_INPUT,
                    liveform.LiveForm(
                        makeRemover(i),
                        [liveform.Parameter(
                                's3lected',
                                liveform.RADIO_INPUT,
                                bool,
                                repr(p),
                                )],
                        '',
                        ),
                    )
             for (i, p)
             in enumerate(self.products)],
            self.which.capitalize() + u' ' + self.username)
        f.setFragmentParent(self)
        return f
示例#2
0
 def getWidgetDocument(self):
     """
     Make a nested form
     """
     f = liveform.LiveForm(lambda **k: None, (liveform.Parameter(
         'inner-form', liveform.FORM_INPUT,
         liveform.LiveForm(lambda **k: None, (liveform.Parameter(
             'inner-parameter', liveform.TEXT_INPUT, unicode, ''), ),
                           ())), ))
     f.setFragmentParent(self)
     return f
示例#3
0
 def render_placeCall(self, ctx, data):
     lf = liveform.LiveForm(self.original.placeCall, [
         liveform.Parameter("target", liveform.TEXT_INPUT,
                            self.parseURLorPhoneNum, "Place call:")
     ])
     lf.setFragmentParent(self)
     return lf
示例#4
0
 def render_addGrabberForm(self, ctx, data):
     f = liveform.LiveForm(
         self.addGrabber,
         [
             liveform.Parameter('domain', liveform.TEXT_INPUT, unicode,
                                u'Domain',
                                u'The domain which hosts the account.'),
             liveform.Parameter(
                 'username', liveform.TEXT_INPUT, unicode, u'Username',
                 u'The username portion of the address from which to retrieve messages.'
             ),
             liveform.Parameter('password1', liveform.PASSWORD_INPUT,
                                unicode, u'Password',
                                u'The password for the remote account.'),
             liveform.Parameter('password2', liveform.PASSWORD_INPUT,
                                unicode, u'Repeat Password'),
             # Along with the above, this might be useful if we had an IMAP grabber.
             #              liveform.Parameter('protocol',
             #                                 liveform.Choice(grabberTypes.keys()),
             #                                 lambda value: grabberTypes[value],
             #                                 u'Super secret computer science stuff',
             #                                 'POP3'),
             liveform.Parameter('ssl', liveform.CHECKBOX_INPUT, bool,
                                u'Use SSL to fetch messages')
         ],
         description='Add Grabber')
     f.jsClass = u'Quotient.Grabber.AddGrabberFormWidget'
     f.setFragmentParent(self)
     f.docFactory = webtheme.getLoader('liveform-compact')
     return ctx.tag[f]
示例#5
0
 def productConfigurationForm(self, request, tag):
     productList = liveform.LiveForm(self.coerceProduct,
                                     [self.powerupConfigurationParameter(pi)
                                      for pi in self.getInstallablePowerups()],
                                     u"Installable Powerups")
     productList.setFragmentParent(self)
     return productList
示例#6
0
 def getWidgetDocument(self):
     """
     Make a LiveForm with one of each kind of input, except for radio
     buttons, since with the current liveform support for them it's
     difficult to use them with a single form, and it's not so important to
     do anything else right now
     """
     f = liveform.LiveForm(
         self.submit,
         (liveform.ChoiceParameter('choice',
                                   (('0', 0, True), ('1', 1, False))),
          liveform.ChoiceParameter('choiceMult',
                                   (('0', 0, True), ('1', 1, True),
                                    ('2', 2, False), ('3', 3, False)),
                                   multiple=True),
          liveform.Parameter(
              'text', liveform.TEXT_INPUT, unicode, default=u'hello world'),
          liveform.Parameter('passwd',
                             liveform.PASSWORD_INPUT,
                             unicode,
                             default=u'secret key'),
          liveform.Parameter('textArea',
                             liveform.TEXTAREA_INPUT,
                             unicode,
                             default=u'hello world 2'),
          liveform.Parameter(
              'checkbox', liveform.CHECKBOX_INPUT, bool, default=True)))
     f.setFragmentParent(self)
     return f
示例#7
0
 def getWidgetDocument(self):
     f = liveform.LiveForm(self.submit, [
         liveform.ChoiceParameter('argument', [('One', 1, False),
                                               ('Two', 2, True),
                                               ('Three', 3, False)])
     ])
     f.setFragmentParent(self)
     return f
示例#8
0
 def makeProductPicker(self):
     """
     Make a LiveForm with radio buttons for each Product in the store.
     """
     productPicker = liveform.LiveForm(self.coerceProduct, [
         liveform.Parameter(
             str(id(product)), liveform.FORM_INPUT,
             liveform.LiveForm(
                 lambda selectedProduct, product=product: selectedProduct
                 and product, [
                     liveform.Parameter('selectedProduct',
                                        liveform.RADIO_INPUT, bool,
                                        repr(product))
                 ]))
         for product in self.original.store.parent.query(Product)
     ], u"Product to Install")
     return productPicker
示例#9
0
 def getWidgetDocument(self):
     f = liveform.LiveForm(
         self.submit, (liveform.ListParameter('sequence',
                                              int,
                                              4,
                                              'A bunch of text inputs: ',
                                              defaults=(1, 2, 3, 4)), ))
     f.setFragmentParent(self)
     return f
示例#10
0
 def render_altcontactForm(self, ctx, data):
     lf = liveform.LiveForm(self.setAltContact, [
         liveform.Parameter(
             "altcontact", liveform.TEXT_INPUT, self.parseURLorPhoneNum,
             "An alternate SIP URL or phone number to forward calls to when you are not registered",
             "")
     ], "Set")
     lf.setFragmentParent(self)
     return lf
示例#11
0
 def getWidgetDocument(self):
     f = liveform.LiveForm(self.submit, [
         liveform.ChoiceParameter('argument', [('One', 1, True),
                                               ('Two', 2, False),
                                               ('Three', 3, True)],
                                  "Choosing multiples from a list.",
                                  multiple=True)
     ])
     f.setFragmentParent(self)
     return f
示例#12
0
 def getWidgetDocument(self):
     f = liveform.LiveForm(self.submit, [
         liveform.Parameter('argument',
                            liveform.TEXTAREA_INPUT,
                            unicode,
                            'A text area: ',
                            default=self.defaultText)
     ])
     f.setFragmentParent(self)
     return f
示例#13
0
 def getWidgetDocument(self):
     f = liveform.LiveForm(self.submit, [
         liveform.Parameter('argument',
                            liveform.TEXT_INPUT,
                            unicode,
                            'A text input field: ',
                            default=u'hello world')
     ])
     f.setFragmentParent(self)
     return f
示例#14
0
 def getWidgetDocument(self):
     # XXX No support for rendering these yet!
     f = liveform.LiveForm(self.submit,
                           [liveform.Parameter('argument', None, unicode)])
     f.docFactory = loaders.stan(
         tags.form(render=tags.directive('liveElement'))
         [tags.select(
             name="argument")[tags.option(value="apples")["apples"],
                              tags.option(value="oranges")["oranges"]],
          tags.input(type='submit', render=tags.directive('submitbutton'))])
     f.setFragmentParent(self)
     return f
示例#15
0
class ProductFragment(athena.LiveElement):
    fragmentName = 'product-configuration'
    live = 'athena'

    def __init__(self, configger):
        athena.LiveElement.__init__(self)
        self.original = configger

    def head(self):
        #XXX put this in its own CSS file?
        return tags.style(type='text/css')['''
        input[name=linktext], input[name=subject], textarea[name=blurb] { width: 40em }
        ''']

    def getInstallablePowerups(self):
                for installedOffering in getInstalledOfferings(self.original.store.parent).itervalues():
                    for p in installedOffering.installablePowerups:
                        yield p


    def coerceProduct(self, **kw):
        """
        Create a product and return a status string which should be part of a
        template.

        @param **kw: Fully qualified Python names for powerup types to
        associate with the created product.
        """
        self.original.createProduct(filter(None, kw.values()))
        return u'Created.'


    def makePowerupCoercer(self, powerup):
        def powerupCoercer(selectedPowerup):
            if selectedPowerup:
                return powerup
            else:
                return None
        return powerupCoercer

    def makePowerupSelector(self, desc):
        return liveform.Parameter('selectedPowerup',
                                  liveform.CHECKBOX_INPUT,
                                  bool, desc)

    def powerupConfigurationParameter(self, (name, desc, p)):
        return liveform.Parameter(
            name,
            liveform.FORM_INPUT,
            liveform.LiveForm(self.makePowerupCoercer(p),
                              [self.makePowerupSelector(desc)],
                              name))
示例#16
0
 def getWidgetDocument(self):
     f = liveform.LiveForm(self.submit, [
         liveform.Parameter('argument',
                            liveform.TEXT_INPUT,
                            unicode,
                            'A text input field: ',
                            default=u'hello world'),
         liveform.Parameter(
             'group',
             liveform.FORM_INPUT,
             liveform.LiveForm(self.paramfilter, [
                 liveform.Parameter('param1',
                                    liveform.TEXT_INPUT,
                                    unicode,
                                    'Another input field: ',
                                    default=u'goodbye world')
             ]),
             'A form input group: ',
         )
     ])
     f.setFragmentParent(self)
     return f
示例#17
0
 def render_addRule(self, ctx, data):
     f = liveform.LiveForm(
         self.addRule,
         [liveform.Parameter('headerName', None, lambda s: s.strip().lower()),
          liveform.Parameter('negate', None, lambda s: bool([u"does", u"doesn't"].index(s))),
          liveform.Parameter('operation', None, _namesToOps.__getitem__),
          liveform.Parameter('value', None, unicode),
          liveform.Parameter('shortCircuit', None, bool),
          liveform.Parameter('caseSensitive', None, bool),
          liveform.Parameter('tagName', None, unicode)])
     f.jsClass = u'Quotient.Filter.RuleWidget'
     f.docFactory = webtheme.getLoader('add-filtering-rule')
     f.setFragmentParent(self)
     return ctx.tag[f]
示例#18
0
    def addAddressForm(self, req, tag):
        """
        @return: an L{xmantissa.liveform.LiveForm} instance which allows users
                 to add from addresses
        """
        def makeRequiredCoercer(paramName, coerce=lambda v: v):
            def notEmpty(value):
                if not value:
                    raise liveform.InvalidInput('value required for ' +
                                                paramName)
                return coerce(value)

            return notEmpty

        def textParam(name, label, *a):
            return liveform.Parameter(name, liveform.TEXT_INPUT,
                                      makeRequiredCoercer(name), label, *a)

        # ideally we would only show the "address" input by default and have a
        # "SMTP Info" disclosure link which exposes the rest of them

        lf = liveform.LiveForm(
            self.addAddress,
            (textParam('address',
                       'Email Address'), textParam('smtpHost', 'SMTP Host'),
             liveform.Parameter(
                 'smtpPort',
                 liveform.TEXT_INPUT,
                 makeRequiredCoercer('smtpPort', int),
                 'SMTP Port',
                 default=25), textParam('smtpUsername', 'SMTP Username'),
             liveform.Parameter('smtpPassword', liveform.PASSWORD_INPUT,
                                makeRequiredCoercer('smtpPassword'),
                                'SMTP Password'),
             liveform.Parameter('default', liveform.CHECKBOX_INPUT, bool,
                                'Default?',
                                'Use this as default from address')),
            description='Add From Address')
        lf.jsClass = u'Quotient.Compose.AddAddressFormWidget'
        lf.docFactory = getLoader('liveform-compact')
        lf.setFragmentParent(self)
        return lf
示例#19
0
 def render_postiniForm(self, ctx, data):
     f = liveform.LiveForm(self.configurePostini, [
         liveform.Parameter('usePostiniScore',
                            liveform.CHECKBOX_INPUT,
                            bool,
                            u'Use Postini Score',
                            u'Classify messages based on Postini scores.',
                            default=self.filter.usePostiniScore),
         liveform.Parameter('postiniThreshhold',
                            liveform.TEXT_INPUT,
                            float,
                            u'Postini Threshold',
                            u'Score below which to consider messages spam.',
                            default=self.filter.postiniThreshhold)
     ],
                           description='Configure Postini')
     f.jsClass = u"Quotient.Spam.PostiniSettings"
     f.setFragmentParent(self)
     f.docFactory = getLoader('liveform-compact')
     return ctx.tag[f]
示例#20
0
    def getEditGrabberForm(self, targetID):
        if self.wt is None:
            self.wt = self.original.privateApplication

        grabber = self.wt.fromWebID(targetID)

        f = liveform.LiveForm(
            lambda **kwargs: self.editGrabber(grabber, **kwargs),
            (liveform.Parameter('password1', liveform.PASSWORD_INPUT, unicode,
                                u'New Password'),
             liveform.Parameter('password2', liveform.PASSWORD_INPUT, unicode,
                                u'Repeat Password'),
             liveform.Parameter('ssl',
                                liveform.CHECKBOX_INPUT,
                                bool,
                                'Use SSL',
                                default=grabber.ssl)),
            description='Edit Grabber')

        grabber.grab()
        f.setFragmentParent(self)
        return unicode(flatten(f), 'utf-8')
示例#21
0
 def userCreate(self, request, tag):
     """
     Render a form for creating new users.
     """
     userCreator = liveform.LiveForm(
         self.createUser,
         [liveform.Parameter(
                 "localpart",
                 liveform.TEXT_INPUT,
                 unicode,
                 "localpart"),
          liveform.Parameter(
                 "domain",
                 liveform.TEXT_INPUT,
                 unicode,
                 "domain"),
          liveform.Parameter(
                 "password",
                 liveform.PASSWORD_INPUT,
                 unicode,
                 "password")])
     userCreator.setFragmentParent(self)
     return userCreator
示例#22
0
    def render_signupConfigurationForm(self, ctx, data):
        def makeSignupCoercer(signupPlugin):
            """
            Return a function that converts a selected flag and a set of
            keyword arguments into either None (if not selected) or a 2-tuple
            of (signupClass, kwargs).  signupClass is a callable which takes
            the kwargs as keyword arguments and returns an Item (a signup
            mechanism plugin gizmo).
            """
            def signupCoercer(selectedSignup, **signupConf):
                """
                Receive coerced values from the form post, massage them as
                described above.
                """
                if selectedSignup:
                    return signupPlugin.itemClass, signupConf
                return None

            return signupCoercer

        def coerceSignup(**kw):
            return filter(None, kw.values())[0]

        signupMechanismConfigurations = liveform.LiveForm(
            # makeSignupCoercer sets it up, we knock it down. (Nones returned
            # are ignored, there will be exactly one selected).
            coerceSignup,
            [
                liveform.Parameter(
                    signupMechanism.name, liveform.FORM_INPUT,
                    liveform.LiveForm(makeSignupCoercer(signupMechanism), [
                        liveform.Parameter('selectedSignup',
                                           liveform.RADIO_INPUT, bool,
                                           signupMechanism.description)
                    ] + signupMechanism.configuration, signupMechanism.name))
                for signupMechanism in
                self.original.getSignupSystems().itervalues()
            ],
            u"Signup Type")

        def coerceEmailTemplate(**k):
            return file(sibpath(__file__, 'signup.rfc2822')).read() % k

        emailTemplateConfiguration = liveform.LiveForm(coerceEmailTemplate, [
            liveform.Parameter(
                'subject',
                liveform.TEXT_INPUT,
                unicode,
                u'Email Subject',
                default='Welcome to a Generic Axiom Application!'),
            liveform.Parameter('blurb',
                               liveform.TEXTAREA_INPUT,
                               unicode,
                               u'Blurb',
                               default=''),
            liveform.Parameter(
                'linktext',
                liveform.TEXT_INPUT,
                unicode,
                u'Link Text',
                default=
                "Click here to claim your 'generic axiom application' account")
        ],
                                                       description=
                                                       'Email Template')
        emailTemplateConfiguration.docFactory = getLoader('liveform-compact')

        existing = list(self.original.store.parent.query(_SignupTracker))
        if 0 < len(existing):
            deleteSignupForm = liveform.LiveForm(
                lambda **kw: self._deleteTrackers(k for
                                                  (k, v) in kw.itervalues()
                                                  if v),
                [
                    liveform.Parameter('signup-' + str(i),
                                       liveform.CHECKBOX_INPUT,
                                       lambda wasSelected, tracker=tracker:
                                       (tracker, wasSelected),
                                       repr(tracker.signupItem))
                    for (i, tracker) in enumerate(existing)
                ],
                description='Delete Existing Signups')
            deleteSignupForm.setFragmentParent(self)
        else:
            deleteSignupForm = ''

        productPicker = self.makeProductPicker()

        createSignupForm = liveform.LiveForm(self.createSignup, [
            liveform.Parameter(
                'signupPrompt',
                liveform.TEXT_INPUT,
                unicode,
                u'Descriptive, user-facing prompt for this signup',
                default=u'Sign Up'),
            liveform.Parameter('product', liveform.FORM_INPUT, productPicker,
                               u'Pick some product'),
            liveform.Parameter('signupTuple', liveform.FORM_INPUT,
                               signupMechanismConfigurations,
                               u'Pick just one dude'),
            liveform.Parameter('emailTemplate', liveform.FORM_INPUT,
                               emailTemplateConfiguration,
                               u'You know you want to')
        ],
                                             description='Create Signup')
        createSignupForm.setFragmentParent(self)

        return [deleteSignupForm, createSignupForm]