Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: CMF

Custom factories?

 

 

Zope cmf RSS feed   Index | Next | Previous | View Threaded


charlie at begeistert

Mar 3, 2008, 1:48 PM

Post #1 of 5 (381 views)
Permalink
Custom factories?

Hi,

I've been working on some very lightweight content types that differ
minimally from each other so I'd like to use attributes rather than
different classes. I've come across a couple of problems while working
on this: if I put the attributes into the factory I need to make my
basic object into a callable because it gets called when the factory
gets registered.

Currently I have something like this:

class SpecialDocument:
def __init__(self, **kw):
pass

def __call__(self, text_type=None):
self.text_type = text_type

HTMLDocFactory = Factory(SpecialDocument(text_type='text/html')
PlainTextDocFactory = Factory(SpecialDocument(text_type='text/plain')

This is extended with additional registrations of the content class
with additional meta_types.

This seems to be the most minimal configuration I can use and seems
reasonably Pythonic but I'm worried about unexpected side effects and
whether there is a different way of doing this, ie. using local
utilities as these content types are going to be site specific. I was
going to try this approach (similar to the KitchenTools example in
Philip's book) but wasn't sure about some of the other things I was
going to need.

Comments much appreciated.

On a personal note: over this last month, thanks to the list but also
to Philip's and Martin's books I've really started to understand and
appreciate the Zope 3 approach to stuff: it has a great deal of
elegance even if it takes a while to get used to!

Charlie
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


y.2008 at wcm-solutions

Mar 3, 2008, 2:45 PM

Post #2 of 5 (353 views)
Permalink
Re: Custom factories? [In reply to]

Hi Charlie!


Charlie Clark wrote:
> I've been working on some very lightweight content types that differ
> minimally from each other so I'd like to use attributes rather than
> different classes. I've come across a couple of problems while working
> on this: if I put the attributes into the factory I need to make my
> basic object into a callable because it gets called when the factory
> gets registered.
>
> Currently I have something like this:
>
> class SpecialDocument:
> def __init__(self, **kw):
> pass
>
> def __call__(self, text_type=None):
> self.text_type = text_type
>
> HTMLDocFactory = Factory(SpecialDocument(text_type='text/html')
> PlainTextDocFactory = Factory(SpecialDocument(text_type='text/plain')
>
> This is extended with additional registrations of the content class with
> additional meta_types.

Do you mean you use different meta types for one class? There should not
be a need for that. One meta type can be used for several portal types.

I attached a custom factory for plain CMF documents that sets the
initial text format to 'html'. Maybe that code helps you.

Cheers,

Yuppie



-----------------------------------------------------

from zope.interface import implementedBy
from zope.interface import implements
from zope.component.interfaces import IFactory
from Products.CMFDefault.Document import Document


class _HTMLDocumentFactory(object):

"""Creates an HTML document.
"""

implements(IFactory)
title = u'HTML document'
description = u'An HTML document.'

def __call__(self, *args, **kw):
item = Document(*args, **kw)

item.setFormat('html')

return item

def getInterfaces(self):
return implementedBy(Document)

HTMLDocumentFactory = _HTMLDocumentFactory()

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Mar 4, 2008, 5:49 AM

Post #3 of 5 (350 views)
Permalink
Re: Re: Custom factories? [In reply to]

Am 03.03.2008 um 23:45 schrieb yuppie:

> Do you mean you use different meta types for one class? There should
> not be a need for that. One meta type can be used for several portal
> types.

That's good to hear - how do I register different portal types? I've
just been experimenting with stuff and found I needed to have
different meta types for them all to show up in the "add" view for
folders.

> I attached a custom factory for plain CMF documents that sets the
> initial text format to 'html'. Maybe that code helps you.


Yes, I'd thought of doing this but was hoping for a short cut by using
**args or something similar. Still having a collection of factories is
less copy & paste than a collection of factories and classes - this is
really what I'm trying to avoid.

Charlie
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


y.2008 at wcm-solutions

Mar 4, 2008, 8:13 AM

Post #4 of 5 (346 views)
Permalink
Re: Custom factories? [In reply to]

Charlie Clark wrote:
>
> Am 03.03.2008 um 23:45 schrieb yuppie:
>
>> Do you mean you use different meta types for one class? There should
>> not be a need for that. One meta type can be used for several portal
>> types.
>
> That's good to hear - how do I register different portal types? I've
> just been experimenting with stuff and found I needed to have different
> meta types for them all to show up in the "add" view for folders.

There is no new way to register them. Portal types are still persistent
sub-objects of the types tool. You can import them from a GenericSetup
profile or add them TTW.

'Product meta type' has to be the meta type of the class created by
'Product factory'. If you have the permission to add that class, you
should be able to add all portal types based on that class.

HTH, Yuppie

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


charlie at begeistert

Mar 4, 2008, 10:36 AM

Post #5 of 5 (340 views)
Permalink
Re: Re: Custom factories? [In reply to]

Am 04.03.2008 um 17:13 schrieb yuppie:

> There is no new way to register them. Portal types are still
> persistent sub-objects of the types tool. You can import them from a
> GenericSetup profile or add them TTW.

Of course, me just not seeing the wood for the trees!

> 'Product meta type' has to be the meta type of the class created by
> 'Product factory'. If you have the permission to add that class, you
> should be able to add all portal types based on that class.

Yes, somehow got confused between the portal_type which is the "Title"
of the portal_type and it's metatype.

Charlie
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests

Zope cmf RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.