Knowing the Zope database is configured read-only
Hello, A CMF/CPS site I work on needs to switch to read-only-database mode sometimes, to be only viewed but not edited. The problem is when being in this mode, I would like to hide some actions or links pointing to methods adding or editing content. Is there a simple way to know from code (zpt, script, Condition of actions) that the main database has been set read-only ? Thanks in advance for hints, -- Damien
Damien Wyart wrote at 2005-2-17 17:35 +0100:
... Is there a simple way to know from code (zpt, script, Condition of actions) that the main database has been set read-only ?
I do not know of a simple way -- but a complex one: If "obj" is a persistent object, then "obj._p_jar" is its ZODB connection (that loaded it from the ZODB). If "conn" is a ZODB connection, then "conn._storage" is its ZODB storage. If "storage" is a storage, then, usually, you can check the "_is_read_only" attribute to determine writability. As you see from the "_" prefix in attribute, this method requires trusted code (e.g. an External Method). -- Dieter
[Damien Wyart]
... Is there a simple way to know from code (zpt, script, Condition of actions) that the main database has been set read-only ?
[Dieter Maurer]
I do not know of a simple way -- but a complex one:
If "obj" is a persistent object, then "obj._p_jar" is its ZODB connection (that loaded it from the ZODB).
If "conn" is a ZODB connection, then "conn._storage" is its ZODB storage.
If "storage" is a storage, then, usually, you can check the "_is_read_only" attribute to determine writability.
As you see from the "_" prefix in attribute, this method requires trusted code (e.g. an External Method).
FWIW, both storages and connections support the isReadOnly() method; you don't have to (and shouldn't) muck around looking at private attributes like _storage or _is_read_only, and in the case of a ZEO client connection _is_read_only alone doesn't tell the full story (but isReadOnly() does).
participants (3)
-
Damien Wyart -
Dieter Maurer -
Tim Peters