[Zope-dev] Repost to zope-dev: Best way to do "links"

Bjorn Stabell bjorn@exoweb.net
Wed, 14 Nov 2001 17:35:54 +0800


Two comments.  One with regards to solving the original problem, one
with regards to links.


SEVERAL TEMPLATES FOR ONE CONTENT TYPE

With the CMF you have another level of typing of objects available:
portal_type (dynamic type).  A meta_type can have many corresponding
portal_types, e.g., a generic MyDocument class (implemented in a Python
product) can support many logical types who only varies in their usage
and skin.  The CMF lets you set the portal_type at creation time (you're
basically creating a portal_type object, implicitly based on some kind
of meta_type object).

What I'm doing now, and it works quite nicely, is to enable users to
change the portal_type at run-time.  In the Metadata edit view for an
object, I scan the available portal_types for the given meta_type and
give the user the option to select one of them as the "current dynamic
type (portal_type).  The CMF's portal_skin tool does the rest of
selecting the correct skins to use (based on the portal_type attribute).


LINKS IN THE OODB

I've used Shane's suggestion, and it works most of the time, but if you
ZSync your objects to another server, you'll get two copies instead of
one object and one link...  Have a look at the PortalHole product
release recently; it addresses linking.

Another way to do links involves storing the path to the other object
(which is how PortalHole does it), or you can create a portal-wide
unqiue id (someone suggested this) which you can index in the
portal_catalog.  Now all you have to do is store the link, and the link
won't break if the objects move with respect to each other (=3Dthe path
changes).

An improvement on this is to create a Mixin that implements logic to
setup and break these links; this way to you can notify the other object
when you're deleted that it should also remove the link.  Otherwise
you'll have broken links when the other object is deleted.

You can also just allow broken links and fix them with regular sweeps
across all content objects checking for and removing broken links
(sort-of like garbage collection).

There should really be a FAQ about how to do this.


We've got this kind of Mixin already, but it comes with a few bugs.  Let
me know if you want/need it. :)


Regards,
--=20
Bjorn

> -----Original Message-----
> From: Oliver Bleutgen [mailto:myzope@gmx.net]
> Posted At: Wednesday, November 14, 2001 03:54
> Posted To: Zope Developer
> Conversation: [Zope-dev] Repost to zope-dev: Best way to do "links"
> Subject: [Zope-dev] Repost to zope-dev: Best way to do "links"
>=20
>=20
> Hi reposting to zope-dev because the zope-list didn't yield
> any answer (although it should belong there, I think).
>=20
> I am unsure how to achieve the following in a product:
>=20
> I have a folder with templates which shall be used to render articles.
> This folder will be the central repository of templates for=20
> all articles=20
> which find it in their acquisition path.
> Now, I want be able to dynamically assign (and change) templates for a
> given article, and if I edit one template it should reflect in all
> articles which are configured to use that template.
>=20
> In http://lists.zope.org/pipermail/zope-dev/2001-May/011187.html Shane
> Hathaway  describe hardlinks, which seem to do what I need.
>=20
> i.e. I then just do
> t =3D template_folder.one_template
> self.template =3D t
>=20
> I looked at how ZSQL-methods solve that problem (usage of
> SQLConnections), and as far as I can see ZSQL-methods just=20
> store the id
> of the ZSQL connection and use that everytime they need to=20
> access the DB.
>=20
> Is that right and if so, why is it done that way?
> Doesn't give that a performance hit?
>=20
> And the last one:
>=20
> Will the above described method still allow import/export of these=20
> instances?
>=20
> cheers,
> oliver
>=20
>=20
>=20
>=20
>=20
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists -=20
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope )