# ~*~ coding: utf-8 from Products.Five import BrowserView from zope.publisher.interfaces.browser import IBrowserView from zope.interface import implements from zope.component import getUtility from Products.Korpus.schemas import get_field, get_schema, all from Products.Korpus.utils import translate texttypeclass = get_field('texttype') from Products.Korpus.interfaces import IWWW, ICorpusManager class View(BrowserView): implements(IBrowserView) def __init__(self, context, request): self.request = request self.context = context self.wwwpage = "" def test(self, cond, tru, fal=''): if cond: return tru return fal def getTextTypesHTML(self): return texttypeclass.select(self.request, self.context.getLanguage(self.request)) def getInformantView(self): sc = get_schema(self.context.getMetaSchema()) return sc.view(self.context, self.context.getLanguage(self.request)) def getInformantEdit(self): sc = get_schema(self.context.getMetaSchema()) return sc.edit(self.context, self.context.getLanguage(self.request)) def setPage(self, pname): self.wwwpage = pname def getPage(self): return self.wwwpage def getPageLinks(self): lang = self.context.getLanguage(self.request) w = getUtility(IWWW) return w.getPagesList(lang) def getPortalLanguages(self): return getattr(self.context, 'portallangs', []) class StatisticsView(View): """ statistics view """ def renderStatisticsTable(self): seen = [] res = u"" stats = self.context.compute_stats(self.request) base = self.request.get('base', None) lang = self.context.getLanguage(self.request) fields = [] for s in all(): for f in s.fields: if f.getName() in seen: continue seen.append(f.getName()) fields.append([len(f.choices), f]) fields.sort(reverse=False) x = fields[-1] fields[-1] = fields[-3] fields[-3] = x for num_of_choices, f in fields: tmp = u'
'+f.getTitleI18N(lang)+' | ' tmp += '% | ' tmp += ''+translate(None, 'words', lang)+' | ' tmp += '
---|---|---|
' if not cls: tmp += '' im = f.getChoiceI18N(k, lang) tmp += im if not cls: tmp += '' tmp += ' | ' perc = stats.get(f.getName()+'_'+k+'_perc') if perc is None: perc = 0 word = stats.get(f.getName()+'_'+k+'_word') if word is None: word = 0 tmp += ''+str(perc)+' | ' tmp += ''+str(word)+' | ' tmp += '