Ignore:
Timestamp:
Sep 20, 2006 8:05:24 PM (12 years ago)
Author:
hazmat
Message:

add a flavor aware content for configuration of flavors through at schemas

Location:
Products.ContentFlavors/trunk
Files:
4 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • Products.ContentFlavors/trunk/configure.zcml

    r1664 r1668  
    33 
    44 <include package="zope.app.annotation"/> 
     5 <include package=".browser"/> 
     6 
     7 <adapter  
     8    for=".interfaces.IFlavorAware" 
     9    provides=".interfaces.IFlavorSchemaProvider" 
     10    factory=".schema.FlavorSchemaComposer"/> 
     11 
     12 <adapter  
     13    for=".interfaces.IFlavorAware" 
     14    provides=".interfaces.IFlavorProvider" 
     15    factory=".provider.FlavorProvider"/> 
    516 
    617</configure> 
  • Products.ContentFlavors/trunk/provider.py

    r1667 r1668  
    3232from zope import component 
    3333from zope.interface import implements 
    34 from interfaces import IFlavorProvider 
     34from interfaces import IFlavorProvider, IFlavor 
    3535from persistent.list import PersistentList 
    3636 
     
    4343    def __init__(self, context ): 
    4444        self.context = context 
    45         annotation = IAnnotation( context ) 
     45        annotation = IAnnotations( context ) 
    4646        if annotation.get( self.ANNOTATION_KEY ) is None: 
    4747            annotation[ self.ANNOTATION_KEY ] = PersistentList() 
     
    5757     
    5858    def getFlavorNames( self ): 
    59         return self._flavors 
     59        return tuple(self._flavors) 
    6060     
    6161    def setFlavorNames( self, flavors ): 
    62         flavors = list(  set( flavors ) + set( self._flavors ) ) 
     62        flavors = list(  set( flavors ).union( set( self._flavors )) ) 
    6363        # verify each exists and is reachable from our location. 
    6464        for name in flavors: 
    65             flavor = component.getAdapter( self, IFlavor, name=name ) 
     65            flavor = component.getAdapter( self.context, IFlavor, name=name ) 
    6666        self._flavors[:] = flavors 
    6767 
     
    7777     
    7878    def getAvailableFlavors( self ): 
    79         return [adapter for name, adapter in component.getAdapters( self.context, IFlavor ) \ 
    80                 if name not in self._flavors ] 
     79        return [adapter for name, adapter in component.getAdapters( (self.context,), IFlavor )]# \ 
     80        #    if name not in self._flavors ] 
     81 
    8182 
    8283    available_flavors = property( getAvailableFlavors ) 
  • Products.ContentFlavors/trunk/readme.txt

    r1664 r1668  
    22Content Flavors 
    33---------------- 
     4 
    45What are flavors? 
     6----------------- 
    57 
    68 are bits of behavior and schema that we can add to content. 
    79 we can gain additional access to icons, actions, views, adapters, 
    8  and at schemas via adding a flavor to a piece of content. 
     10 and at schemas via adding a flavor to a piece of content.  
    911 
    10 How do i use flavors with my content class 
     12 A flavor is composed of a number of optional parts based on 
     13 requirements, archetypes schemas to compose, marker interfaces to 
     14 apply, etc. see the zcml section, for a complete definition. 
    1115 
    12 # the content needs to implement the interface IFlavorAware, if it does 
    13 # a flavors tab will appear for the content. on this content tab  
    14 # users can add, remove, and order flavors. 
     16Using Flavors 
     17------------- 
    1518 
    16  for archetypes schema integration a mixin is required to perform 
    17  the schema lookup and icon delegation. 
     19 Plone content that wants to fully utilize flavors, should mixin the 
     20 minimal Products.ContentFlavors.aware.FlavorAware class. This 
     21 provides the schema lookup/composition and icon delegation. 
     22  
     23 Additionally, a default view for modifying flavors is registered for  
     24 IFlavorAware which the mixin provides.  
     25 
     26 
     27Installation 
     28------------ 
     29 
     30Content Flavors bridges a number of frameworks, and requires a 
     31specific version to operate. Its tested on and requires 
     32 
     33 - Plone 2.5 
     34 - Zope 2.9.4 
     35 - Five 1.4 
     36 - CMFonFive 1.3.3  
     37 
    1838 
    1939System Properties 
     40----------------- 
    2041 
    2142 - a flavor is defined in zcml, it has a name, icon, description,  
     
    5778 
    5879 
    59  Required Attributes 
     80Required Attributes 
     81=================== 
    6082 
    6183 - name .. a qualified name to the interface, this is used in adapter 
     
    6486 - title .. a user displayed string for applying the flavor. 
    6587 
    66  Optional Attributes 
     88Optional Attributes 
     89=================== 
    6790 
    6891 - description .. an additional user information string describing the flavor. 
  • Products.ContentFlavors/trunk/zcml.py

    r1667 r1668  
    2424""" 
    2525 
     26from zope import component 
    2627from zope import interface 
    2728from zope import schema 
     
    8283    """ generate an adapter factory on the fly with specified settings 
    8384    """ 
    84     class_prefix = "".join( [n.upper() for n in name.split('.') if n] ) 
     85    class_prefix = "".join( [n.title() for n in name.split('.') if n] ) 
    8586     
    8687    flavor = type( "%sFlavor"%class_prefix, 
    8788                   (Flavor,), 
    88                    d = dict( name = name, 
    89                              title = title, 
    90                              description = description, 
    91                              icon = icon,                         
    92                              archetype_schema = archetype_schema, 
    93                              marker = marker ) 
     89                   dict( name = name, 
     90                         title = title, 
     91                         description = description, 
     92                         icon = icon,                         
     93                         archetype_schema = archetype_schema, 
     94                         marker = marker ) 
    9495                  ) 
    9596    return flavor 
     
    108109    if not adapts: 
    109110        adapts = (IFlavorAware,) 
    110          
     111 
    111112    # register adapter from (IFlavorAware, name) -> adapter 
    112113    component.provideAdapter( adapter, adapts=adapts, provides=IFlavor, name=name ) 
     
    129130    context.action( 
    130131        discriminator=('flavor', name), 
    131         callable=createFlavor, 
     132        callable=setupFlavor, 
    132133        args=( name, title, description, icon, archetype_schema, adapter, marker, for_ ), 
    133134        ) 
Note: See TracChangeset for help on using the changeset viewer.