Exemplo n.º 1
0
 def invoke(self, *a, **kw):
     item = super(ItemView, self).invoke(*a, **kw)
     if self.item is None and item is not None:
         self.createItem(item)
         if self.switchInPlace:
             self.item = item
         else:
             link = IWebTranslator(item.store).linkTo(item.storeID)
             return link.decode('ascii')
Exemplo n.º 2
0
 def invoke(self, *a, **kw):
     item = super(ItemView, self).invoke(*a, **kw)
     if self.item is None and item is not None:
         self.createItem(item)
         if self.switchInPlace:
             self.item = item
         else:
             link = IWebTranslator(item.store).linkTo(item.storeID)
             return link.decode('ascii')
Exemplo n.º 3
0
 def test_renderedScrollerInitializedCorrectly(self):
     """
     L{hyperbola_view.BlogBlurbViewer.render_view} should return a
     L{hyperbola.hyperbola_view.ShareScrollTable} that is aware of
     all of the posts that have been made to the blog.
     """
     scroller = self._getRenderViewScroller()
     rows = scroller.rowsAfterValue(None, 10)
     self.assertEqual(len(rows), 1)
     theRow = rows[0]
     self.assertEqual(
         theRow['dateCreated'],
         self.blogPostItem.dateCreated.asPOSIXTimestamp())
     self.assertEqual(
         theRow['__id__'],
         IWebTranslator(self.userStore).toWebID(self.blogPostItem))
     blogPostFragment = theRow['blurbView']
     # the scrolltable fragment is not customized, so we want to
     # ensure that the proxy passed to the IColumns is the facet
     # shared to Everyone
     self.assertEqual(
         list(blogPostFragment.original.sharedInterfaces),
         list(self.blogPostSharedToEveryone.sharedInterfaces))
     self.assertIdentical(
         sharing.itemFromProxy(blogPostFragment.original),
         self.blogPostItem)
Exemplo n.º 4
0
def _webTranslator(store, fallback):
    """
    Discover a web translator based on an Axiom store and a specified default.
    Prefer the specified default.

    This is an implementation detail of various initializers in this module
    which require an L{IWebTranslator} provider.  Some of those initializers
    did not previously require a webTranslator, so this function will issue a
    L{UserWarning} if no L{IWebTranslator} powerup exists for the given store
    and no fallback is provided.

    @param store: an L{axiom.store.Store}
    @param fallback: a provider of L{IWebTranslator}, or None

    @return: 'fallback', if it is provided, or the L{IWebTranslator} powerup on
    'store'.
    """
    if fallback is None:
        fallback = IWebTranslator(store, None)
        if fallback is None:
            warnings.warn(
                "No IWebTranslator plugin when creating Scrolltable - broken "
                "configuration, now deprecated!  Try passing webTranslator "
                "keyword argument.",
                category=DeprecationWarning,
                stacklevel=4)
    return fallback
Exemplo n.º 5
0
    def rootChild_resetPassword(self, req, webViewer):
        """
        Redirect authenticated users to their settings page (hopefully they
        have one) when they try to reset their password.

        This is the wrong way for this functionality to be implemented.  See
        #2524.
        """
        from xmantissa.ixmantissa import IWebTranslator, IPreferenceAggregator
        return URL.fromString(
            IWebTranslator(self.store).linkTo(
                IPreferenceAggregator(self.store).storeID))
Exemplo n.º 6
0
    def test_invoke(self):
        """
        L{ComposeFragment.invoke} accepts a browser-generated structure
        representing the values in the compose form, coerces it according to
        the L{Parameters} it defines, and passes the result to the LiveForm
        callable.
        """
        # The from addresses are web ids for FromAddress items.
        fromAddr = IWebTranslator(self.userStore).toWebID(self.defaultFromAddr)

        # Override the callable to see what happens.
        sent = []
        expectedResult = object()

        def fakeSend(fromAddress, toAddresses, subject, messageBody, cc, bcc,
                     files, draft):
            sent.append((fromAddress, toAddresses, subject, messageBody, cc,
                         bcc, files, draft))
            return expectedResult

        self.cf.callable = fakeSend

        toAddresses = [
            mimeutil.EmailAddress(u'*****@*****.**', False),
            mimeutil.EmailAddress(u'*****@*****.**', False)
        ]
        subject = u'Hello World'
        body = u'How are you'
        cc = [mimeutil.EmailAddress(u'*****@*****.**', False)]
        bcc = [mimeutil.EmailAddress(u'*****@*****.**', False)]
        draft = True

        invokeDeferred = self.cf.invoke({
            u'fromAddress': [fromAddr],
            u'toAddresses': [mimeutil.flattenEmailAddresses(toAddresses)],
            u'subject': [subject],
            u'messageBody': [body],
            u'cc': [mimeutil.flattenEmailAddresses(cc)],
            u'bcc': [mimeutil.flattenEmailAddresses(bcc)],
            u'draft': [draft]
        })

        def cbInvoked(invokeResult):
            self.assertEquals(
                sent,
                [(self.defaultFromAddr, toAddresses, subject, body, cc, bcc,
                  (), draft)])
            self.assertIdentical(invokeResult, expectedResult)

        invokeDeferred.addCallback(cbInvoked)
        return invokeDeferred
