Ejemplo n.º 1
0
 def load(self, *args, **kw):
     doc = self.original.load(*args, **kw)
     if self.default is _no_default:
         return inevow.IQ(doc).onePattern(self.pattern)
     else:
         try:
             return inevow.IQ(doc).onePattern(self.pattern)
         except stan.NodeNotFound:
             return self.default
Ejemplo n.º 2
0
    def render(self, ctx, key, args, errors):

        charset = util.getPOSTCharset(ctx)
        converter = iformal.IStringConvertible(self.original)

        if errors:
            value = self._valueFromRequestArgs(charset, key, args)
        else:
            value = converter.fromType(args.get(key))

        if value is None:
            value = iformal.IKey(self.noneOption).key()

        optionGen = inevow.IQ(self.template).patternGenerator('option')
        selectedOptionGen = inevow.IQ(self.template).patternGenerator('selectedOption')
        optionTags = []
        selectOther = True

        if self.noneOption is not None:
            noneValue = iformal.IKey(self.noneOption).key()
            if value == noneValue:
                tag = selectedOptionGen()
                selectOther = False
            else:
                tag = optionGen()
            tag.fillSlots('value', noneValue)
            tag.fillSlots('label', iformal.ILabel(self.noneOption).label())
            optionTags.append(tag)

        if self.options is not None:
            for item in self.options:
                if value == item:
                    tag = selectedOptionGen()
                    selectOther = False
                else:
                    tag = optionGen()
                tag.fillSlots('value', item)
                tag.fillSlots('label', item)
                optionTags.append(tag)

        if selectOther:
            tag = selectedOptionGen()
            otherValue = value
        else:
            tag = optionGen()
            otherValue = ''
        tag.fillSlots('value', self.otherOption[0])
        tag.fillSlots('label', self.otherOption[1])
        optionTags.append(tag)

        tag = T.invisible[self.template.load(ctx)]
        tag.fillSlots('key', key)
        tag.fillSlots('id', render_cssid(key))
        tag.fillSlots('options', optionTags)
        tag.fillSlots('otherValue', otherValue)
        return tag
Ejemplo n.º 3
0
 def accountChooser(self, request, tag):
     select = inevow.IQ(self.docFactory).onePattern('accountChooser')
     option = inevow.IQ(select).patternGenerator('accountChoice')
     selectedOption = inevow.IQ(select).patternGenerator('selectedAccountChoice')
     for acc in [None] + list(self._accountNames()):
         if acc == self.viewSelection["account"]:
             p = selectedOption
         else:
             p = option
         opt = p().fillSlots('accountName', acc or 'all')
         select[opt]
     return select
Ejemplo n.º 4
0
 def tagChooser(self, request, tag):
     select = inevow.IQ(self.docFactory).onePattern('tagChooser')
     option = inevow.IQ(select).patternGenerator('tagChoice')
     selectedOption = inevow.IQ(select).patternGenerator('selectedTagChoice')
     for tag in [None] + self.getUserTagNames():
         if tag == self.viewSelection["tag"]:
             p = selectedOption
         else:
             p = option
         opt = p().fillSlots('tagName', tag or 'all')
         select[opt]
     return select
Ejemplo n.º 5
0
    def _locatePatterns(self, pattern, default, loop=True):
        produced = []
        for item in self.original:
            try:
                for x in inevow.IQ(item)._locatePatterns(pattern,
                                                         None,
                                                         loop=False):
                    produced.append(x)
                    yield x.clone(deep=False, clearPattern=True)
            except stan.NodeNotFound:
                continue

        if produced:
            while True:
                for x in produced:
                    yield x.clone(deep=False, clearPattern=True)

        if default is None:
            raise stan.NodeNotFound, ("pattern", pattern)
        if hasattr(default, 'clone'):
            while True:
                yield default.clone(deep=False)
        else:
            while True:
                yield default
