def registerPlugin(c): """ Add a class to Zwiki's global plugin registry. >>> from Products.ZWiki.plugins import registerPlugin >>> registerPlugin(MyMixinClass) """ name = '%s.%s' % (c.__module__, c.__name__) for i in range(len(PLUGINS)): if PLUGINS[i] == Null: PLUGINS[i] = c BLATHER('loaded plugin: %s' % name) return BLATHER('could not register %s plugin, need more plugin slots!' % name)
def vote(self,vote=None,REQUEST=None): """ Record a user's vote for this page, or unrecord it if a null vote string is provided. To make robust image-button voting forms easier, if vote is not provided we also look for form values named like vote0, vote1.. voteN and use the selected N as the vote. """ username = self.usernameFrom(REQUEST) if username: votes = self.votes() if vote == None: # look for a form input named voteN and get N # depending on browser, there will also be # voteN.x and voteN.y, or only these if REQUEST: votefields = [k for k in REQUEST.form.keys() if k.startswith('vote')] if votefields: vote = votefields[0][4:] vote = re.sub(r'\.[xy]$','',vote) if vote == None: # probably a bot visit, ignore return elif vote == '': try: del votes[username] BLATHER("%s: removed %s's vote" % (self.toencoded(self.pageName()),username)) except KeyError: return else: votes[username] = vote BLATHER("%s: recorded %s vote for %s" % (self.toencoded(self.pageName()),vote,username)) self.setVotes(votes) # update catalog, just the affected indexes self.catalog().catalog_object(self, idxs=['rating', 'voteCount'], uid=None) if REQUEST: REQUEST.RESPONSE.redirect( # redirect to the page they came on.. might be some # other page, eg a list of rated pages. Is this robust ? #REQUEST.URL1 REQUEST.HTTP_REFERER )
def registerPageType(t, prepend=0): """ Add a page type class to Zwiki's global registry, optionally at the front. >>> from Products.ZWiki.plugins.pagetypes import registerPageType >>> registerPageType(MyPageTypeClass) """ if prepend: pos = 0 else: pos = len(PAGETYPES) PAGETYPES.insert(pos, t) PAGE_TYPES[t._id] = t._name BLATHER('loaded page type: %s (%s)' % (t._id, t._name))
def test_BLATHER(self): BLATHER('E') # ascii BLATHER('É') # utf-8 BLATHER(u'\xc9') # unicode
>>> registerPlugin(MyMixinClass) """ name = '%s.%s' % (c.__module__, c.__name__) for i in range(len(PLUGINS)): if PLUGINS[i] == Null: PLUGINS[i] = c BLATHER('loaded plugin: %s' % name) return BLATHER('could not register %s plugin, need more plugin slots!' % name) # load plugins # import all modules and packages in this directory, each will register itself import os, re modules = [ re.sub('.py$', '', f) for f in os.listdir(__path__[0]) if os.path.isdir(os.path.join(__path__[0], f)) or (f.endswith( '.py') and not f.endswith('_tests.py') and not f == '__init__.py') ] for m in modules: if m.startswith('_'): BLATHER('%s plugin disabled with _ prefix, skipping\n' % m[1:]) else: try: __import__('Products.ZWiki.plugins.%s' % m) except ImportError: BLATHER( 'could not load %s plugin, skipping (traceback follows)\n%s' % (m, formattedTraceback()))
def setupTracker(self, REQUEST=None, pages=0): """ Configure this wiki for issue tracking. This - sets up the necessary extra catalog fields - sets up issue_* folder properties, for customizing - creates a dummy issue, if needed, to activate the issue links/tabs - if pages=1, installs forms as DTML pages, for easy customizing Safe to call more than once; will ignore any already existing items. """ TextIndexes = [] FieldIndexes = [ 'category', 'category_index', 'isIssue', 'issueNumber', 'severity', 'severity_index', 'status', 'status_index', 'issueName' ] KeywordIndexes = [] DateIndexes = [] PathIndexes = [] # make sure we have a basic zwiki catalog set up self.setupCatalog(reindex=0) catalog = self.catalog() catalogindexes, catalogmetadata = catalog.indexes(), catalog.schema() PluginIndexes = catalog.manage_addProduct['PluginIndexes'] # add indexes, for i in TextIndexes: if not i in catalogindexes: PluginIndexes.manage_addTextIndex(i) for i in FieldIndexes: if not i in catalogindexes: PluginIndexes.manage_addFieldIndex(i) for i in KeywordIndexes: if not i in catalogindexes: PluginIndexes.manage_addKeywordIndex(i) for i in DateIndexes: if not i in catalogindexes: PluginIndexes.manage_addDateIndex(i) for i in PathIndexes: if not i in catalogindexes: PluginIndexes.manage_addPathIndex(i) # metadata, # setupCatalog just does this by default now, since # ensureCompleteMetadataIn always tries to fetch all metadata #for m in TRACKER_METADATA: # if not m in catalogmetadata: catalog.manage_addColumn(m) # properties, self.upgradeFolderIssueProperties() # dtml pages, if pages: dir = package_home(globals()) for page in ['IssueTracker', 'FilterIssues', 'IssueBrowser']: if not self.pageWithName(page): self.create(page, text=open(os.path.join(dir, page + '.dtml'), 'r').read(), sendmail=0, type='html') # also, disable subtopics display under IssueTracker self.IssueTracker.setSubtopicsPropertyStatus(0) # index each page, to make all indexes and metadata current # may duplicate some work in setupCatalog n = 0 cid = self.catalog().getId() for p in self.pageObjects(): n = n + 1 BLATHER('indexing page #%d %s in %s' % (n, p.id(), cid)) p.index_object(log=0) BLATHER('indexing complete, %d pages processed' % n) # and a dummy issue to enable site navigation links if not self.hasIssues(): self.createNextIssue( 'first issue', 'This issue was created to activate the issue tracker links/tabs. You can re-use it.', ISSUE_CATEGORIES[-1], ISSUE_SEVERITIES[-1], ISSUE_STATUSES[-1], REQUEST=REQUEST) if REQUEST: REQUEST.RESPONSE.redirect(self.trackerUrl())