Re: Traversal modifizieren

Andreas Jung <[email protected]>
Newsgroups gmane.comp.web.zope.german
Organization ZOPYX Ltd & Co. KG
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vielleicht hilft das als Inspiration:

  6     <!-- set authentication cookie timeout to N seconds -->
  7     <adapter provides="zope.traversing.interfaces.ITraversable"
  8
factory=".session_timeout_adapter.AuthCookieRefreshAndExpiration"
  9              />


Der Traversaladapter hängt sich ins Traversal und modifiziert
das __ac Cookie um einen Sessiontimeout zu realisieren.

....

class AuthCookieRefreshAndExpiration(object):
    """ This traversal adapter will intercept traversal steps
        and refresh the __ac once per traversal.  An expiration
        date will be added to the __ac cookie. The traverser
        is registered for all Archetypes-based content objects.
    """

    implements(ITraversable)
    adapts(IBaseObject)

    def __init__(self, subject):
        self._subject = subject

    def traverse(self, name, furtherPath):
        #print 'traverse()'
        try:
            foo = self._subject.request.__ac_refreshed
            # nothing to do
            raise TraversalError(self._subject, name)
        except AttributeError:
            pass

        request = getattr(self._subject, 'REQUEST')
        if request is None:
            raise TraversalError(self._subject, name)

        cookies = request.cookies
        if '__ac' in cookies:
            if not hasattr(request, '__ac_refreshed'):
                __ac = cookies['__ac']
                expires = datetime.utcnow() +
timedelta(seconds=TIMEOUT_AFTER)
                expires = expires.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
                # determine relative path of plone site
                plone = getUtility(ISiteRoot)
                plone_path = '/' + plone.absolute_url(1)
                request.response.setCookie('__ac', __ac,
expires=expires, path=plone_path)
                request.__ac_refreshed = True

Andreas


Peter Zechmeister wrote:
> Hallo,
> 
> ich möchte unserer ZMS-Site so etwas wie "Perma-Links" verpassen. Dazu
> würde ich Objekte mit ihren Ids und Pfaden indizieren. Wir stellen
> sicher, dass Ids eindeutig bleiben. Jedoch können sich Pfade durch
> verschieben von Objekten ändern. Anhand der Id sollten sie jedoch im
> Baum dann wieder gefunden werden.
> 
> Wenn nun ein Request mit einem nicht mehr existierenden Pfad kommt, wird
> der letzte Schritt im Pfad (= angefragtes Objekt) als Id genommen, im
> Index gesucht und auf den neuen Pfad redirected.
> 
> Allerdings will ich Zope/ZMS daran hindern, 404 zu machen. Das könnte
> man doch mit __before_publishing_traverse__ abfangen? Prüfen, ob der
> Pfad existiert. Falls nicht wird im Index gesucht und umgeleitet oder -
> falls dort auch nichts gefunden wird, erst dann ein 404 gemacht. Dazu
> muss man aber in das Traversal eingreifen.
> 
> Hier http://wiki.zope.org/zope2/ZPublisher werden diese Hooks kurz
> erklärt ("[...]However, the request object also provides methods that
> change the path segments still to be traversed[...]"), gibts dazu
> irgendwo eine genauere Anleitung?
> 
> Grü
> PeterZ 
> 
> 
> 
> _______________________________________________
> zope mailing list
> [email protected]
> https://mail.dzug.org/mailman/listinfo/zope


- -- 
ZOPYX Limited           | zopyx group
Charlottenstr. 37/1     | The full-service network for Zope & Plone
D-72070 Tübingen        | Produce & Publish
www.zopyx.com           | www.produce-and-publish.com
- ------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQGUBAEBAgAGBQJN3O5wAAoJEADcfz7u4AZjzTULwIOrwakGLugHb4r9ts48N4zw
e9fKuoQuT9rDRHGBKngsSnzXXgktdhjCKIh4RzzLK3+O/2Xz2ebilBHll6lxYmpP
sR0n9rIhdyIV4q565sTTzSIy8vgU+GKLEBdeHR/5iM/stFrbyBCUOi+43dgoksZE
/Ms6wz/pwkF4w8+7snGfWrU0+PPt7Sb+REYOMNz/08dwweIaHpAssn+UoRt8A30C
LfO818RLxQjcQ3wKxdNceQQt7/hJ569C0VtmuWTcHhr7EspdGJRhast8DW/za31W
tUfr31YLZ67Lq/JLQXs4++WuUW8QAdSknTJbMXn9dqNTadunca6yw550G/5Hy4pZ
b9Om+pKOHD4e4tWV8X1HmvuKhAgX5CsVvq0vu8NjZ7Mk1ji0mHa8A0gBVUc1CaQa
SE+GEuv1MPfNvRvwBtgDmGQqbOWxD+5wF1O2sCblbNeGt6yfoS/MO2ECQudbQpKP
1RC3CvmUUeH+yYHDsT/HDW1Nu9J0t84=
=zsGH
-----END PGP SIGNATURE-----



_______________________________________________
zope mailing list
[email protected]
https://mail.dzug.org/mailman/listinfo/zope
lists.vcf (text/x-vcard, 316 B)
begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[email protected]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.