Allow custom address in email selection #38844
This commit is contained in:
parent
2dfd8242d8
commit
884ec72de0
1
setup.py
1
setup.py
|
@ -44,6 +44,7 @@ setup(name='collective.dms.basecontent',
|
||||||
'setuptools',
|
'setuptools',
|
||||||
'five.grok',
|
'five.grok',
|
||||||
'collective.documentviewer',
|
'collective.documentviewer',
|
||||||
|
'collective.select2',
|
||||||
'plone.api',
|
'plone.api',
|
||||||
'plone.app.dexterity',
|
'plone.app.dexterity',
|
||||||
'plone.namedfile',
|
'plone.namedfile',
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
xmlns:grok="http://namespaces.zope.org/grok"
|
xmlns:grok="http://namespaces.zope.org/grok"
|
||||||
xmlns:i18n="http://namespaces.zope.org/i18n"
|
xmlns:i18n="http://namespaces.zope.org/i18n"
|
||||||
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
|
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
|
||||||
|
xmlns:browser="http://namespaces.zope.org/browser"
|
||||||
i18n_domain="collective.dms.basecontent">
|
i18n_domain="collective.dms.basecontent">
|
||||||
|
|
||||||
<include package="five.grok" />
|
<include package="five.grok" />
|
||||||
|
@ -68,4 +69,14 @@
|
||||||
for=".dmsfile.IDmsFile"
|
for=".dmsfile.IDmsFile"
|
||||||
factory=".dmsfile.DmsFileWriteFile"/>
|
factory=".dmsfile.DmsFileWriteFile"/>
|
||||||
|
|
||||||
|
|
||||||
|
<browser:page
|
||||||
|
for="plone.app.layout.navigation.interfaces.INavigationRoot"
|
||||||
|
name="select2-ldap-emails-search"
|
||||||
|
class=".widget.LDAPEmailsSearch"
|
||||||
|
permission="cmf.SetOwnPassword"
|
||||||
|
layer="pfwbged.policy.interfaces.IPfwbgedPolicyLayer"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import zope.component
|
|
||||||
|
|
||||||
from zope.schema.interfaces import ISource, IContextSourceBinder
|
|
||||||
from zope.interface import implementer
|
|
||||||
import z3c.form.interfaces
|
import z3c.form.interfaces
|
||||||
|
import zope.component
|
||||||
from z3c.form import interfaces, util, value
|
from collective.select2.browser import BaseSearch
|
||||||
|
|
||||||
from collective.z3cform.chosen.widget import AjaxChosenMultiSelectionWidget
|
from collective.z3cform.chosen.widget import AjaxChosenMultiSelectionWidget
|
||||||
|
from z3c.form import interfaces
|
||||||
|
from zope.component import getUtility
|
||||||
|
from zope.interface import implementer
|
||||||
|
from zope.schema.interfaces import IVocabularyFactory
|
||||||
|
|
||||||
|
|
||||||
class CustomAjaxChosenMultiSelectionWidget(AjaxChosenMultiSelectionWidget):
|
class CustomAjaxChosenMultiSelectionWidget(AjaxChosenMultiSelectionWidget):
|
||||||
@property
|
@property
|
||||||
|
@ -25,6 +25,7 @@ class CustomAjaxChosenMultiSelectionWidget(AjaxChosenMultiSelectionWidget):
|
||||||
source.extra_default_values = adapter.get()
|
source.extra_default_values = adapter.get()
|
||||||
return source
|
return source
|
||||||
|
|
||||||
|
|
||||||
@implementer(z3c.form.interfaces.IFieldWidget)
|
@implementer(z3c.form.interfaces.IFieldWidget)
|
||||||
def AjaxChosenMultiFieldWidget(field, request):
|
def AjaxChosenMultiFieldWidget(field, request):
|
||||||
widget = z3c.form.widget.FieldWidget(field,
|
widget = z3c.form.widget.FieldWidget(field,
|
||||||
|
@ -32,3 +33,30 @@ def AjaxChosenMultiFieldWidget(field, request):
|
||||||
widget.populate_select = True
|
widget.populate_select = True
|
||||||
widget.ignoreMissing = True
|
widget.ignoreMissing = True
|
||||||
return widget
|
return widget
|
||||||
|
|
||||||
|
|
||||||
|
class LDAPEmailsSearch(BaseSearch):
|
||||||
|
"""Search for LDAP emails, allow dynamic option selection"""
|
||||||
|
def results(self, search_term, add_terms=False):
|
||||||
|
factory = getUtility(
|
||||||
|
IVocabularyFactory,
|
||||||
|
'collective.dms.basecontent.ldap_emails',
|
||||||
|
)
|
||||||
|
vocabulary = factory(self.context)
|
||||||
|
found = False
|
||||||
|
|
||||||
|
for term in vocabulary:
|
||||||
|
if search_term in term.token:
|
||||||
|
found = True
|
||||||
|
yield {
|
||||||
|
"text": term.value,
|
||||||
|
"id": term.value,
|
||||||
|
}
|
||||||
|
|
||||||
|
# make the search term a selectable value
|
||||||
|
# if it doesn't match any existing email
|
||||||
|
if add_terms and not found:
|
||||||
|
yield {
|
||||||
|
"text": search_term,
|
||||||
|
"id": search_term
|
||||||
|
}
|
||||||
|
|
Reference in New Issue