Exemplo n.º 7
0
    def dictifyItem(self, item, index):
        def _formatValue(value):
            if isinstance(value, Time):
                return value.asDatetime(self.timezone).strftime(
                    '%a, %d %h %Y %H:%M:%S').decode('ascii')
            return value

        if isinstance(item, tuple):
            link, item = item
        else:
            if self.webTranslator is None:
                self.webTranslator = IWebTranslator(item.store)
            link = unicode(self.webTranslator.toWebID(item), 'ascii')

        d = dict((cid, _formatValue(col.extractValue(self, item)))
                 for (cid, col) in self.columns)
        d[u'__link__'] = link
        d[u'__id__'] = index

        return d
Exemplo n.º 8
0
    def test_authenticatedResetPasswordRedirectsToSettings(self):
        """
        When a user is already logged in, navigating to C{/resetPassword}
        redirects them to their own settings page.
        """
        prefPage = IPreferenceAggregator(self.userStore)
        urlPath = IWebTranslator(self.userStore).linkTo(prefPage.storeID)

        # Get the password reset resource.
        page = getResource(self.factory,
                           '/resetPassword',
                           headers={'host': self.domain.encode('ascii')},
                           cookies=self.cookies)

        def rendered(request):
            # Make sure it's a redirect to the settings page.
            self.assertEquals(
                'http://' + self.domain.encode('ascii') + urlPath,
                request.redirected_to)

        page.addCallback(rendered)
        return page
Exemplo n.º 9
0
    def setUp(self):
        """
        Create a handful of messages spread out over a brief time period so
        that tests can assert things about methods which operate on messages.
        """
        self.store = Store()

        inboxItem = Inbox(store=self.store)
        installOn(inboxItem, self.store)
        self.privateApplication = inboxItem.privateApplication
        self.webTranslator = IWebTranslator(self.store)

        baseTime = datetime(year=2001, month=3, day=6)
        self.msgs = []
        for i in xrange(5):
            self.msgs.append(
                testMessageFactory(
                    store=self.store,
                    read=False,
                    spam=False,
                    receivedWhen=Time.fromDatetime(baseTime +
                                                   timedelta(seconds=i))))

        self.inbox = InboxScreen(inboxItem)
Exemplo n.º 10
0
 def extractLink(self, model, item):
     webTranslator = IWebTranslator(item.store, None)
     if webTranslator is not None:
         return unicode(webTranslator.toWebID(item), 'ascii')
     return None
Exemplo n.º 11
0
class QueryList(ThemedElement):
    """
    A widget that displays data tabulated according to a set of columns.

    Actions are supported too.
    """
    jsClass = u'Methanal.Widgets.QueryList'
    fragmentName = 'methanal-table'

    def __init__(self, rows, columns, webTranslator=None, timezone=None, **kw):
        warn('QueryList is deprecated, use methanal.widgets.Table instead')
        super(QueryList, self).__init__(**kw)

        self.rows = list(rows)
        def _adapt(col):
            try:
                return IColumn(col)
            except TypeError:
                col = mantissaIColumn(col)

            warn('use methanal.imethanal.IColumn instead of '
                 'xmantissa.ixmantissa.IColumn', DeprecationWarning, 2)
            return col

        columns = (_adapt(col) for col in columns)
        self.columns = [(col.attributeID.decode('ascii'), col)
                        for col in columns]
        self.webTranslator = webTranslator

        if timezone is None:
            hour, minute = divmod(time.timezone, -3600)
            timezone = FixedOffset(hour, minute)
            warn('not passing in timezone is deprecated', DeprecationWarning, 2)

        self.timezone = timezone


    def dictifyItem(self, item, index):
        def _formatValue(value):
            if isinstance(value, Time):
                return value.asDatetime(self.timezone).strftime(
                    '%a, %d %h %Y %H:%M:%S').decode('ascii')
            return value

        if isinstance(item, tuple):
            link, item = item
        else:
            if self.webTranslator is None:
                self.webTranslator = IWebTranslator(item.store)
            link = unicode(self.webTranslator.toWebID(item), 'ascii')

        d = dict((cid, _formatValue(col.extractValue(self, item)))
                 for (cid, col) in self.columns)
        d[u'__link__'] = link
        d[u'__id__'] = index

        return d


    def getInitialArguments(self):
        return [getArgsDict(self)]


    def getArgs(self):
        IDs = []
        aliases = {}
        for cid, col in self.columns:
            IDs.append(cid)
            if isinstance(col, AttributeColumn):
                alias = col.attribute.doc
            else:
                alias = col
            aliases[cid] = unicode(alias)

        return {u'columnIDs':     IDs,
                u'columnAliases': aliases,
                u'rows':          [self.dictifyItem(row, i)
                                   for i, row in enumerate(self.rows)]}


    @expose
    def performAction(self, name, rowIndex):
        method = getattr(self, 'action_' + name)
        item = self.rows[rowIndex]
        return method(item)