Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Static Private Attributes
ATContentTypes.content.topic.ATTopic Class Reference
Inheritance diagram for ATContentTypes.content.topic.ATTopic:
Inheritance graph
[legend]
Collaboration diagram for ATContentTypes.content.topic.ATTopic:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def initializeArchetype
def validateAddCriterion
def criteriaByIndexId
def listCriteriaTypes
def listCriteriaMetaTypes
def listSearchCriteriaTypes
def listSearchCriteriaMetaTypes
def listSortCriteriaTypes
def listSortCriteriaMetaTypes
def listCriteria
def listSearchCriteria
def hasSortCriterion
def getSortCriterion
def removeSortCriterion
def setSortCriterion
def listIndicesByCriterion
def listFields
def listSortFields
def listAvailableFields
def listSubtopics
def hasSubtopics
def listMetaDataFields
def allowedCriteriaForField
def buildQuery
def queryCatalog
def addCriterion
def deleteCriterion
def getCriterion
def addSubtopic
def synContentValues
def canSetDefaultPage
def getCriteriaUniqueWidgetAttr
def displayContentsTab
def HEAD
def setText
def getTidyOutput

Static Public Attributes

 schema = ATTopicSchema
string portal_type = 'Topic'
string archetype_name = 'Collection'
tuple assocMimetypes = ()
tuple assocFileExt = ()
tuple cmf_edit_kws = ()
int use_folder_tabs = 0
tuple security = ClassSecurityInfo()

Static Private Attributes

dictionary _atct_newTypeFor = {'portal_type' : 'CMF Topic', 'meta_type' : 'Portal Topic'}
 __implements__ = ATCTFolder.__implements__,IATTopic
 __dav_marshall__ = True

Detailed Description

An automatically updated stored search that can be used to display items matching criteria you specify.

Definition at line 162 of file topic.py.


Member Function Documentation

def ATContentTypes.content.topic.ATTopic.addCriterion (   self,
  field,
  criterion_type 
)
Add a new search criterion. Return the resulting object.

Definition at line 474 of file topic.py.

00474 
00475     def addCriterion(self, field, criterion_type):
00476         """Add a new search criterion. Return the resulting object.
00477         """
00478         newid = 'crit__%s_%s' % (field, criterion_type)
00479         ct    = _criterionRegistry[criterion_type]
00480         crit  = ct(newid, field)
00481 
00482         self._setObject( newid, crit )
00483         return self._getOb( newid )

Here is the call graph for this function:

Here is the caller graph for this function:

Add a new subtopic.

Definition at line 504 of file topic.py.

00504 
00505     def addSubtopic(self, id):
00506         """Add a new subtopic.
00507         """
00508         ti = self.getTypeInfo()
00509         ti.constructInstance(self, id)
00510         return self._getOb( id )

Here is the call graph for this function:

def ATContentTypes.content.topic.ATTopic.allowedCriteriaForField (   self,
  field,
  display_list = False 
)
Return all valid criteria for a given field.  Optionally include
    descriptions in list in format [(desc1, val1) , (desc2, val2)] for
    javascript selector.

Definition at line 365 of file topic.py.

00365 
00366     def allowedCriteriaForField(self, field, display_list=False):
00367         """ Return all valid criteria for a given field.  Optionally include
00368             descriptions in list in format [(desc1, val1) , (desc2, val2)] for
00369             javascript selector."""
00370         tool = getToolByName(self, TOOLNAME)
00371         criteria = tool.getIndex(field).criteria
00372         allowed = [crit for crit in criteria
00373                                 if self.validateAddCriterion(field, crit)]
00374         if display_list:
00375             flat = []
00376             for a in allowed:
00377                 desc = _criterionRegistry[a].shortDesc
00378                 flat.append((a,desc))
00379             allowed = DisplayList(flat)
00380         return allowed

Here is the call graph for this function:

Construct a catalog query using our criterion objects.

Definition at line 382 of file topic.py.

00382 
00383     def buildQuery(self):
00384         """Construct a catalog query using our criterion objects.
00385         """
00386         result = {}
00387         criteria = self.listCriteria()
00388         acquire = self.getAcquireCriteria()
00389         if not criteria and not acquire:
00390             # no criteria found
00391             return None
00392 
00393         if acquire:
00394             try:
00395                 # Tracker 290 asks to allow combinations, like this:
00396                 # parent = aq_parent(self)
00397                 parent = aq_parent(aq_inner(self))
00398                 result.update(parent.buildQuery())
00399             except (AttributeError, Unauthorized): # oh well, can't find parent, or it isn't a Topic.
00400                 pass
00401 
00402         for criterion in criteria:
00403             for key, value in criterion.getCriteriaItems():
00404                 result[key] = value
00405         return result

Here is the call graph for this function:

Here is the caller graph for this function:

Override BrowserDefaultMixin because default page stuff doesn't make
sense for topics.

Definition at line 522 of file topic.py.

00522 
00523     def canSetDefaultPage(self):
00524         """
00525         Override BrowserDefaultMixin because default page stuff doesn't make
00526         sense for topics.
00527         """
00528         return False

Definition at line 201 of file topic.py.

00201 
00202     def criteriaByIndexId(self, indexId):
00203         catalog_tool = getToolByName(self, CatalogTool.id)
00204         indexObj = catalog_tool.Indexes[indexId]
00205         results = _criterionRegistry.criteriaByIndex(indexObj.meta_type)
00206         return results

Here is the call graph for this function:

Here is the caller graph for this function:

def ATContentTypes.content.topic.ATTopic.deleteCriterion (   self,
  criterion_id 
)
Delete selected criterion.

Definition at line 485 of file topic.py.

00485 
00486     def deleteCriterion(self, criterion_id):
00487         """Delete selected criterion.
00488         """
00489         if type(criterion_id) is StringType:
00490             self._delObject(criterion_id)
00491         elif type(criterion_id) in (ListType, TupleType):
00492             for cid in criterion_id:
00493                 self._delObject(cid)

Here is the call graph for this function:

Here is the caller graph for this function:

def ATContentTypes.content.topic.ATTopic.displayContentsTab (   self,
  args,
  kwargs 
)
Only display a contents tab when we are the default page
   because we have our own

Definition at line 548 of file topic.py.

00548 
00549     def displayContentsTab(self, *args, **kwargs):
00550         """Only display a contents tab when we are the default page
00551            because we have our own"""
00552         putils = getToolByName(self, 'plone_utils', None)
00553         if putils is not None:
00554             if putils.isDefaultPage(self):
00555                 script = putils.displayContentsTab.__of__(self)
00556                 return script()
00557         return False

Here is the call graph for this function:

Get a unique list values for a specific attribute for all widgets
   on all criteria

Definition at line 530 of file topic.py.

00530 
00531     def getCriteriaUniqueWidgetAttr(self, attr):
00532         """Get a unique list values for a specific attribute for all widgets
00533            on all criteria"""
00534         criteria = self.listCriteria()
00535         order = []
00536         for crit in criteria:
00537             fields = crit.Schema().fields()
00538             for f in fields:
00539                 widget = f.widget
00540                 helper = getattr(widget, attr, None)
00541                 # We expect the attribute value to be a iterable.
00542                 if helper:
00543                     [order.append(item) for item in helper
00544                         if item not in order]
00545         return order

Here is the call graph for this function:

def ATContentTypes.content.topic.ATTopic.getCriterion (   self,
  criterion_id 
)
Get the criterion object.

Definition at line 495 of file topic.py.

00495 
00496     def getCriterion(self, criterion_id):
00497         """Get the criterion object.
00498         """
00499         try:
00500             return self._getOb('crit__%s' % criterion_id)
00501         except AttributeError:
00502             return self._getOb(criterion_id)

Here is the call graph for this function:

