# ~*~ 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'' tmp += '' tmp += '' tmp += '' tmp += '' tmp += '' for k, v in f.choices.items(): cls = '' if base is not None: if base == f.getName()+'_'+k: cls = ' class="viewPoint"' 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 += '' tmp += '' tmp += '' tmp += '
'+f.getTitleI18N(lang)+'%'+translate(None, 'words', lang)+'
' if not cls: tmp += '' im = f.getChoiceI18N(k, lang) tmp += im if not cls: tmp += '' tmp += ''+str(perc)+''+str(word)+'
' res += tmp return res class SearchView(View): """ search view """ def renderSearchForm(self): """ render search form """ res = u"" lang = self.context.getLanguage(self.request) fc = 0 seen = [] for s in all(): res += '\n' for f in s.fields: if f.getName() in seen: continue seen.append(f.getName()) fc = fc + 1 if fc == 3: res += '\n\n' fc = 1 res += '\n' res += f.getTitleI18N(lang) res += '\n' res += '\n' res += f.select(trLang = lang) res += '\n' res += '\n' return res class DocumentsView(View): def listDocus(self): d = ['document_1', 'document_2'] return '\n'.join(d) def getSchemas(self): return all() def getCorpuses(self): cm = getUtility(ICorpusManager) return cm.getCorpuses()