Ejemplo n.º 1
0
    def __str__(self):
        url = super(TransientTileAbsoluteURL, self).__str__()
        manager = ITileDataManager(self.context)

        # Transient looking tile with id is only really transient
        # if it caches its decoded query data in request annotations
        transient = manager.storage == IAnnotations(self.request)

        # When transient looking tile with id is not really transient,
        # its data should not be encoded into query string
        if self.context.id and not transient:
            return url

        # All tiles don't need / have configuration data at all.
        data = manager.get()
        if not data:
            return url

        # But when configuration data is really read from query string
        # and not persisted, it should also be kept in query string
        tileType = queryUtility(ITileType, name=self.context.__name__)
        if tileType is not None and tileType.schema is not None:
            if '?' in url:
                url += '&' + encode(data, tileType.schema)
            else:
                url += '?' + encode(data, tileType.schema)
        return url
Ejemplo n.º 2
0
    def __str__(self):
        url = super(TransientTileAbsoluteURL, self).__str__()
        manager = ITileDataManager(self.context)

        # Transient looking tile with id is only really transient
        # if it caches its decoded query data in request annotations
        transient = manager.storage == IAnnotations(self.request)

        # When transient looking tile with id is not really transient,
        # its data should not be encoded into query string
        if self.context.id and not transient:
            return url

        # All tiles don't need / have configuration data at all.
        data = manager.get()
        if not data:
            return url

        # But when configuration data is really read from query string
        # and not persisted, it should also be kept in query string
        tileType = queryUtility(ITileType, name=self.context.__name__)
        if tileType is not None and tileType.schema is not None:
            if '?' in url:
                url += '&' + encode(data, tileType.schema)
            else:
                url += '?' + encode(data, tileType.schema)
        return url
Ejemplo n.º 3
0
 def __str__(self):
     url = super(TransientTileAbsoluteURL, self).__str__()
     data = ITileDataManager(self.context).get()
     if data:
         tileType = queryUtility(ITileType, name=self.context.__name__)
         if tileType is not None and tileType.schema is not None:
             if '?' in url:
                 url += '&' + encode(data, tileType.schema)
             else:
                 url += '?' + encode(data, tileType.schema)
     return url
Ejemplo n.º 4
0
 def __str__(self):
     url = super(TransientTileAbsoluteURL, self).__str__()
     data = ITileDataManager(self.context).get()
     if data:
         tileType = queryUtility(ITileType, name=self.context.__name__)
         if tileType is not None and tileType.schema is not None:
             if '?' in url:
                 url += '&' + encode(data, tileType.schema)
             else:
                 url += '?' + encode(data, tileType.schema)
     return url
Ejemplo n.º 5
0
 def test_skip_encoding_primary_fields(self):
     data = {
         'words': [u'ä', u'ö']
     }
     self.assertEqual(
         encode(data, schema=IPrimary),
         ''
     )
Ejemplo n.º 6
0
 def test_encode_unicode_lines(self):
     data = {
         'words': [u'ä', u'ö']
     }
     self.assertEqual(
         encode(data, schema=IWords),
         'words%3Alist=%C3%A4&words%3Alist=%C3%B6'
     )
Ejemplo n.º 7
0
 def __str__(self):
     url = super(FragmentTileAbsoluteURL, self).__str__().split('?')[0]
     data = ITileDataManager(self.context).get()
     if data and 'fragment' in data:
         fragment = data['fragment']
         if fragment:
             if '?' in url:
                 url += '&fragment=' + fragment
             else:
                 url += '?fragment=' + fragment
             for schema_ in getFragmentSchemata(fragment):
                 url += '&' + encode(data, schema_)
     return url
Ejemplo n.º 8
0
 def test_encode_querystring_special(self):
     data = {
         'query': [{'i': 'Subject',
                    'o': 'plone.app.querystring.operation.selection.any',
                    'v': [u'äüö']}],
         'title': u'Hello World'
     }
     self.assertEqual(
         encode(data, schema=IQuerySchema),
         ('query.i%3Arecords=Subject&query.o%3A'
          'records=plone.app.querystring.operation.selection.any&'
          'query.v%3Alist%3Arecords=%C3%A4%C3%BC%C3%B6&title=Hello+World')
     )