Return the Sort criterion if setup.

Definition at line 279 of file topic.py.

00279 
00280     def getSortCriterion(self):
00281         """Return the Sort criterion if setup.
00282         """
00283         for criterion in self.listCriteria():
00284             if IATTopicSortCriterion.isImplementedBy(criterion):
00285                 return criterion
00286         return None

Here is the call graph for this function:

Here is the caller graph for this function:

Get the tidied output for a specific field from the request
if available

Definition at line 614 of file topic.py.

00614 
00615     def getTidyOutput(self, field):
00616         """Get the tidied output for a specific field from the request
00617         if available
00618         """
00619         request = getattr(self, 'REQUEST', None)
00620         if request is not None and isinstance(request, HTTPRequest):
00621             tidyAttribute = '%s_tidier_data' % field.getName()
00622             return request.get(tidyAttribute, None)
00623 
00624 registerATCT(ATTopic, PROJECTNAME)

Here is the call graph for this function:

Here is the caller graph for this function:

Tells if a sort criterai is already setup.

Definition at line 273 of file topic.py.

00273 
00274     def hasSortCriterion(self):
00275         """Tells if a sort criterai is already setup.
00276         """
00277         return not self.getSortCriterion() is None

Here is the call graph for this function:

Here is the caller graph for this function:

Returns true if subtopics have been created on this topic.

Definition at line 351 of file topic.py.

00351 
00352     def hasSubtopics(self):
00353         """Returns true if subtopics have been created on this topic.
00354         """
00355         val = self.objectIds(self.meta_type)
00356         return not not val

Here is the call graph for this function:

def ATContentTypes.content.topic.ATTopic.HEAD (   self,
  REQUEST,
  RESPONSE 
)
Retrieve resource information without a response body.

An empty Topic returns 404 NotFound while a topic w/ a
criterion returns 200 OK.

Definition at line 558 of file topic.py.

00558 
00559     def HEAD(self, REQUEST, RESPONSE):
00560         """Retrieve resource information without a response body.
00561 
00562         An empty Topic returns 404 NotFound while a topic w/ a
00563         criterion returns 200 OK.
00564         """
00565         self.dav__init(REQUEST, RESPONSE)
00566         criteria = self.listCriteria()
00567         acquire = self.getAcquireCriteria()
00568         if not criteria:
00569             if not acquire:
00570                 # no criteria found
00571                 raise NotFound, 'The requested resource is empty.'
00572             else:
00573                 # try to acquire a query
00574                 parent = aq_parent(aq_inner(self))
00575                 try:
00576                     query = parent.buildQuery()
00577                 except (AttributeError, KeyError):
00578                     raise NotFound, 'The requested resource is empty.'
00579                 else:
00580                     if not query:
00581                         raise NotFound, 'The requested resource is empty.'
00582 
00583         return WebdavResoure.HEAD(self, REQUEST, RESPONSE)

Here is the call graph for this function:

Definition at line 184 of file topic.py.

00184 
00185     def initializeArchetype(self, **kwargs):
00186         ret_val = ATCTFolder.initializeArchetype(self, **kwargs)
00187         # Enable topic syndication by default
00188         syn_tool = getToolByName(self, 'portal_syndication', None)
00189         if syn_tool is not None:
00190             if (syn_tool.isSiteSyndicationAllowed() and
00191                                     not syn_tool.isSyndicationAllowed(self)):
00192                 syn_tool.enableSyndication(self)
00193         return ret_val

Here is the call graph for this function:

Return a list of available fields for new criteria.

Definition at line 324 of file topic.py.

00324 
00325     def listAvailableFields(self):
00326         """Return a list of available fields for new criteria.
00327         """
00328         current   = [ crit.Field() for crit in self.listCriteria()
00329                       if not IATTopicSortCriterion.isImplementedBy(crit)]
00330         fields = self.listFields()
00331         val = [ field
00332                  for field in fields
00333                  if field[0] not in current
00334                ]
00335         return val

