Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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]
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def __init__(self, organizer):
     self.organizer = organizer
     liveform.LiveForm.__init__(
         self, self.addPerson,
         (liveform.Parameter(
             'nickname',
             liveform.TEXT_INPUT,
             people._normalizeWhitespace,
             'Name'),
          liveform.Parameter(
              'email',
              liveform.TEXT_INPUT,
              people._normalizeWhitespace,
              'Email')),
          description=u'Add Person')
Ejemplo n.º 6
0
 def __init__(self, uis):
     self.userInfoSignup = uis
     self.templateResolver = ITemplateNameResolver(uis.store)
     super(ValidatingSignupForm, self).__init__(uis.createUser, [
         liveform.Parameter(pname, liveform.TEXT_INPUT, unicode)
         for pname in self._parameterNames
     ])
Ejemplo n.º 7
0
 def __init__(self, blogPost):
     super(BlogPostBlurbEditor, self).__init__(
         lambda *a, **k: blogPost.edit(newAuthor=blogPost.author, *a, **k),
         (liveform.Parameter(
             'newTitle',
             liveform.TEXT_INPUT,
             unicode),
          liveform.Parameter(
             'newBody',
             liveform.TEXT_INPUT,
             unicode),
          liveform.Parameter(
             'newTags',
             liveform.TEXT_INPUT,
             parseTags)))
     self.blogPost = blogPost
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
0
 def __init__(self, page, hyperbola):
     super(BlogAddingFragment, self).__init__(
         hyperbola.createBlog,
         [liveform.Parameter(
             'title',
             liveform.TEXT_INPUT,
             unicode,
             "A title for your blog",
             "A Blog"),
          liveform.Parameter(
             'description',
             liveform.TEXT_INPUT,
             unicode,
             "A description of your blog",
             "A Blog that I write")])
     self.setFragmentParent(page)
     self.hyperbola = hyperbola
     _docFactorify(self)
Ejemplo n.º 11
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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 14
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
Ejemplo n.º 15
0
    def __init__(self, composer, message):
        """
        @type composer: L{Composer}

        @param message: the message being redirected
        @type message: L{Message}
        """
        self.composer = composer
        self.message = message

        self.translator = ixmantissa.IWebTranslator(composer.store)

        super(RedirectingComposeFragment, self).__init__(
            callable=self.redirect,
            parameters=(liveform.Parameter(name='fromAddress',
                                           type=liveform.TEXT_INPUT,
                                           coercer=self.translator.fromWebID),
                        liveform.Parameter(name='toAddresses',
                                           type=liveform.TEXT_INPUT,
                                           coercer=self._coerceEmailAddressString)))
Ejemplo n.º 16
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]
Ejemplo n.º 17
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
Ejemplo n.º 18
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))
Ejemplo n.º 19
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')
Ejemplo n.º 20
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
Ejemplo n.º 21
0
    def __init__(self, parent):
        self.parent = parent
        self._commentTypeName = flavorNames[
            FLAVOR.commentFlavors[parent.original.flavor]]

        super(AddCommentFragment, self).__init__(
            self.addComment,
            (liveform.Parameter(
                'title',
                liveform.TEXT_INPUT,
                unicode,
                'Title'),
             liveform.Parameter(
                'body',
                liveform.TEXT_INPUT,
                unicode,
                'Body'),
             liveform.Parameter(
                'tags',
                liveform.TEXT_INPUT,
                parseTags)))

        _docFactorify(self)
