Skip to content

Commit

Permalink
port control panel to z3c.form
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Sep 7, 2015
1 parent d911ce5 commit 6e33ccc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 283 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'plone.app.layout',
'plone.app.testing',
'plone.app.vocabularies',
'plone.api',
'plone.browserlayer',
'plone.indexer',
'setuptools',
Expand Down
289 changes: 9 additions & 280 deletions src/collective/solr/configlet.py
Original file line number Diff line number Diff line change
@@ -1,293 +1,22 @@
# -*- coding: utf-8 -*-
from zope.component import adapts, queryUtility
from zope.formlib.form import FormFields
from zope.interface import implements
from Products.CMFDefault.formlib.schema import SchemaAdapterBase
from Products.CMFPlone.interfaces import IPloneSiteRoot
from plone.app.controlpanel.form import ControlPanelForm

from collective.solr.interfaces import ISolrSchema, _
from collective.solr.interfaces import ISolrConnectionConfig
from collective.solr.interfaces import ISolrConnectionManager


class SolrControlPanelAdapter(SchemaAdapterBase):
adapts(IPloneSiteRoot)
implements(ISolrSchema)

def reset(self):
manager = queryUtility(ISolrConnectionManager)
if manager is not None:
manager.closeConnection()

def getActive(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'active', '')

def setActive(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.active = value
self.reset()

active = property(getActive, setActive)

def getHost(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'host', '')

def setHost(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.host = value
self.reset()

host = property(getHost, setHost)

def getPort(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'port', '')

def setPort(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.port = value
self.reset()

port = property(getPort, setPort)

def getBase(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'base', '')

def setBase(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.base = value

base = property(getBase, setBase)

def getAsync(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'async', '')

def setAsync(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.async = value

async = property(getAsync, setAsync)

def getAutoCommit(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'auto_commit', '')

def setAutoCommit(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.auto_commit = value

auto_commit = property(getAutoCommit, setAutoCommit)

def getCommitWithin(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'commit_within', '')

def setCommitWithin(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.commit_within = value

commit_within = property(getCommitWithin, setCommitWithin)

def getIndexTimeout(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'index_timeout', '')

def setIndexTimeout(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.index_timeout = value

index_timeout = property(getIndexTimeout, setIndexTimeout)

def getSearchTimeout(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'search_timeout', '')

def setSearchTimeout(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.search_timeout = value

search_timeout = property(getSearchTimeout, setSearchTimeout)

def getMaxResults(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'max_results', '')

def setMaxResults(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.max_results = value

max_results = property(getMaxResults, setMaxResults)

def getRequiredParameters(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'required', '')
from plone.app.registry.browser import controlpanel

def setRequiredParameters(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.required = value

required = property(getRequiredParameters, setRequiredParameters)

def getSearchPattern(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'search_pattern', '')

def setSearchPattern(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.search_pattern = value.encode('utf-8')

search_pattern = property(getSearchPattern, setSearchPattern)

def getDefaultFacets(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'facets', '')

def setDefaultFacets(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.facets = value

facets = property(getDefaultFacets, setDefaultFacets)

def getFilterQueryParameters(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'filter_queries', '')

def setFilterQueryParameters(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.filter_queries = value

filter_queries = property(
getFilterQueryParameters, setFilterQueryParameters)

def getSlowQueryThreshold(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'slow_query_threshold', '')

def setSlowQueryThreshold(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.slow_query_threshold = value

slow_query_threshold = property(
getSlowQueryThreshold, setSlowQueryThreshold)

def getEffectiveSteps(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'effective_steps', '')

def setEffectiveSteps(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.effective_steps = value

effective_steps = property(getEffectiveSteps, setEffectiveSteps)

def getExcludeUser(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'exclude_user', '')

def setExcludeUser(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.exclude_user = value

exclude_user = property(getExcludeUser, setExcludeUser)

def getHighlightFields(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'highlight_fields', '')

def setHighlightFields(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.highlight_fields = value

highlight_fields = property(getHighlightFields, setHighlightFields)

def getHighlightFormatterPre(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'highlight_formatter_pre', '')

def setHighlightFormatterPre(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.highlight_formatter_pre = value

highlight_formatter_pre = property(
getHighlightFormatterPre, setHighlightFormatterPre)

def getHighlightFormatterPost(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'highlight_formatter_post', '')

def setHighlightFormatterPost(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.highlight_formatter_post = value

highlight_formatter_post = property(
getHighlightFormatterPost, setHighlightFormatterPost)

def getHighlightFragsize(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'highlight_fragsize', '')

def setHighlightFragsize(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.highlight_fragsize = value

highlight_fragsize = property(getHighlightFragsize, setHighlightFragsize)
from collective.solr.interfaces import ISolrSchema, _

def getFieldList(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'field_list', '')

def setFieldList(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.field_list = value

field_list = property(getFieldList, setFieldList)

def getLevenshteinDistance(self):
util = queryUtility(ISolrConnectionConfig)
return getattr(util, 'levenshtein_distance', '')

def setLevenshteinDistance(self, value):
util = queryUtility(ISolrConnectionConfig)
if util is not None:
util.levenshtein_distance = value
class SolrControlPanelForm(controlpanel.RegistryEditForm):

levenshtein_distance = property(
getLevenshteinDistance, setLevenshteinDistance)
id = "SolrControlPanel"
label = _('label_solr_settings', default='Solr settings')
schema = ISolrSchema
schema_prefix = "collective.solr"


class SolrControlPanel(ControlPanelForm):
class SolrControlPanel(controlpanel.ControlPanelFormWrapper):

form_fields = FormFields(ISolrSchema)
form = SolrControlPanelForm

label = _('label_solr_settings', default='Solr settings')
description = _(
'help_solr_settings',
default='Settings to enable and configure Solr integration.')
form_name = _('label_solr_settings', default='Solr settings')
2 changes: 0 additions & 2 deletions src/collective/solr/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
factory="plone.app.layout.icons.icons.CatalogBrainContentIcon"
provides="plone.app.layout.icons.interfaces.IContentIcon" />

<adapter factory=".configlet.SolrControlPanelAdapter" />

<browser:page
name="solr-controlpanel"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
Expand Down
4 changes: 3 additions & 1 deletion src/collective/solr/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ class ISolrSchema(Interface):
default=u'Specify a threshold (in milliseconds) after which '
u'queries are considered to be slow causing them to '
u'be logged. Set to "0" to prevent any logging.'
)
),
default=0,
)

effective_steps = Int(
Expand Down Expand Up @@ -260,6 +261,7 @@ class ISolrSchema(Interface):
u'between 0 and 1.'
),
required=False,
default=0.0,
)


Expand Down
27 changes: 27 additions & 0 deletions src/collective/solr/profiles/default/registry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<registry>
<records interface="collective.solr.interfaces.ISolrSchema"
prefix="collective.solr">
<value key="active">True</value>
<value key="host">127.0.0.1</value>
<value key="port">8983</value>
<value key="base">/solr</value>
<value key="index_timeout">0.0</value>
<value key="search_timeout">0.0</value>
<value key="max_results">10000000</value>
<value key="exclude_user">False
</value>
<value key="search_pattern">+(Title:{value}^5 OR Description:{value}^2 OR SearchableText:{value} OR SearchableText:({base_value}) OR searchwords:({base_value})^1000) +showinsearch:True
</value>
<value key="required">
<element>SearchableText</element>
</value>
<value key="facets">
<element>portal_type</element>
<element>review_state</element>
</value>
<value key="filter_queries">
<element>portal_type</element>
</value>
</records>
</registry>

0 comments on commit 6e33ccc

Please sign in to comment.