Back to index

plone3  3.1.7
reference.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """ Topic:
00020 
00021 """
00022 
00023 __author__  = 'Alec Mitchell'
00024 __docformat__ = 'restructuredtext'
00025 __old_name__ = 'Products.ATContentTypes.types.criteria.ATReferenceCriterion'
00026 
00027 from Products.CMFCore.utils import getToolByName
00028 from AccessControl import ClassSecurityInfo
00029 
00030 from Products.ATContentTypes.criteria import registerCriterion
00031 from Products.ATContentTypes.criteria import REFERENCE_INDICES
00032 from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
00033 from Products.ATContentTypes.criteria.selection import ATSelectionCriterion
00034 from Products.Archetypes.atapi import DisplayList
00035 
00036 ATReferenceCriterionSchema = ATSelectionCriterion.schema
00037 
00038 class ATReferenceCriterion(ATSelectionCriterion):
00039     """A reference criterion"""
00040 
00041     __implements__ = ATSelectionCriterion.__implements__ + (IATTopicSearchCriterion, )
00042     security       = ClassSecurityInfo()
00043     meta_type      = 'ATReferenceCriterion'
00044     archetype_name = 'Reference Criterion'
00045     shortDesc      = 'Select referenced content'
00046 
00047 
00048     def getCurrentValues(self):
00049         catalog = getToolByName(self, 'portal_catalog')
00050         uid_cat = getToolByName(self, 'uid_catalog')
00051         putils = getToolByName(self, 'plone_utils')
00052         options = catalog.uniqueValuesFor(self.Field())
00053 
00054         brains = uid_cat(UID=options, sort_on='Title')
00055         display = [((putils.pretty_title_or_id(b)).lower(), b.UID, b.Title or b.id) for b in brains]
00056         display.sort()
00057         display_list = DisplayList([(d[1], d[2]) for d in display])
00058 
00059         return display_list
00060 
00061 registerCriterion(ATReferenceCriterion, REFERENCE_INDICES)