Ejemplo n.º 22
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
Ejemplo n.º 23
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]
Ejemplo n.º 24
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]
Ejemplo n.º 25
0
            prompt: a short unicode string describing this signup mechanism, as
            distinct from others.  For example: "Student Sign Up", or "Faculty
            Sign Up"

        @param configuration: a list of LiveForm arguments.
        """
        self.name = name
        self.description = description
        self.itemClass = itemClass
        self.configuration = configuration


freeTicketSignupConfiguration = [
    liveform.Parameter(
        'prefixURL',
        liveform.TEXT_INPUT,
        unicode,
        u'The web location at which users will be able to request tickets.',
        default=u'signup')
]


class FreeTicketSignup(Item, PrefixURLMixin):
    implements(ISiteRootPlugin)

    typeName = 'free_signup'
    schemaVersion = 6

    sessioned = True

    prefixURL = text(allowNone=False)
    booth = reference()
Ejemplo n.º 26
0
 def textParam(name, label, *a):
     return liveform.Parameter(name, liveform.TEXT_INPUT,
                               makeRequiredCoercer(name), label, *a)
Ejemplo n.º 27
0
    def __init__(self, composer, recipients=None, subject=u'', messageBody=u'',
                 attachments=(), inline=False, parentMessage=None,
                 parentAction=None):
        """
        @type composer: L{Composer}

        @param recipients: email addresses of the recipients of this message.
        defaults to no recipients
        @type recipients: C{dict} which can contain any combination of the
        keys C{to}, C{cc} and C{bcc}, where the values are sequences of
        L{xquotient.mimeutil.EmailAddress} instances

        @param subject: the subject of this message
        @type subject: C{unicode}

        @param messageBody: the body of this message
        @type messageBody: C{unicode}

        @param attachments: the attachments of this message
        @type attachments: sequence of L{xquotient.mimepart.AttachmentPart}
        instances

        @param inline: whether the compose widget is being displayed inline,
        e.g. as a child of another widget
        @type inline: boolean

        @param parentMessage: The existing message this message is in
        response to, if any; otherwise None.

        @param parentAction: The status that should be set on the
        parent message, if any, once this message is delivered. Should
        be a value from L{xquotient.exmess} that ends in C{_STATUS}.

        C{toAddresses}, C{subject}, C{messageBody} and C{attachments} should
        be considered as presets - their values can be manipulated via the
        user interface
        """
        self.composer = composer
        self.cabinet = self.composer.store.findOrCreate(FileCabinet)
        self.translator = ixmantissa.IWebTranslator(composer.store)
        self._savedDraft = None
        super(ComposeFragment, self).__init__(
            callable=self._sendOrSave,
            parameters=[liveform.Parameter(name='fromAddress',
                                           type=liveform.TEXT_INPUT,
                                           coercer=self.translator.fromWebID),
                        liveform.Parameter(name='toAddresses',
                                           type=liveform.TEXT_INPUT,
                                           coercer=self._coerceEmailAddressString),
                        liveform.Parameter(name='subject',
                                           type=liveform.TEXT_INPUT,
                                           coercer=unicode),
                        liveform.Parameter(name='messageBody',
                                           type=liveform.TEXTAREA_INPUT,
                                           coercer=unicode),
                        liveform.Parameter(name='cc',
                                           type=liveform.TEXT_INPUT,
                                           coercer=self._coerceEmailAddressString),
                        liveform.Parameter(name='bcc',
                                           type=liveform.TEXT_INPUT,
                                           coercer=self._coerceEmailAddressString),
                        liveform.Parameter(name='draft',
                                           type=liveform.CHECKBOX_INPUT,
                                           coercer=bool)])
        if recipients is None:
            recipients = {}
        self.recipients = recipients
        self.subject = subject
        self.messageBody = messageBody
        self.attachments = attachments
        self.fileAttachments = []
        self.inline = inline

        self.docFactory = None
        self.parentMessage = parentMessage
        self.parentAction = parentAction
Ejemplo n.º 28
0
 def makePowerupSelector(self, desc):
     return liveform.Parameter('selectedPowerup',
                               liveform.CHECKBOX_INPUT,
                               bool, desc)
Ejemplo n.º 29
0
 def getPreferenceParameters(self):
     return (liveform.Parameter('foo', liveform.TEXT_INPUT, str), )
Ejemplo n.º 30
0
 def getPreferenceParameters(self):
     return (liveform.Parameter('preferredWidget', liveform.TEXT_INPUT,
                                unicode, 'Preferred Widget'), )