I've created two dexterity types called services and appointment
class IService(model.Schema):
...
professional = schema.TextLine(
title=_(u"label_professional", default=u"Professional"),
description=_(u"help_professional", default=u"Enter professional name"),
required=True,
)
class IAppointment(model.Schema):
...
professional = schema.Choice(
title=_(u"label_professional", default=u"Professional"),
description=_(u"help_professional", default=u"Choose a professional"),
source=Professionals(),
required=True,
)
service = schema.Choice(
title=_(u"label_service", default=u"Service"),
description=_(u"help_service", default=u"Choose a service you want an appoint"),
source=Services(),
required=True,
)
Appointment uses two classes for sources: Professionals and Services.
class Professionals(object):
implements(IContextSourceBinder)
def __call__(self, object):
user_list = []
users = api.user.get_users()
for user in users:
if user.getUser().getProperty('role') == u"P":
user_list.append(SimpleTerm(
value=user.getUser().getProperty('fullname'),
title=user.getUser().getProperty('fullname')))
return SimpleVocabulary(user_list)
class Services(object):
implements(IContextSourceBinder)
def __call__(self, object):
# get the tool
catalog = api.portal.get_tool(name='portal_catalog')
# execute a search
results = catalog(
portal_type="service",
review_state="published",
sort_on='sortable_title',
sort_order='ascending')
# examine the results
for brain in results:
obj = brain.getObject()
results.append(SimpleTerm(
value=obj.Title(),
title=obj.Title())
)
return SimpleVocabulary(results)
Professional and Services list all itens, but for services I'd like to create a source class that show only the services that the chosen professional offers (source class filtered by professional value). How can I do that?