Commit ec7a90e9 authored by Jean-Paul Smets's avatar Jean-Paul Smets

New implementation of filtering and rendering


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@185 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2e31abea
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Acquisition import Implicit
class Filter(Implicit):
def __init__(self, spec=None, filter={}, portal_type=None):
"""
A fil
"""
if type(filter) is type({}):
self.filter = filter
else:
self.filter = {}
if portal_type is not None:
self.filter['portal_type'] = portal_type
if spec is not None:
self.filter['meta_type'] = spec
def test(self, context):
"""
Test filter on a context
"""
for k, v in self.filter.items():
if type(v) in (type([]), type(())):
if context.getProperty(k) not in v:
return 0
elif context.getProperty(k) != v:
return 0
return 1
def asDict(self):
"""
Returns a dictionnary of parameters which can be passed to SQL Catalog
"""
return self.filter
def asSql(self):
"""
Returns an SQL expression which can be used as a query
"""
# To be done
def filter(self, value_list):
return filter(lambda v: self.test(v), value_list)
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Filter import Filter
class Renderer(Filter):
"""
Produces Item list out of category list
"""
def __init__(self, spec=None, filter={}, portal_type=None,
display_id = None, sort_id = None,
display_method = None, sort_method = None,
is_right_display = 0, translate_display = 0, translatation_domain = None,
base_category = None, base=1, display_none_category=0):
"""
- *display_id*: the id of attribute to "call" to calculate the value to display
(getProperty(display_id) -> getDisplayId)
- *display_method*: a callable method which is used to calculate the value to display
- *sort_id*: the id of the attribute to "call" to calculate the value used for sorting.
Sorting is only applied to default ItemList items.
self.getProperty(sort_id)
foo 3
foo1 1
foo2 5
display order will be (foo1, foo, foo2)
- *sort_method*: a callable method which provides a sort function (à la cmp)
- *is_right_display*: use the right value in the couple as the display value.
- *translate_display*: set to 1, we call translation on each item
- *translatation_domain*: domain to use for translation
- *recursive*: browse recursively to build the ItemList
- *base_category*: the base category to consider (if None, default is used) API
- *base*: if set to 0, do not include the base category. If set to 1,
include the base category. If set to a string, use the string as base.
(implementation trick: if set to string, use that string as the base string
when recursing) IMPLEMENTATION HACK
- *base*: if set to 0, do not include the base category. If set to 1,
include the base category. If set to a string, use the string as base.
This is useful for creationg multiple base categories sharing the same categories.
(ex. target_region/region/europe)
- *is_self_excluded*: allows to exclude this category from the displayed list
- *current_category*: allows to provide a category which is not part of the
default ItemList. Very useful for displaying
values in a popup menu which can no longer
be selected.
- *display_none_category*: allows to include an empty value. Very useful
to define None values or empty lists through
popup widgets. If both has_empty_item and
current_category are provided, current_category
is displayed first.
"""
Filter.__init__(self, spec=spec, filter=filter, portal_type=portal_type)
self.display_id = display_id
self.sort_id = sort_id
self.display_method = display_method
self.sort_method = sort_method
self.is_right_display = is_right_display
self.translate_display = translate_display
self.translatation_domain = translatation_domain
self.base_category = base_category
self.base = base
self.display_none_category = display_none_category
def render(self, category_tool, value_list, current_category):
"""
Returns rendered items
"""
value_list = self.filter(value_list)
if self.sort_method is not None:
value_list.sort(self.sort_method)
elif self.sort_id is not None:
value_list.sort(lambda x,y: cmp(x.getProperty(self.sort_id), y.getProperty(self.sort_id)))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment