Changeset 412
- Timestamp:
- 07/20/06 08:44:24
- Files:
-
- qTopic/trunk/Extensions (copied) (copied from qTopic/trunk/Extensions)
- qTopic/trunk/Extensions/Install.py (copied) (copied from qTopic/trunk/Extensions/Install.py) (2 diffs)
- qTopic/trunk/LICENSE.txt (copied) (copied from qTopic/trunk/LICENSE.txt)
- qTopic/trunk/__init__.py (copied) (copied from qTopic/trunk/__init__.py)
- qTopic/trunk/config.py (copied) (copied from qTopic/trunk/config.py) (1 diff)
- qTopic/trunk/history.txt (copied) (copied from qTopic/trunk/history.txt) (1 diff)
- qTopic/trunk/qTopic.py (copied) (copied from qTopic/trunk/qTopic.py) (9 diffs)
- qTopic/trunk/readme.txt (copied) (copied from qTopic/trunk/readme.txt) (2 diffs)
- qTopic/trunk/refresh.txt (copied) (copied from qTopic/trunk/refresh.txt)
- qTopic/trunk/skins (copied) (copied from qTopic/trunk/skins)
- qTopic/trunk/skins/qtopic (copied) (copied from qTopic/trunk/skins/qtopic)
- qTopic/trunk/skins/qtopic/atct_macros.pt (copied) (copied from qTopic/branches/plone2.1/skins/qtopic/atct_macros.pt)
- qTopic/trunk/skins/qtopic/atct_manageTopicIndex.cpt.metadata (copied) (copied from qTopic/branches/plone2.1/skins/qtopic/atct_manageTopicIndex.cpt.metadata)
- qTopic/trunk/skins/qtopic/atct_manageTopicMetadata.cpt.metadata (copied) (copied from qTopic/branches/plone2.1/skins/qtopic/atct_manageTopicMetadata.cpt.metadata)
- qTopic/trunk/skins/qtopic/export_csv.py (copied) (copied from qTopic/trunk/skins/qtopic/export_csv.py) (1 diff)
- qTopic/trunk/skins/qtopic/getPGNewsletterSubscribers.py (copied) (copied from qTopic/branches/plone2.1/skins/qtopic/getPGNewsletterSubscribers.py)
- qTopic/trunk/skins/qtopic/result_csv.pt (copied) (copied from qTopic/trunk/skins/qtopic/result_csv.pt) (2 diffs)
- qTopic/trunk/tests (copied) (copied from qTopic/branches/plone2.1/tests)
- qTopic/trunk/tests/__init__.py (copied) (copied from qTopic/branches/plone2.1/tests/__init__.py)
- qTopic/trunk/tests/framework.py (copied) (copied from qTopic/branches/plone2.1/tests/framework.py)
- qTopic/trunk/tests/runalltests.py (copied) (copied from qTopic/branches/plone2.1/tests/runalltests.py)
- qTopic/trunk/tests/test_topictool.py (copied) (copied from qTopic/branches/plone2.1/tests/test_topictool.py)
- qTopic/trunk/version.txt (copied) (copied from qTopic/trunk/version.txt) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
qTopic/trunk/Extensions/Install.py
r410 r412 8 8 def install(self): 9 9 out = StringIO() 10 10 11 11 installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME) 12 12 print >> out, 'Types Installed' … … 14 14 install_subskin(self, out, GLOBALS) 15 15 print >> out, 'Skins Installed' 16 17 pact = getToolByName(self, 'portal_actions') 18 pact.addAction( 'export_csv', 19 'Export in CSV', 20 'string:$object_url/export_csv?download=1', 21 'python:(object.meta_type == "qTopic") or (object.meta_type == "ATTopic")', 22 'View', 23 'document_actions') 24 pact_icons = getToolByName(self, 'portal_actionicons') 25 pact_icons.addActionIcon('plone', 26 'export_csv', 27 'topic_icon.gif', 28 'Export in CSV') 16 29 17 30 out.write('Installation %s successfully completed.\n' % PROJECTNAME) qTopic/trunk/config.py
r410 r412 1 from Products.ATContentTypes. Permissions import ADD_CONTENT_PERMISSION, ADD_TOPIC_PERMISSION1 from Products.ATContentTypes.permission import AddTopics 2 2 from Products.CMFCore import CMFCorePermissions 3 3 qTopic/trunk/history.txt
r410 r412 1 0.1.2 12-08-2005 1 1.0 20-07-2006 2 3 * added Plone 2.1.x - 2.15 support 4 5 * added export to CSV action 6 7 * tests addd 8 9 * multicatalogs support in atct tool 10 11 * new atct catalogs metadata registry configlets 12 13 0.1.2 12-08-2005 2 14 3 15 * added show_header parameter to export_csv script qTopic/trunk/qTopic.py
r410 r412 5 5 from Acquisition import aq_parent, aq_inner 6 6 7 from Products.ATContentTypes.types.ATContentType import updateActions 8 from Products.ATContentTypes.types.ATTopic import ATTopic, IGNORED_FIELDS 9 from Products.ATContentTypes.interfaces.IATTopic import IATTopic 10 from Products.ATContentTypes.types.criteria import CriterionRegistry 11 from Products.ATContentTypes.Permissions import ChangeTopics, AddTopics 12 from Products.ATContentTypes.types.schemata import ATTopicSchema 13 from Products.ATContentTypes.interfaces.IATTopic import IATTopicSearchCriterion, IATTopicSortCriterion 7 from Products.ATContentTypes.content.base import updateActions 8 from Products.ATContentTypes.content.topic import ATTopic, IGNORED_FIELDS 9 from Products.ATContentTypes.interfaces import IATTopic 10 from Products.ATContentTypes.types.criteria import _criterionRegistry 11 from Products.ATContentTypes.permission import ChangeTopics, AddTopics 12 from Products.CMFCore.permissions import View 13 from Products.ATContentTypes.content.topic import ATTopicSchema 14 from Products.ATContentTypes.interfaces import IATTopicSearchCriterion, IATTopicSortCriterion 14 15 from Products.Archetypes.public import * 15 16 from config import * 17 from Products.CMFPlone.PloneBatch import Batch 18 from Products.ATContentTypes.config import TOOLNAME 16 19 17 20 qTopic_schema = ATTopicSchema.copy() + Schema(( 18 StringField( 'catalog',19 default = 'portal_catalog',20 vocabulary = 'getCatalogList',21 StringField("catalog", 22 default = "portal_catalog", 23 vocabulary = "getCatalogList", 21 24 widget = SelectionWidget(label="Catalog", 22 25 label_msgid="label_catalog", … … 24 27 description_msgid="description_catalog") 25 28 ), 26 LinesField('exportFields', 27 vocabulary = 'getFieldsList', 28 schemata = 'export', 29 widget = MultiSelectionWidget(label="Fields to be exported", 30 label_msgid="label_export_fields", 31 description="Select fileds to be exported", 32 description_msgid="description_export_fields") 33 ), 34 BooleanField('showHeader', 35 schemata = 'export', 29 BooleanField("showHeader", 30 schemata = "export", 36 31 default = 1, 37 32 widget = BooleanWidget(label="Print field headers", … … 40 35 description_msgid="description_print_headers") 41 36 ), 42 StringField( 'delimiter',43 default = ';',44 schemata = 'export',37 StringField("delimiter", 38 default = ";", 39 schemata = "export", 45 40 widget = StringWidget(label="Values delimiter", 46 41 label_msgid="label_delimiter", … … 50 45 ), 51 46 )) 52 47 qTopic_schema["customViewFields"].schemata = "export" 48 qTopic_schema["customViewFields"].vocabulary = "getFieldsList" 49 qTopic_schema["customViewFields"].default=("id","getFullName","getEmail") 53 50 54 51 class qTopic(ATTopic): 55 52 """A topic folder""" 56 meta_type = 'qTopic'57 portal_type = 'qTopic'58 archetype_name = 'qTopic'53 meta_type = "qTopic" 54 portal_type = "qTopic" 55 archetype_name = "qTopic" 59 56 typeDescription= ("qTopic is the same topic but with "+ 60 57 "option of catlog selection") 61 typeDescMsgId = 'description_edit_topic'58 typeDescMsgId = "description_edit_topic" 62 59 63 60 schema = qTopic_schema … … 66 63 ( 67 64 { 68 'id' : 'export_csv',69 'name' : 'Export in CSV',70 'action' : 'string:${folder_url}/result_csv',71 'permissions': (CMFCorePermissions.View,)65 "id" : "export_csv", 66 "name" : "Export in CSV", 67 "action" : "string:${folder_url}/result_csv", 68 "permissions" : (CMFCorePermissions.View,) 72 69 }, 73 70 ) … … 77 74 """ return list of catalog ids 78 75 """ 79 at_tool = getToolByName(self, 'archetype_tool')76 at_tool = getToolByName(self, "archetype_tool") 80 77 catalogs = at_tool.getCatalogsInSite() 81 78 return DisplayList(zip(catalogs, catalogs)) 82 79 83 80 def getFieldsList(self): 84 81 """ return DisplayList of fields … … 91 88 ] 92 89 val.sort(lambda x,y: strcoll(self.translate(x),self.translate( y))) 93 return DisplayList(zip(val, val))94 95 security.declareProtected(ChangeTopics, 'criteriaByIndexId')90 return [(i, i, i)for i in val] 91 92 security.declareProtected(ChangeTopics, "criteriaByIndexId") 96 93 def criteriaByIndexId(self, indexId): 94 """ get createrias bu index """ 97 95 catalog_tool = getToolByName(self, self.getCatalog()) 98 96 indexObj = catalog_tool.Indexes[indexId] 99 results = CriterionRegistry.criteriaByIndex(indexObj.meta_type)97 results = _criterionRegistry.criteriaByIndex(indexObj.meta_type) 100 98 return results 101 99 102 security.declareProtected(ChangeTopics, 'listFields') 100 security.declareProtected(View, 'allowedCriteriaForField') 101 def allowedCriteriaForField(self, field, display_list=False): 102 """ Return all valid criteria for a given field. Optionally include 103 descriptions in list in format [(desc1, val1) , (desc2, val2)] for 104 javascript selector.""" 105 tool = getToolByName(self, self.getCatalog()) 106 criteria = _criterionRegistry.listTypes() 107 allowed = [crit for crit in criteria 108 if crit in self.criteriaByIndexId(field)] 109 if display_list: 110 flat = [] 111 for a in allowed: 112 desc = _criterionRegistry[a].shortDesc 113 flat.append((a,desc)) 114 allowed = DisplayList(flat) 115 return allowed 116 """ 117 security.declareProtected(ChangeTopics, "listFields") 103 118 def listFields(self): 104 """Return a list of fields from portal_catalog.105 """106 119 pcatalog = getToolByName( self, self.getCatalog() ) 107 120 available = pcatalog.indexes() … … 111 124 ] 112 125 val.sort(lambda x,y: strcoll(self.translate(x),self.translate( y))) 113 return val 114 115 116 security.declareProtected(CMFCorePermissions.View, 'queryCatalog') 117 def queryCatalog(self, REQUEST=None, **kw): 126 return [(i, i, i)for i in val] 127 """ 128 security.declareProtected(ChangeTopics, "listFields") 129 def listFields(self): 130 """Return a list of fields from portal_catalog. 131 """ 132 tool = getToolByName(self, TOOLNAME) 133 return tool.getEnabledFields(catalog_name=self.getCatalog()) 134 135 security.declareProtected(ChangeTopics, 'listAvailableFields') 136 def listAvailableFields(self): 137 """Return a list of available fields for new criteria. 138 """ 139 return self.listFields() 140 141 security.declareProtected(View, 'listMetaDataFields') 142 def listMetaDataFields(self, exclude=True): 143 """Return a list of metadata fields from portal_catalog. 144 """ 145 tool = getToolByName(self, TOOLNAME) 146 catalog_name=self.getCatalog() 147 return tool.getMetadataDisplay(exclude,catalog_name=catalog_name) 148 149 security.declareProtected(CMFCorePermissions.View, "queryCatalog") 150 def queryCatalog(self, REQUEST=None, batch=False, b_size=None, 151 full_objects=False, **kw): 118 152 """Invoke the catalog using our criteria to augment any passed 119 153 in query before calling the catalog. 120 154 """ 155 if REQUEST is None: 156 REQUEST = getattr(self, 'REQUEST', {}) 157 b_start = REQUEST.get('b_start', 0) 158 121 159 q = self.buildQuery() 122 160 if q is None: 123 161 # empty query - do not show anything 162 if batch: 163 return Batch([], 20, int(b_start), orphan=0) 124 164 return [] 125 kw.update(q) 165 # Allow parameters to further limit existing criterias 166 for k,v in q.items(): 167 if kw.has_key(k): 168 arg = kw.get(k) 169 if isinstance(arg, (ListType,TupleType)) and isinstance(v, (ListType,TupleType)): 170 kw[k] = [x for x in arg if x in v] 171 elif isinstance(arg, StringType) and isinstance(v, (ListType,TupleType)) and arg in v: 172 kw[k] = [arg] 173 else: 174 kw[k]=v 175 else: 176 kw[k]=v 177 #kw.update(q) 126 178 pcatalog = getToolByName(self, self.getCatalog()) 127 179 limit = self.getLimitNumber() 128 180 max_items = self.getItemCount() 129 if limit and self.hasSortCriterion(): 181 # Batch based on limit size if b_szie is unspecified 182 if max_items and b_size is None: 183 b_size = int(max_items) 184 else: 185 b_size = 20 186 if limit and max_items and self.hasSortCriterion(): 130 187 # Sort limit helps Zope 2.6.1+ to do a faster query 131 188 # sorting when sort is involved 132 189 # See: http://zope.org/Members/Caseman/ZCatalog_for_2.6.1 133 190 kw.setdefault('sort_limit', max_items) 191 __traceback_info__ = (self, kw,) 134 192 results = pcatalog.searchResults(REQUEST, **kw) 193 if full_objects and not limit: 194 results = [b.getObject() for b in results] 195 if batch: 196 batch = Batch(results, b_size, int(b_start), orphan=0) 197 return batch 135 198 if limit: 199 if full_objects: 200 return [b.getObject() for b in results[:max_items]] 136 201 return results[:max_items] 137 202 return results 203 138 204 139 205 … … 144 210 """ 145 211 actions = [] 146 for action in fti[ 'actions']:147 if action[ 'id'] == 'folderlisting':148 action[ 'visible'] = False212 for action in fti["actions"]: 213 if action["id"] == "folderlisting": 214 action["visible"] = False 149 215 #actions.append(action) 150 #fti[ 'actions'] = tuple(actions)216 #fti["actions"] = tuple(actions) qTopic/trunk/readme.txt
r410 r412 1 qTopic is simple ATCTTopic extending class. 1 qTopic is ATCTTopic extending class. qTopic allows query custom 2 catalogs besides portal_catalog, export query result to csv file. 2 3 4 qTopic 0.1.3 is designed for Plone 2.0.5 5 qTopic 1.0 does support Plone 2.1.x and Plone 2.5 3 6 4 "Product Homepage":http://quintagroup.com/services/plone-development/products/click-tracking-tool | 5 "Download":http://sourceforge.net/projects/quintagroup 6 7 (c) "Quintagroup":http://quintagroup.com/ , 2005. 8 9 support@quintagroup.com * quintessence of modern business 10 11 12 13 FEATURES 14 15 * export serch result in CSV format 16 17 * select source catalog 7 New features added for Plone 2.1.x Plone 2.5: 8 atct tool catalogs metadata registry extended to allow custom catalog indexes and metadata registration. 9 added new action for SmartFolders export to CSV. 10 added tests. 18 11 19 12 … … 30 23 AUTHORS 31 24 32 * Volodymyr Cherepanyak, quintagroup.com 25 Volodymyr Cherepanyak, quintagroup.com. 26 Mykola Harechko, quintagroup.com. qTopic/trunk/skins/qtopic/export_csv.py
r410 r412 9 9 if download: 10 10 context.REQUEST.RESPONSE.setHeader('Content-Type', 'plain/text') 11 context.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment; filename="%s.csv"' % context.getId()) 11 context.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment; filename="%s.csv"'% context.getId()) 12 12 13 res = context.queryCatalog() 13 fields = fields or context.getExportFields() 14 delimiter = context.getDelimiter() or ';' 15 if show_header and context.getShowHeader(): 16 print delimiter.join(fields) 14 fields = fields or context.getCustomViewFields() 15 16 if hasattr(context, 'getDelimiter'): 17 delimiter = context.getDelimiter() or ';' 18 else: 19 delimiter = ',' 20 21 if hasattr(context, 'getShowHeader'): 22 if show_header and context.getShowHeader(): 23 print delimiter.join(fields) 24 else: 25 if show_header: 26 print delimiter.join(fields) 27 28 17 29 for r in res: 18 30 print delimiter.join([test(getattr(r, f, ''),getattr(r, f, ''),'') for f in fields]) qTopic/trunk/skins/qtopic/result_csv.pt
r410 r412 1 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" 2 lang="en" 3 metal:use-macro="here/main_template/macros/master" 4 i18n:domain="plone"> 1 <html xmlns="http://www.w3.org/1999/xhtml" 2 xml:lang="en-US" 3 lang="en-US" 4 xmlns:tal="http://xml.zope.org/namespaces/tal" 5 xmlns:metal="http://xml.zope.org/namespaces/metal" 6 xmlns:i18n="http://xml.zope.org/namespaces/i18n" 7 i18n:domain="plone" 8 metal:use-macro="here/main_template/macros/master"> 5 9 6 10 <body> … … 24 28 CSV file 25 29 </iframe> 26 30 27 31 </tal:main-macro> 28 32 </div> qTopic/trunk/version.txt
r410 r412 1 0.1.3 1 1.0