Here is the call graph for this function:

Return a list of our criteria objects.

Definition at line 256 of file topic.py.

00256 
00257     def listCriteria(self):
00258         """Return a list of our criteria objects.
00259         """
00260         val = self.objectValues(self.listCriteriaMetaTypes())
00261         # XXX Sorting results in inconsistent order. Leave them in the order
00262         # they were added.
00263         #val.sort()
00264         return val

Here is the call graph for this function:

Here is the caller graph for this function:

List available criteria

Definition at line 216 of file topic.py.

00216 
00217     def listCriteriaMetaTypes(self):
00218         """List available criteria
00219         """
00220         val = _criterionRegistry.listTypes()
00221         val.sort()
00222         return val

Here is the caller graph for this function:

List available criteria types as dict

Definition at line 208 of file topic.py.

00208 
00209     def listCriteriaTypes(self):
00210         """List available criteria types as dict
00211         """
00212         return [ {'name': ctype,
00213                   'description':_criterionRegistry[ctype].shortDesc}
00214                  for ctype in self.listCriteriaMetaTypes() ]

Here is the call graph for this function:

Return a list of fields from portal_catalog.

Definition at line 309 of file topic.py.

00309 
00310     def listFields(self):
00311         """Return a list of fields from portal_catalog.
00312         """
00313         tool = getToolByName(self, TOOLNAME)
00314         return tool.getEnabledFields()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 303 of file topic.py.

00303 
00304     def listIndicesByCriterion(self, criterion):
00305         """
00306         """
00307         return _criterionRegistry.indicesByCriterion(criterion)

def ATContentTypes.content.topic.ATTopic.listMetaDataFields (   self,
  exclude = True 
)
Return a list of metadata fields from portal_catalog.

Definition at line 358 of file topic.py.

00358 
00359     def listMetaDataFields(self, exclude=True):
00360         """Return a list of metadata fields from portal_catalog.
00361         """
00362         tool = getToolByName(self, TOOLNAME)
00363         return tool.getMetadataDisplay(exclude)

Here is the call graph for this function:

Return a list of our search criteria objects.

Definition at line 266 of file topic.py.

00266 
00267     def listSearchCriteria(self):
00268         """Return a list of our search criteria objects.
00269         """
00270         return [val for val in self.listCriteria() if
00271              IATTopicSearchCriterion.isImplementedBy(val)]

Here is the call graph for this function:

List available search criteria

Definition at line 232 of file topic.py.

00232 
00233     def listSearchCriteriaMetaTypes(self):
00234         """List available search criteria
00235         """
00236         val = _criterionRegistry.listSearchTypes()
00237         val.sort()
00238         return val

Here is the caller graph for this function:

List available search criteria types as dict

Definition at line 224 of file topic.py.

00224 
00225     def listSearchCriteriaTypes(self):
00226         """List available search criteria types as dict
00227         """
00228         return [ {'name': ctype,
00229                   'description':_criterionRegistry[ctype].shortDesc}
00230                  for ctype in self.listSearchCriteriaMetaTypes() ]

Here is the call graph for this function:

List available sort criteria

Definition at line 248 of file topic.py.

00248 
00249     def listSortCriteriaMetaTypes(self):
00250         """List available sort criteria
00251         """
00252         val = _criterionRegistry.listSortTypes()
00253         val.sort()
00254         return val

Here is the caller graph for this function:

List available sort criteria types as dict

Definition at line 240 of file topic.py.

00240 
00241     def listSortCriteriaTypes(self):
00242         """List available sort criteria types as dict
00243         """
00244         return [ {'name': ctype,
00245                   'description':_criterionRegistry[ctype].shortDesc}
00246                  for ctype in self.listSortCriteriaMetaTypes() ]

Here is the call graph for this function:

Return a list of available fields for sorting.

Definition at line 316 of file topic.py.

