[Setup] Re: Extend user profile with SQLPAS + remember or CMF Plone override

Bruno Cacheira bcacheira at dcc.fc.up.pt
Thu May 22 15:46:21 UTC 2008


Raphael Ritz wrote:
> Bruno Cacheira wrote:
>> Yes I did and now I have figured out how to set it up as a product. I 
>> was missing a piece of inicialization code in the Install.py that 
>> I'll paste at the bottom of this message. Now I'm trying to figure 
>> out how to override author.pt (author.cpt?) and personalize form.
>
> Do you mean
>
>   CMFPlone/skins/plone_content/author.cpt
>
> and
>
>   CMFPlone/skins/plone_prefs/personalize_form.cpt ?
>
Exactly. Also, the MembershipTool overrides CMFPlone's getMemberInfo... 
bost CMFCore and CMFDefault's MembershipTool don't have this method 
directly (they seem to be "lower" layers for the member methods and 
such). If I'm saying something stupid, feel free to correct me.
> They are traditional old-style skin templates that you should be able
> to customize either TTW in ZMI or by placing them in a skin layer
> that you provide with your product (and register and install of course).
That's hat I though. I can costumize it TTW just fine (for instance, 
I've done that to expose the "harmless" authorinfo dictionary that's 
returned by MembershipTool), but I can't seem to be able to register it 
with just a registerdirectory of my custom skin directory, so I've tried 
mimicking what a plone 3 product (as created by paster's theme) does, 
also to no avail. I've later removed my TTW modified author.cpt, bacause 
I thought it could be a priority issue with the "custom" skin layer, but 
it wasn't that either. I've followed this link first
http://docs.neuroinf.de/programming-plone/main#1-32
because I thought that they were old-style skins (aparently I was 
right). In the example they override search_form.pt, but I might have 
missed something.

> And make sure to copy and adjust their metadata files (for the form
> controller) and eventually the form processing scripts as well.
>
I've looked at the metadata and I don't think I saw anything that should 
be changed (may have changed the namespace at most or something, don't 
remember). I had forgoten about the form processing scripts... have to 
find out what they are first. Well, at least I'm learning some new stuff :D

> HTH
>
>     Raphael
>
Thanks once again, best regards
    B Cacheira

>
>
>  By using
>> SQLPASPlugin, all the fields I declare in the select that 
>> LoadProperties uses is immediatly available to the PAS and as such, 
>> usable elsewere. The problem I had was that I wasn't registering it, 
>> because I had nothing on the Install (and there's a little piece of 
>> code that needs to be run once... I learned that now).
>>
>> So, now, all that's left is to override the personalise_form and 
>> author. I've tried the Zope2 way as described in Mysite and it didn't 
>> work, so now I'm following Martin Aspelli's book and using a paster 
>> theme template as guindance. Must be doing something wrong anyway, 
>> because I can't seem to be able to get it right. Next, I'll try to 
>> get the specialized queries I need to be automatically loaded to 
>> SQLPASPlugin so that I only have to install this product and have a 
>> fully modded user profile.
>>
>> After this, I'm gonna fully document this and make it available on 
>> the site... I don't think anyone whould have to go through this again 
>> :P Any help on how to override (c)pt files or the SQLPASPlugin config 
>> would be appeciated. If not, I'll just gladly continue to hammer away 
>> and try to shape this into something useful.
>>
>> PS: You know... plone seems to make it all harder than it should be 
>> and makes me feel stupid, but when you get something to work, it 
>> seems like a victory of sorts.
>>
>> Thanks for all your help so far.
>>
>> ------------------------- Install.py 
>> -----------------------------------------
>> from StringIO import StringIO
>>
>> import transaction
>> from Acquisition import aq_base
>> from Products.CMFCore.utils import getToolByName
>>
>> from ers_public.entidades.config import PROJECTNAME
>> from ers_public.entidades.MembershipTool import MembershipTool
>>
>> PRODUCT_DEPENDENCIES = ()
>>
>> EXTENSION_PROFILES = ()
>>
>> def install(self, reinstall=False):
>>    """Install a set of products (which themselves may either use 
>> Install.py
>>    or GenericSetup extension profiles for their configuration) and then
>>    install a set of extension profiles.
>>      One of the extension profiles we install is that of this 
>> product. This
>>    works because an Install.py installation script (such as this one) 
>> takes
>>    precedence over extension profiles for the same product in
>>    portal_quickinstaller.
>>      We do this because it is not possible to install other products 
>> during
>>    the execution of an extension profile (i.e. we cannot do this during
>>    the importVarious step for this profile).
>>    """
>>      portal_quickinstaller = getToolByName(self, 
>> 'portal_quickinstaller')
>>    portal_setup = getToolByName(self, 'portal_setup')
>>      for product in PRODUCT_DEPENDENCIES:
>>        if reinstall and 
>> portal_quickinstaller.isProductInstalled(product):
>>            portal_quickinstaller.reinstallProducts([product])
>>            transaction.savepoint()
>>        elif not portal_quickinstaller.isProductInstalled(product):
>>            portal_quickinstaller.installProduct(product)
>>            transaction.savepoint()
>>              for extension_id in EXTENSION_PROFILES:
>>        portal_setup.runAllImportStepsFromProfile('profile-%s' % 
>> extension_id, purge_old=False)
>>        product_name = extension_id.split(':')[0]
>>        portal_quickinstaller.notifyInstalled(product_name)
>>        transaction.savepoint()
>>
>>    out = StringIO()
>>    installMembershipTool(self,out)
>>    print >> out, "Installation completed."
>>    return out.getvalue()
>>
>> def _migrateTool(portal, toolid, name, attrs):
>>    orig=getToolByName(portal, toolid)
>>    portal.manage_delObjects(toolid)
>>    portal.manage_addProduct[PROJECTNAME].manage_addTool(name)
>>    tool = getToolByName(portal, toolid)
>>    #for attr in attrs:
>>    #    setattr(tool, attr, aq_base(getattr(aq_base(orig), attr)))
>>    return aq_base(orig)
>>
>> def installMembershipTool(self, out):
>>    portal = getToolByName(self, 'portal_url').getPortalObject()
>>    if getToolByName(self, 'portal_membership', None) is not None:
>>        _migrateTool(portal, 'portal_membership',
>>                     MembershipTool.meta_type,
>>                     ['_actions'])
>>        out.write('Migrated membership tool to AutoIMember Membership 
>> Tool')
>>    else:
>>        
>> portal.manage_addProduct[PROJECTNAME].manage_addTool(MembershipTool.meta_type, 
>> None)
>>        out.write('Added AutoIMember Membership Tool')
>>                      
>> Raphael Ritz wrote:
>>> bcacheira at dcc.fc.up.pt wrote:
>>>> Thanks for your help, but I still seem to be doing something wrong. 
>>>> The product
>>>> is listed on the additional products screen, but when i select it 
>>>> to install
>>>> it, it does nothing. It doesn't install, apparently, because when I 
>>>> look up the
>>>> transverse in the author info, it returns {'username': 'admin', 
>>>> 'description':
>>>> '', 'language': '', 'home_page': '', 'location': '', 'fullname': 
>>>> ''}, without
>>>> any additional fields.
>>>>
>>>> For instance, in this particular case, I'm trying to get aditional 
>>>> information
>>>> obtained by SQLPASPlugin, which I map via the col_mapping option in 
>>>> this
>>>> plugin. For what I understood, this should be enough to allow 
>>>> access to if from
>>>> another part of the site (in fact, I can do just that using 
>>>> getmemberproperties,
>>>> only I want to do it by extending the MembershipTool and 
>>>> registering fields as
>>>> "harmless"), without special permissions.
>>>>
>>>> I've stripped down the producto to a minimum and I basically have:
>>>
>>> What you show here is your customization of the member info returned
>>> but did you also add your custom properties in the member *data* tool?
>>> (can be done in ZMI or via GS)
>>>
>>> Raphael
>>>
>>>
>>>>
>>>> ------------------------------- 
>>>> MembershipTool.py--------------------------
>>>> from Globals import InitializeClass
>>>> from AccessControl import ClassSecurityInfo
>>>> from DateTime import DateTime
>>>> from Products.CMFCore.utils import getToolByName
>>>> from Products.CMFPlone.MembershipTool import MembershipTool as 
>>>> BaseTool
>>>>
>>>>
>>>> class MembershipTool(BaseTool):
>>>>
>>>>    meta_type = "ERS Membership Tool"
>>>>    title="ERS custom membership tool"
>>>>
>>>>    security = ClassSecurityInfo()
>>>>    plone_tool = 1
>>>>
>>>>
>>>>    security.declarePublic('getMemberInfo')
>>>>    def getMemberInfo(self, memberId=None):
>>>>        """
>>>>        Return 'harmless' Memberinfo of any member, such as Full name,
>>>>        Location, etc
>>>>        """
>>>>        if not memberId:
>>>>            member = self.getAuthenticatedMember()
>>>>        else:
>>>>            member = self.getMemberById(memberId)
>>>>
>>>>        if member is None:
>>>>            return None
>>>>
>>>>        memberinfo = { 'fullname'    : member.getProperty('fullname'),
>>>>                       'description' : 
>>>> member.getProperty('description'),
>>>>                       'location'    : member.getProperty('location'),
>>>>                       'language'    : member.getProperty('language'),
>>>>                       'home_page'   : member.getProperty('home_page'),
>>>>                       'applicationname'   :
>>>> member.getProperty('applicationname'),
>>>>                       'username'    : member.getUserName(),
>>>>                     }
>>>>
>>>>        return memberinfo
>>>>
>>>> MembershipTool.__doc__ = BaseTool.__doc__
>>>>
>>>> InitializeClass(MembershipTool)
>>>>
>>>>
>>>> ------------------------------- config.py--------------------------
>>>> from Products.CMFCore.permissions import AddPortalContent
>>>>
>>>> ADD_CONTENT_PERMISSION = AddPortalContent
>>>> PROJECTNAME = "ERSExtendMemberInfo"
>>>> SKINS_DIR = 'skins'
>>>>
>>>> GLOBALS = globals()
>>>>
>>>>
>>>> ------------------------------- __init__.py--------------------------
>>>>
>>>> from Products.CMFCore import utils
>>>> from Products.CMFCore.DirectoryView import registerDirectory
>>>> from Products.Archetypes.public import process_types, listTypes
>>>>
>>>> from config import SKINS_DIR, GLOBALS, PROJECTNAME
>>>>
>>>> import MembershipTool
>>>>
>>>> registerDirectory(SKINS_DIR, GLOBALS)
>>>>
>>>>
>>>> tools = (MembershipTool.MembershipTool,)
>>>>
>>>>
>>>> def initialize(context):
>>>>    content_types, constructors, ftis = process_types(
>>>>        listTypes(PROJECTNAME),
>>>>        PROJECTNAME)
>>>>
>>>>    utils.ToolInit(PROJECTNAME + ' Tool',
>>>>                   tools=tools,
>>>>                   product_name=PROJECTNAME,
>>>>                   icon="tool.gif",
>>>>                   ).initialize(context)
>>>>
>>>>
>>>> Thanks for your help, btw ;D
>>>>
>>>> ----------------------------------------------------------------
>>>> Departamento de Ciencia de Computadores
>>>> Faculdade de Ciencias da Universidade do Porto
>>>> http://www.dcc.fc.up.pt/
>>>>
>>>>
>>>>
>>>
>>>
>>> _______________________________________________
>>> Setup mailing list
>>> Setup at lists.plone.org
>>> http://lists.plone.org/mailman/listinfo/setup
>>
>>
>
>
> _______________________________________________
> Setup mailing list
> Setup at lists.plone.org
> http://lists.plone.org/mailman/listinfo/setup




More information about the Setup mailing list