Ejemplo n.º 9
0
 def __str__(self):
     url = super(FragmentTileAbsoluteURL, self).__str__().split('?')[0]
     data = ITileDataManager(self.context).get()
     if data and 'fragment' in data:
         fragment = data['fragment']
         if fragment:
             if '?' in url:
                 url += '&fragment=' + fragment
             else:
                 url += '?fragment=' + fragment
             for schema_ in getFragmentSchemata(fragment):
                 url += '&' + encode(data, schema_)
     return url
Ejemplo n.º 10
0
 def test_encode_querystring_special(self):
     data = {
         'query': [{
             'i': 'Subject',
             'o': 'plone.app.querystring.operation.selection.any',
             'v': [u'äüö']
         }],
         'title':
         u'Hello World'
     }
     self.assertEqual(
         encode(data, schema=IQuerySchema),
         ('query.i%3Arecords=Subject&query.o%3A'
          'records=plone.app.querystring.operation.selection.any&'
          'query.v%3Alist%3Arecords=%C3%A4%C3%BC%C3%B6&title=Hello+World'))
Ejemplo n.º 11
0
def addTile(tile, event):
    schema = getUtility(ITileType, name=tile.__name__).schema

    data = ILayout(tile.context).content
    root = etree.fromstring(data)
    
    head = root.xpath("html:head", namespaces=NAMESPACES)[0]

    rows = root.xpath(
        ("//html:div[contains(concat(' ', normalize-space(@class), ' '), "
         "' row ')]"), namespaces=NAMESPACES)
    for row in rows:
        columns = row.xpath(
            ("html:div[contains(concat(' ', normalize-space(@class), ' '), "
             "' cell ')]"), namespaces=NAMESPACES)
        for column in reversed(columns):

            link = etree.Element("link")
            link.set("rel", "tile")
            link.set("target", tile.id)
            link.set("href", u"%s/%s" % (tile.__name__, tile.id))

            head.append(link)

            div = etree.Element("div")
            div.set("id", tile.id)

            classname = getUtility(IIDNormalizer).normalize(tile.__name__)
            div.set("class", "tile %s" % classname)

            column.insert(0, div)

            if not IPersistentTile.providedBy(tile) and schema:
                link.set("href", link.get("href")
                         + u"?" + encode(tile.data, schema))
            try:
                ILayout(tile.context).content =\
                    etree.tostring(root, pretty_print=True)
            except AttributeError:
                # layout is read only
                pass
            break
        break
Ejemplo n.º 12
0
def modifyTile(tile, event):
    # updates transient tiles
    schema = getUtility(ITileType, name=tile.__name__).schema
    if not IPersistentTile.providedBy(tile) and schema:
        data = ILayout(tile.context).content
        root = etree.fromstring(data)

        link = root.xpath("//html:link[@target='%s']"\
            % tile.id, namespaces=NAMESPACES)
        href = u"%s/%s" % (tile.__name__, tile.id)\
            + u"?" + encode(tile.data, schema)

        if len(link) and link[0].get("href") != href:
            link[0].set("href", href)
            try:
                ILayout(tile.context).content =\
                    etree.tostring(root, pretty_print=True)
            except AttributeError:
                # layout is read only
                pass
Ejemplo n.º 13
0
 def test_skip_encoding_primary_fields(self):
     data = {'words': [u'ä', u'ö']}
     self.assertEqual(encode(data, schema=IPrimary), '')
Ejemplo n.º 14
0
 def test_encode_unicode_lines(self):
     data = {'words': [u'ä', u'ö']}
     self.assertEqual(encode(data, schema=IWords),
                      'words%3Alist=%C3%A4&words%3Alist=%C3%B6')