00316 
00317     def listSortFields(self):
00318         """Return a list of available fields for sorting."""
00319         fields = [ field
00320                     for field in self.listFields()
00321                     if self.validateAddCriterion(field[0], 'ATSortCriterion') ]
00322         return fields

Here is the call graph for this function:

Return a list of our subtopics.

Definition at line 337 of file topic.py.

00337 
00338     def listSubtopics(self):
00339         """Return a list of our subtopics.
00340         """
00341         val = self.objectValues(self.meta_type)
00342         check_p = getToolByName(self, 'portal_membership').checkPermission
00343         tops = []
00344         for top in val:
00345             if check_p('View', top):
00346                 tops.append((top.Title().lower(),top))
00347         tops.sort()
00348         tops = [t[1] for t in tops]
00349         return val

Here is the call graph for this function:

def ATContentTypes.content.topic.ATTopic.queryCatalog (   self,
  REQUEST = None,
  batch = False,
  b_size = None,
  full_objects = False,
  kw 
)
Invoke the catalog using our criteria to augment any passed
    in query before calling the catalog.

Definition at line 408 of file topic.py.

00408 
00409                                                     full_objects=False, **kw):
00410         """Invoke the catalog using our criteria to augment any passed
00411             in query before calling the catalog.
00412         """
00413         if REQUEST is None:
00414             REQUEST = getattr(self, 'REQUEST', {})
00415         b_start = REQUEST.get('b_start', 0)
00416 
00417         pcatalog = getToolByName(self, 'portal_catalog')
00418         mt = getToolByName(self, 'portal_membership')
00419         related = [ i for i in self.getRelatedItems() \
00420                         if mt.checkPermission(View, i) ]
00421         if not full_objects:
00422             related = [ pcatalog(path='/'.join(r.getPhysicalPath()))[0] 
00423                         for r in related]
00424         related=LazyCat([related])
00425 
00426         limit = self.getLimitNumber()
00427         max_items = self.getItemCount()
00428         # Batch based on limit size if b_szie is unspecified
00429         if max_items and b_size is None:
00430             b_size = int(max_items)
00431         else:
00432             b_size = b_size or 20
00433 
00434         q = self.buildQuery()
00435         if q is None:
00436             results=LazyCat([[]])
00437         else:
00438             # Allow parameters to further limit existing criterias
00439             for k,v in q.items():
00440                 if kw.has_key(k):
00441                     arg = kw.get(k)
00442                     if isinstance(arg, (ListType,TupleType)) and isinstance(v, (ListType,TupleType)):
00443                         kw[k] = [x for x in arg if x in v]
00444                     elif isinstance(arg, StringType) and isinstance(v, (ListType,TupleType)) and arg in v:
00445                         kw[k] = [arg]
00446                     else:
00447                         kw[k]=v
00448                 else:
00449                     kw[k]=v
00450             #kw.update(q)
00451             if not batch and limit and max_items and self.hasSortCriterion():
00452                 # Sort limit helps Zope 2.6.1+ to do a faster query
00453                 # sorting when sort is involved
00454                 # See: http://zope.org/Members/Caseman/ZCatalog_for_2.6.1
00455                 kw.setdefault('sort_limit', max_items)
00456             __traceback_info__ = (self, kw,)
00457             results = pcatalog.searchResults(REQUEST, **kw)
00458 
00459 
00460         if limit and not batch:
00461             if full_objects:
00462                 return related[:max_items] + \
00463                        [b.getObject() for b in results[:max_items-len(related)]]
00464             return related[:max_items] + results[:max_items-len(related)]
00465         elif full_objects:
00466             results = related + LazyCat([[b.getObject() for b in results]])
00467         else:
00468             results = related + results
00469         if batch:
00470             batch = Batch(results, b_size, int(b_start), orphan=0)
00471             return batch
00472         return results

Here is the call graph for this function:

Here is the caller graph for this function:

remove the Sort criterion.

Definition at line 288 of file topic.py.

