def hdfExport(self, prefix, hdf_dataset, *extra, **extranamed): skip_fields = extranamed.get("skip_fields", None) no_escape = extranamed.get("no_escape", None) translate_dict = extranamed.get("translate_dict", None) tz = extranamed.get("tz", "US/Pacific") for col_name, value in self.items(): if skip_fields and (col_name in skip_fields): continue try: name, col_type, col_options = self._table.getColumnDef( col_name) except: col_type = odb.kVarString col_options = {} if (value is not None): if col_options.get("no_export", 0): continue if type(value) in [type(0), type(0L)]: hdf_dataset.setValue(prefix + "." + col_name, "%d" % value) elif type(value) == type(1.0): if int(value) == value: hdf_dataset.setValue(prefix + "." + col_name, "%d" % value) else: hdf_dataset.setValue(prefix + "." + col_name, "%0.2f" % value) else: if col_type == odb.kReal: log("why are we here with this value: %s" % value) if translate_dict: for k, v in translate_dict.items(): value = string.replace(value, k, v) if no_escape and col_name in no_escape: hdf_dataset.setValue(prefix + "." + col_name, str(value)) else: hdf_dataset.setValue(prefix + "." + col_name, neo_cgi.htmlEscape(str(value))) if col_options.get("int_date", 0): hdf_dataset.setValue(prefix + "." + col_name + ".string", renderDate(value)) hdf_dataset.setValue( prefix + "." + col_name + ".day_string", renderDate(value, day=1)) hdf_dataset.setValue( prefix + "." + col_name + ".date_string", renderDate(value, date=1)) if value: try: neo_cgi.exportDate(hdf_dataset, "%s.%s" % (prefix, col_name), tz, value) except TypeError: pass if col_options.has_key("enum_values"): enum = col_options["enum_values"] hdf_dataset.setValue(prefix + "." + col_name + ".enum", str(enum.get(value, '')))
def export_message (self, prefix, hdf, m = None, as_text = 0, attach_str = ""): self._charset = None if m is None: m = self.message hdf.setValue ("%s.charset" % prefix, neo_cgi.htmlEscape(self.charset(m))) h_date = self.decode_header(m, 'date', as_utf8 = 0) if h_date: tup = date.parsedate_tz(h_date) if tup: try: t = date.mktime_tz(tup) hdf.setValue("%s.date_t" % prefix, str(t)) neo_cgi.exportDate(hdf, "%s.h_date" % prefix, self._tz, t) except ValueError: log("Bad Date: %s" % repr(tup)) pass except OverflowError: log("Bad Date: %s" % repr(tup)) pass hdf.setValue ("%s.h_date" % prefix, neo_cgi.htmlEscape(self.decode_header(m, 'date', as_utf8 = 1))) hdf.setValue ("%s.h_from" % prefix, htmlhelp.emailEscape(maskAddr(self.decode_header(m, 'from', as_utf8 = 1)))) hdf.setValue ("%s.h_to" % prefix, htmlhelp.emailEscape(maskAddr(self.decode_header(m, 'to', as_utf8 = 1)))) hdf.setValue ("%s.h_cc" % prefix, htmlhelp.emailEscape(maskAddr(self.decode_header(m, 'cc', as_utf8 = 1)))) hdf.setValue ("%s.h_subject" % prefix, neo_cgi.htmlEscape(self.decode_header(m, 'subject', as_utf8 = 1))) self.export_address_header("%s.addr.from" % prefix, hdf, m, 'from') self.export_address_header("%s.addr.to" % prefix, hdf, m, 'to') self.export_address_header("%s.addr.cc" % prefix, hdf, m, 'cc') self._urls = {} if attach_str: self.embedded_parts(m, attach_str, self._urls) if as_text: body = self.part_as_text (m) body = re.sub("\s([^\s@]+)@([^\s@]+\.[^\s@]+)","\\1@...",body) hdf.setValue("%s.textbody" % prefix,neo_cgi.htmlEscape(body)) else: self.export_part (m, prefix, hdf)
def subclassinit(self): # hardcoded template location! hdf = self.ncgi.hdf hdf.setValue("Config.DebugPassword","1") hdf.setValue("Config.CompressionEnabled","0") hdf.setValue("Config.WhiteSpaceStrip","1") now = int(time.time()) today = time.localtime(now) neo_cgi.exportDate(hdf, "CGI.Today", "US/Pacific", now)
def hdfExport(self, prefix, hdf_dataset, *extra, **extranamed): skip_fields = extranamed.get("skip_fields", None) no_escape = extranamed.get("no_escape", None) translate_dict = extranamed.get("translate_dict", None) tz = extranamed.get("tz", "US/Pacific") for col_name,value in self.items(): if skip_fields and (col_name in skip_fields): continue try: name,col_type,col_options = self._table.getColumnDef(col_name) except: col_type = odb.kVarString col_options = {} if (value is not None): if col_options.get("no_export",0): continue if type(value) in [ type(0), type(0L) ]: hdf_dataset.setValue(prefix + "." + col_name,"%d" % value) elif type(value) == type(1.0): if int(value) == value: hdf_dataset.setValue(prefix + "." + col_name,"%d" % value) else: hdf_dataset.setValue(prefix + "." + col_name,"%0.2f" % value) else: if col_type == odb.kReal: log("why are we here with this value: %s" % value) if translate_dict: for k,v in translate_dict.items(): value = string.replace(value,k,v) if no_escape and col_name in no_escape: hdf_dataset.setValue(prefix + "." + col_name,str(value)) else: hdf_dataset.setValue(prefix + "." + col_name,neo_cgi.htmlEscape(str(value))) if col_options.get("int_date",0): hdf_dataset.setValue(prefix + "." + col_name + ".string",renderDate(value)) hdf_dataset.setValue(prefix + "." + col_name + ".day_string",renderDate(value,day=1)) hdf_dataset.setValue(prefix + "." + col_name + ".date_string",renderDate(value,date=1)) if value: try: neo_cgi.exportDate(hdf_dataset, "%s.%s" % (prefix, col_name), tz, value) except TypeError: pass if col_options.has_key("enum_values"): enum = col_options["enum_values"] hdf_dataset.setValue(prefix + "." + col_name + ".enum", str(enum.get(value,'')))
def subclassinit(self): hdf = self.ncgi.hdf proxy_path = hdf.getValue("HTTP.Soap.Action", "") if proxy_path and not config.gBaseURL.startswith(proxy_path): config.gBaseURL = proxy_path + config.gBaseURL config.gROSURL = proxy_path + config.gROSURL hdf.setValue("Config.CompressionEnabled","1") hdf.setValue("Config.WhiteSpaceStrip","1") self.login = None self.username = None self.db = None self.userRec = None now = int(time.time()) today = time.localtime(now) neo_cgi.exportDate(hdf, "CGI.Today", "US/Pacific", now) self.authdb = db_auth.initSchema() via = hdf.getValue("HTTP.Via", "") if via: #if via.find(":443") != -1: self.http = "https://" hdf.setValue("CGI.Robot", config.get_robot_name()) hdf.setValue("CGI.robot_type", config.get_robot_type()) hostport_prefix = self.http + "%s%s" % (self.domain.split(':')[0], config.gROSBridgePort) hdf.setValue("CGI.hostport_prefix", hostport_prefix) hdf.setValue("CGI.ros_bridge_uri", hostport_prefix + config.gROSURL) hdf.setValue("CGI.home_server", config.gHomeServer) self.getUsername() self.setStyleSheet(hdf) hdf.setValue("CGI.home_page", self.default_app_path()) request_uri = hdf.getValue("CGI.RequestURI", "") if request_uri.startswith(config.gBaseURL): page_name = request_uri[len(config.gBaseURL):].split('?', 1)[0] hdf.setValue("CGI.page_name", page_name)
def hdfExport(self, prefix, hdf, tz="US/Pacific", subj_prefix=None): hdf.setValue(prefix, "1") obj = hdf.getObj(prefix) obj.setValue("doc_id", str(self.doc_id)) obj.setValue("thread_id", str(self.thread_id)) obj.setValue("parent_id", str(self.parent_id)) obj.setValue("next_id", str(self.next_id)) obj.setValue("child_id", str(self.child_id)) if self.date: neo_cgi.exportDate(obj, "date", tz, self.date) subject = self.subject if subj_prefix: subject = subject.replace(subj_prefix, '') obj.setValue("subject", neo_cgi.htmlEscape(subject)) obj.setValue("subject_strip", neo_cgi.htmlEscape(strip_re(subject, subj_prefix=subj_prefix))) obj.setValue("subject_reduced", reduce_subject(subject, subj_prefix=subj_prefix)) obj.setValue("author", neo_cgi.htmlEscape(self.author)) obj.setValue("email", neo_cgi.htmlEscape(self.email)) if self.summary is not None: obj.setValue("summary", neo_cgi.text2html(self.summary)) if self.snippet is not None: obj.setValue("snippet", self.snippet)
def subclassinit(self): # self._pageparms["nologin"] = 1 hdf = self.ncgi.hdf # self.setPaths([config.gTemplatePath]) # hdf.setValue("Query.debug", "1") # hdf.setValue("Config.DebugPassword","1") hdf.setValue("Config.CompressionEnabled", "1") hdf.setValue("Config.WhiteSpaceStrip", "1") self.login = None self.username = None self.db = None self.userRec = None now = int(time.time()) today = time.localtime(now) neo_cgi.exportDate(hdf, "CGI.Today", "US/Pacific", now) self.authdb = db_auth.initSchema() self.getUsername() self.setStyleSheet(hdf)
def display_home(self): self.pagename = "home" # We need the bymonth data, the 5 most recent threads, the top authors # this month and ever # DO NOT CACHE THIS RESULT (it contains read-status info) wrl = self.whichread.getWRList() self.mdb.openByMonth().hdfExport("CGI.ByMonth", self.ncgi.hdf, reverse=1) max_doc, max_thread = self.mdb.counts() for x in range(5): try: mnum = max_doc - x msg = self.mdb.message(mnum) if msg: msg.hdfExport("CGI.RecentMessages.%d" % x, self.ncgi.hdf,subj_prefix=self.subj_prefix, tz=self.tz) if wrl.isRead(mnum): self.ncgi.hdf.setValue("CGI.RecentMessages.%d.doc_id.IsRead" % x, "1") else: self.ncgi.hdf.setValue("CGI.RecentMessages.%d.doc_id.IsRead" % x, "0") except message_db.eNoMessage: pass authors = self.mdb.openAuthorIndex('r') tup = time.localtime(time.time()) date = '%s-%02d' % (tup[0], tup[1]) data = authors.get_top(date) n = 0 self.ncgi.hdf.setValue("CGI.TopAuthors.NowDate", date) for (count, email) in data[:5]: authorRow = authors.get(email) self.ncgi.hdf.setValue("CGI.TopAuthors.Now.%d.email" % n, email) self.ncgi.hdf.setValue("CGI.TopAuthors.Now.%d.name" % n, authorRow.name) self.ncgi.hdf.setValue("CGI.TopAuthors.Now.%d.count" % n, str(count)) n += 1 self.ncgi.hdf.setValue("CGI.TopAuthors.Now", str(n)) data = authors.get_top('total') n = 0 for (count, email) in data[:5]: authorRow = authors.get(email) if authorRow is None: continue self.ncgi.hdf.setValue("CGI.TopAuthors.Total.%d.email" % n, authorRow.email) self.ncgi.hdf.setValue("CGI.TopAuthors.Total.%d.name" % n, authorRow.name) self.ncgi.hdf.setValue("CGI.TopAuthors.Total.%d.count" % n, str(count)) n += 1 self.ncgi.hdf.setValue("CGI.TopAuthors.Total", str(n)) # populate new post info max_doc,max_thread = self.mdb.counts() ranges = [100,250,500] n = 0 for a_range in ranges: if max_doc > a_range: m_num = max_doc-a_range self.ncgi.hdf.setValue("CGI.NewPosts.%d.Range" % n,"%s" % a_range) self.ncgi.hdf.setValue("CGI.NewPosts.%d.doc_id" % n,"%s" % m_num) try: meta = self.mdb.message(m_num) neo_cgi.exportDate(self.ncgi.hdf, "CGI.NewPosts.%d.Date" % n, self.tz, meta.date) n = n + 1 except message_db.eNoMessage: pass # populate last-visit info visit_last = self.ncgi.hdf.getValue("Cookie.%s.visit_last" % self.listname,"") if visit_last: max_doc, max_thread = self.mdb.counts() valid = 1 try: time_t,o_max_doc,o_max_thread = string.split(visit_last,":") except: valid = 0 if valid: self.ncgi.hdf.setValue("CGI.LastVisit.NewMessages","%s" % (max_doc-int(o_max_doc))) self.ncgi.hdf.setValue("CGI.LastVisit.NewThreads","%s" % (max_thread-int(o_max_thread))) neo_cgi.exportDate(self.ncgi.hdf, "CGI.LastVisit.Date", self.tz, int(time_t))