Ejemplo n.º 6
0
    def beforeRender(self, ctx):
        """
        Before rendering this page, identify the correct URL for the login to post
        to, and the error message to display (if any), and fill the 'login
        action' and 'error' slots in the template accordingly.
        """
        generator = ixmantissa.ISiteURLGenerator(self.store)
        url = generator.rootURL(IRequest(ctx))
        url = url.child('__login__')
        for seg in self.segments:
            url = url.child(seg)
        for queryKey, queryValues in self.arguments.iteritems():
            for queryValue in queryValues:
                url = url.add(queryKey, queryValue)

        req = inevow.IRequest(ctx)
        err = req.args.get('login-failure', ('', ))[0]

        if 0 < len(err):
            error = inevow.IQ(self.fragment).onePattern('error').fillSlots(
                'error', err)
        else:
            error = ''

        ctx.fillSlots("login-action", url)
        ctx.fillSlots("error", error)
Ejemplo n.º 7
0
    def render_authenticateLinks(self, ctx, data):
        """
        For unauthenticated users, add login and signup links to the given tag.
        For authenticated users, remove the given tag from the output.

        When necessary, the I{signup-link} pattern will be loaded from the tag.
        Each copy of it will have I{prompt} and I{url} slots filled.  The list
        of copies will be added as children of the tag.
        """
        if self.username is not None:
            return ''
        # there is a circular import here which should probably be avoidable,
        # since we don't actually need signup links on the signup page.  on the
        # other hand, maybe we want to eventually put those there for
        # consistency.  for now, this import is easiest, and although it's a
        # "friend" API, which I dislike, it doesn't seem to cause any real
        # problems...  -glyph
        from xmantissa.signup import _getPublicSignupInfo

        IQ = inevow.IQ(ctx.tag)
        signupPattern = IQ.patternGenerator('signup-link')

        signups = []
        for (prompt, url) in _getPublicSignupInfo(self.store):
            signups.append(
                signupPattern.fillSlots('prompt',
                                        prompt).fillSlots('url', url))

        return ctx.tag[signups]
Ejemplo n.º 8
0
 def load(self, ctx=None):
     if self._cache is None:
         stan = flat.precompile(self.stan, ctx)
         if self.pattern is not None:
             stan = inevow.IQ(stan).onePattern(self.pattern)
         self._cache = stan
     return self._cache
Ejemplo n.º 9
0
 def patternContext(self, ctx, name):
     context = WovenContext(parent=ctx)
     self.rememberStuff(context)
     # XXX: preprocessors?
     doc = self.docFactory.load(context)
     context.tag = inevow.IQ(doc).onePattern(name)
     return context
Ejemplo n.º 10
0
 def repeater(self, req, tag):
     """
     Render some UI for repeating our form.
     """
     repeater = inevow.IQ(self.docFactory).onePattern('repeater')
     return repeater.fillSlots('object-description',
                               self.parameter.modelObjectDescription)
Ejemplo n.º 11
0
 def load(self, ctx=None):
     if self._cache is None:
         doc = flatsax.parseString(self.template, self.ignoreDocType, self.ignoreComment)
         doc = flat.precompile(doc, ctx)
         if self.pattern is not None:
             doc = inevow.IQ(doc).onePattern(self.pattern)
         self._cache = doc
     return self._cache
Ejemplo n.º 12
0
 def load(self, ctx=None):
     if self._cache is None:
         from twisted.web import microdom
         doc = microdom.parseString(self.template, beExtremelyLenient=self.beExtremelyLenient)
         doc = flat.precompile(doc, ctx)
         if self.pattern is not None:
             doc = inevow.IQ(doc).onePattern(self.pattern)
         self._cache = doc
     return self._cache
Ejemplo n.º 13
0
 def render_tabs(self, ctx, data):
     tabPattern = inevow.IQ(self.docFactory).patternGenerator('tab')
     for (i, (name, content)) in enumerate(self.pages):
         if self.selected == i:
             cls = 'nevow-tabbedpane-selected-tab'
         else:
             cls = 'nevow-tabbedpane-tab'
         yield tabPattern.fillSlots('tab-name',
                                    name).fillSlots('class', cls)
Ejemplo n.º 14
0
 def render_pages(self, ctx, data):
     pagePattern = inevow.IQ(self.docFactory).patternGenerator('page')
     for (i, (name, content)) in enumerate(self.pages):
         if self.selected == i:
             cls = 'nevow-tabbedpane-selected-pane'
         else:
             cls = 'nevow-tabbedpane-pane'
         yield pagePattern.fillSlots('page-content',
                                     content).fillSlots('class', cls)
Ejemplo n.º 15
0
    def mailViewChooser(self, request, tag):
        select = inevow.IQ(self.docFactory).onePattern('mailViewChooser')
        option = inevow.IQ(select).patternGenerator('mailViewChoice')
        selectedOption = inevow.IQ(select).patternGenerator('selectedMailViewChoice')

        counts = self.mailViewCounts()
        counts = sorted(counts.iteritems(), key=lambda (v, c): VIEWS.index(v))

        curview = self.viewSelection["view"]
        for (view, count) in counts:
            if view == curview:
                p = selectedOption
            else:
                p = option

            select[p().fillSlots(
                        'mailViewName', view.title()).fillSlots(
                        'count', count)]
        return select
Ejemplo n.º 16
0
    def button(self, request, tag):
        if self._buttonPattern is None:
            self._buttonPattern = inevow.IQ(
                getLoader('button')).patternGenerator('button')
        # take the contents of the tag and stuff it inside the button pattern,
        # and copy over any attributes

        button = self._buttonPattern()
        button.attributes.update(tag.attributes)
        return button.fillSlots('content', tag.children)
Ejemplo n.º 17
0
 def load(self, ctx=None, preprocessors=()):
     assert not preprocessors, "preprocessors not supported by htmlstr"
     if self._cache is None:
         doc = microdom.parseString(
             self.template, beExtremelyLenient=self.beExtremelyLenient)
         doc = flat.precompile(doc, ctx)
         if self.pattern is not None:
             doc = inevow.IQ(doc).onePattern(self.pattern)
         self._cache = doc
     return self._cache
Ejemplo n.º 18
0
 def load(self, ctx=None, preprocessors=()):
     if self._cache is None:
         stan = [self.stan]
         for proc in preprocessors:
             stan = proc(stan)
         stan = flat.precompile(stan, ctx)
         if self.pattern is not None:
             stan = inevow.IQ(stan).onePattern(self.pattern)
         self._cache = stan
     return self._cache
Ejemplo n.º 19
0
 def test_rawSingleQuote(self):
     """When putting something returned from IQ or otherwise extracted
     from a docFactory inside a single-quote string, the FlattenRaw must
     be responsible for quoting single-quotes.
     """
     l = loaders.stan(
         tags.div(pattern="foo")[
             tags.a(onclick=livepage.js.foo('bar'))["click\n me"]])
     self.assertEquals(
         flat.flatten(livepage.js.foo(inevow.IQ(l).onePattern('foo')), makeCtx()),
         """foo('<div><a onclick="foo(\\\'bar\\\')">click\\n me</a></div>')""")
Ejemplo n.º 20
0
 def load(self, ctx=None):
     mtime, doc = self._cache.get((self._filename, self.pattern), (None,None))
     self._mtime = os.path.getmtime(self._filename)
     if mtime == self._mtime:
         return doc
     doc = flatsax.parse(open(self._filename), self.ignoreDocType, self.ignoreComment)
     doc = flat.precompile(doc)
     if self.pattern is not None:
         doc = inevow.IQ(doc).onePattern(self.pattern)
     self._cache[(self._filename, self.pattern)] = self._mtime, doc
     return doc
Ejemplo n.º 21
0
    def _reallyLoad(self, path, ctx, preprocessors):
        doc = flatsax.parse(open(self._filename), self.ignoreDocType,
                            self.ignoreComment)
        for proc in preprocessors:
            doc = proc(doc)
        doc = flat.precompile(doc, ctx)

        if self.pattern is not None:
            doc = inevow.IQ(doc).onePattern(self.pattern)

        return doc
Ejemplo n.º 22
0
 def load(self, ctx=None):
     mtime = os.path.getmtime(self._filename)
     if mtime != self._mtime or self._cache is None:
         from twisted.web import microdom
         doc = microdom.parse(self._filename, beExtremelyLenient=self.beExtremelyLenient)
         doc = flat.precompile(doc, ctx)
         if self.pattern is not None:
             doc = inevow.IQ(doc).onePattern(self.pattern)
         self._mtime = mtime
         self._cache = doc
     return self._cache
Ejemplo n.º 23
0
 def tags(self, request, tag):
     """
     Render all tags
     """
     iq = inevow.IQ(self.docFactory)
     selTag = self._getSelectedTag(request)
     for tag in self._getAllTags():
         if tag == selTag:
             pattern = 'selected-tag'
         else:
              pattern = 'tag'
         yield iq.onePattern(pattern).fillSlots('name', tag)
Ejemplo n.º 24
0
 def render_existingRules(self, ctx, data):
     rule = inevow.IQ(ctx.tag).patternGenerator('rule')
     for hdrrule in self.original.store.query(HeaderRule):
         ctx.tag[rule().fillSlots(
             'headerName', hdrrule.headerName).fillSlots(
             'negate', hdrrule.negate).fillSlots(
             'operation', _opsToNames[hdrrule.operation]).fillSlots(
             'value', hdrrule.value).fillSlots(
             'shortCircuit', hdrrule.shortCircuit).fillSlots(
             'caseSensitive', hdrrule.caseSensitive).fillSlots(
             'tagName', hdrrule.action.tagName)]
     return ctx.tag
Ejemplo n.º 25
0
    def __init__(self, original):
        self.original = original
        # think about this some more - the messageID or partID could be the
        # mangled storeID of the part to facilitate the making of child
        # links here, but nobody except for us really needs to know about
        # this.
        self.docFactory = getLoader('message-detail-patterns')
        self.iframePattern = inevow.IQ(
            self.docFactory).patternGenerator('content-iframe')

        self.urlPrefix = ixmantissa.IWebTranslator(original.part.store).linkTo(
            original.messageID)
Ejemplo n.º 26
0
    def personChooser(self, request, tag):
        select = inevow.IQ(self.docFactory).onePattern('personChooser')
        option = inevow.IQ(select).patternGenerator('personChoice')
        selectedOption = inevow.IQ(select).patternGenerator('selectedPersonChoice')

        for person in [None] + list(self.inbox.getPeople()):
            if person == self.viewSelection["person"]:
                p = selectedOption
            else:
                p = option
            if person:
                name = person.getDisplayName()
                key = self.translator.toWebID(person)
            else:
                name = key = 'all'

            opt = p().fillSlots(
                    'personName', name).fillSlots(
                    'personKey', key)

            select[opt]
        return select
Ejemplo n.º 27
0
 def _formatFromAddressSelection(self, fromAddresses):
     """
     Turn the given L{smtpout.FromAddress} items into some stan,
     using the C{from-select} and C{from-select-option} patterns
     from the template
     """
     iq = inevow.IQ(self.docFactory)
     return iq.onePattern('from-select').fillSlots(
                     'options', [iq.onePattern(
                                 'from-select-option').fillSlots(
                                     'address', addr.address).fillSlots(
                                     'value', self.translator.toWebID(addr))
                                     for addr in fromAddresses])
Ejemplo n.º 28
0
 def onePattern(self, pattern):
     found = False
     for item in self.original:
         try:
             oldFound = found
             found = inevow.IQ(item).onePattern(pattern)
             if oldFound:
                 raise stan.TooManyNodes('pattern', pattern)
         except stan.NodeNotFound:
             continue
     if not found:
         raise stan.NodeNotFound('pattern', pattern)
     return found
Ejemplo n.º 29
0
 def blogs(self, req, tag):
     """
     Render all blogs
     """
     p = inevow.IQ(self.docFactory).patternGenerator('blog')
     webapp = ixmantissa.IWebTranslator(self.hyperbola.store)
     blogs = list()
     primaryRole = sharing.getSelfRole(self.hyperbola.store)
     for blog in self.hyperbola.getTopLevelFor(primaryRole):
         blogs.append(p.fillSlots(
                 'title', blog.title).fillSlots(
                 'link', websharing.linkTo(blog)).fillSlots(
                 'post-url', self._getPostURL(blog)))
     return tag[blogs]
Ejemplo n.º 30
0
 def load(self, ctx=None, preprocessors=()):
     """
     Get an instance, possibly cached from a previous call, of this document
     """
     if self._cache is None:
         doc = flatsax.parseString(self.template, self.ignoreDocType,
                                   self.ignoreComment)
         for proc in preprocessors:
             doc = proc(doc)
         doc = flat.precompile(doc, ctx)
         if self.pattern is not None:
             doc = inevow.IQ(doc).onePattern(self.pattern)
         self._cache = doc
     return self._cache