00288 
00289     def removeSortCriterion( self):
00290         """remove the Sort criterion.
00291         """
00292         if self.hasSortCriterion():
00293             self.deleteCriterion(self.getSortCriterion().getId())

Here is the call graph for this function:

Here is the caller graph for this function:

def ATContentTypes.content.topic.ATTopic.setSortCriterion (   self,
  field,
  reversed 
)
Set the Sort criterion.

Definition at line 295 of file topic.py.

00295 
00296     def setSortCriterion( self, field, reversed):
00297         """Set the Sort criterion.
00298         """
00299         self.removeSortCriterion()
00300         self.addCriterion(field, 'ATSortCriterion')
00301         self.getSortCriterion().setReversed(reversed)

Here is the call graph for this function:

def ATContentTypes.content.topic.ATTopic.setText (   self,
  value,
  kwargs 
)
Body text mutator

* hook into mxTidy an replace the value with the tidied value

Definition at line 585 of file topic.py.

00585 
00586     def setText(self, value, **kwargs):
00587         """Body text mutator
00588         
00589         * hook into mxTidy an replace the value with the tidied value
00590         """
00591         field = self.getField('text')
00592         # XXX this is ugly
00593         # When an object is initialized the first time we have to 
00594         # set the filename and mimetype.
00595         # In the case the value is empty/None we must not set the value because
00596         # it will overwrite uploaded data like a pdf file.
00597         if (value is None or value == ""):
00598             if not field.getRaw(self):
00599                 # set mimetype and file name although the fi
00600                 if 'mimetype' in kwargs and kwargs['mimetype']:
00601                     field.setContentType(self, kwargs['mimetype'])
00602                 if 'filename' in kwargs and kwargs['filename']:
00603                     field.setFilename(self, kwargs['filename'])
00604             else:
00605                 return
00606 
00607         # hook for mxTidy / isTidyHtmlWithCleanup validator
00608         tidyOutput = self.getTidyOutput(field)
00609         if tidyOutput:
00610             value = tidyOutput
00611 
00612         field.set(self, value, **kwargs) # set is ok

Here is the call graph for this function:

Here is the caller graph for this function:

Getter for syndacation support

Definition at line 512 of file topic.py.

00512 
00513     def synContentValues(self):
00514         """Getter for syndacation support
00515         """
00516         syn_tool = getToolByName(self, 'portal_syndication')
00517         limit = int(syn_tool.getMaxItems(self))
00518         brains = self.queryCatalog(sort_limit=limit)[:limit]
00519         objs = [brain.getObject() for brain in brains]
00520         return [obj for obj in objs if obj is not None]

Here is the call graph for this function:

def ATContentTypes.content.topic.ATTopic.validateAddCriterion (   self,
  indexId,
  criteriaType 
)
Is criteriaType acceptable criteria for indexId

Definition at line 195 of file topic.py.

00195 
00196     def validateAddCriterion(self, indexId, criteriaType):
00197         """Is criteriaType acceptable criteria for indexId
00198         """
00199         return criteriaType in self.criteriaByIndexId(indexId)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 179 of file topic.py.

ATContentTypes.content.topic.ATTopic.__implements__ = ATCTFolder.__implements__,IATTopic [static, private]

Definition at line 176 of file topic.py.

dictionary ATContentTypes.content.topic.ATTopic._atct_newTypeFor = {'portal_type' : 'CMF Topic', 'meta_type' : 'Portal Topic'} [static, private]

Definition at line 169 of file topic.py.

Definition at line 168 of file topic.py.

Definition at line 171 of file topic.py.

Definition at line 170 of file topic.py.

Definition at line 172 of file topic.py.

Definition at line 167 of file topic.py.

Definition at line 165 of file topic.py.

tuple ATContentTypes.content.topic.ATTopic.security = ClassSecurityInfo() [static]

Definition at line 181 of file topic.py.

Definition at line 174 of file topic.py.


The documentation for this class was generated from the following file: