def renderHTML(self, subj, body): from vyperlogix.html import myOOHTML as oohtml h_html = oohtml.Html() if (misc.isString(subj)) and (misc.isList(body)): h_html.text(oohtml.oohtml.DOCTYPE_40_TRANSITIONAL) html_html = h_html.tag(oohtml.oohtml.HTML) head_html = html_html.tag(oohtml.oohtml.HEAD) head_html.tagOp(oohtml.oohtml.META, http_equiv=oohtml.oohtml.CONTENT_TYPE, content=oohtml.oohtml.TEXT_HTML_CHARSET_ISO_8859_1) head_html.metas(( oohtml.oohtml.AUTHOR, "Ray C Horn ([email protected])" ), (oohtml.oohtml.KEYWORDS, "SMTP Email Message"), ( oohtml.oohtml.DESCRIPTION, "The contents of this email are considered to be confidential unless otherwise specified." ), (oohtml.oohtml.ROBOTS, oohtml.oohtml.ALL)) head_html.tagTITLE('SMTP Email Message') body_html = html_html.tag(oohtml.oohtml.BODY) idContent = body_html.tag(oohtml.oohtml.DIV, id="content", style="background-color: white") idContent.html_simple_table(body) pass else: print >> sys.stderr, '%s :: "subj" parm must be of type str and "body" parm must be of type list rather than of types "%s" and "%s", respectively.' % ( ObjectTypeName.objectSignature(self), type(subj), type(body)) return h_html.toHtml()
def render_list_as_table(aList=[]): rows = [] h = oohtml.Html() for item in aList: rows.append(item) h.html_simple_table([[row] if (not isinstance(row, list)) else row for row in rows], width='100%') return h.toHtml()
def rss_content(url, source_domain='', target_domain=''): import urllib from vyperlogix.rss import reader from vyperlogix.html import myOOHTML as oohtml from vyperlogix import misc try: rss = reader.read_feed_links(url) except Exception as e: rss = [['CANNOT ACCESS NEWS FEED :: %s' % (str(e)), url, '']] toks = list(urllib.splitquery(url)) u = 'http://' + toks[0].split('http://')[-1].split('/')[0] if (len(source_domain) > 0) and (len(target_domain) > 0): u = u.replace(source_domain, target_domain) link = oohtml.renderAnchor(u, u) items = [['<h3 align="center">%s</h3>' % (link)]] h = oohtml.Html() if (misc.isList(rss)): try: ul = h.tag(oohtml.oohtml.UL) for item in rss: if (len(source_domain) > 0) and (len(target_domain) > 0): item[1] = item[1].replace(source_domain, target_domain) rss_link = oohtml.renderAnchor('%s' % (item[1]), item[0]) words = item[2].split() item[2] = ' '.join(words[0:0]) ul._tagLI('%s<br/><small>%s</small>' % (rss_link, '<br/>'.join(item[2:]))) except: h.tagTEXTAREA('ERROR: %s' % (rss), rows=10, cols=80) else: h.tagTEXTAREA('ERROR: %s' % (rss), rows=10, cols=80) items += [[h.toHtml()]] h = oohtml.Html() h.html_simple_table(items) content = h.toHtml() return content
def get_tabs_nav_content_html(navigation_tabs): h = oohtml.Html() i = 1 for tab in navigation_tabs: _url, _text1, _text2 = tab div = h.tag(oohtml.oohtml.DIV, id='sb%d' % i, class_="tabcontent") span = div.tag(oohtml.oohtml.SPAN, class_="tabTitle") span.text(_text2) i += 1 return h.toHtml()
def renderBody(_body): h = oohtml.Html() h_html = h.tag(oohtml.oohtml.HTML) h_body = h_html.tag(oohtml.oohtml.BODY) h_Content = h_body.tag(oohtml.oohtml.DIV, id="content", style="background-color: white") _body = _body[0] if (misc.isList(_body)) and (len(_body) == 1) else _body h_Content.text(_body[0]) if (len(_body) > 1): for b in _body[1:]: h_Content.tagOp(oohtml.oohtml.BR) h_Content.text(b) return h_Content.toHtml()
def get_tabs_nav_html(navigation_tabs, request=None, content=''): h = oohtml.Html() ul = h.tag(oohtml.oohtml.UL) i = 1 request_path = request.path if (ObjectTypeName.typeClassName(request).find( 'django.core.handlers.wsgi.WSGIRequest') > -1) else '' for tab in navigation_tabs: _url, _text1, _text2 = tab ul._tagLI( oohtml.renderAnchor('%s' % _url, _text1, target="_blank" if (_url.find('://') > -1) else "_top", rel='sb%d' % i, class_='selected' if (_url == request_path) else '')) i += 1 ul._tagLI(content if (misc.isString(content)) else '') return h.toHtml()
def renderHTML(self, subj, body): from vyperlogix.html import myOOHTML as oohtml h_html = oohtml.Html() def renderBody(_body): h = oohtml.Html() h_html = h.tag(oohtml.oohtml.HTML) h_body = h_html.tag(oohtml.oohtml.BODY) h_Content = h_body.tag(oohtml.oohtml.DIV, id="content", style="background-color: white") _body = _body[0] if (misc.isList(_body)) and (len(_body) == 1) else _body h_Content.text(_body[0]) if (len(_body) > 1): for b in _body[1:]: h_Content.tagOp(oohtml.oohtml.BR) h_Content.text(b) return h_Content.toHtml() if (not misc.isString(subj)): subj = str(subj) if (not misc.isList(body)): body = [body] if (misc.isString(subj)) and (misc.isList(body)): h_html.text(oohtml.oohtml.DOCTYPE_40_TRANSITIONAL) _title = "Vyper Logix SMTP Email Proxy (%s v.%s)" % ( ObjectTypeName.typeName(self), __version__) html_html = h_html.tag(oohtml.oohtml.HTML) head_html = html_html.tag(oohtml.oohtml.HEAD) head_html.tagOp(oohtml.oohtml.META, http_equiv=oohtml.oohtml.CONTENT_TYPE, content=oohtml.oohtml.TEXT_HTML_CHARSET_ISO_8859_1) head_html.metas(( oohtml.oohtml.AUTHOR, '%s :: %s' % (self.author, self.__author__) ), (oohtml.oohtml.KEYWORDS, _title), ( oohtml.oohtml.DESCRIPTION, "The contents of this email are considered to be confidential unless otherwise specified." ), (oohtml.oohtml.ROBOTS, oohtml.oohtml.ALL)) head_html.tagTITLE( '©%s, Vyper Logix Corp., All Rights Reserved., %s' % (_utils.timeStamp(format=_utils.formatDate_YYYY()), _title)) body_html = html_html.tag(oohtml.oohtml.BODY) idContent = body_html.tag(oohtml.oohtml.DIV, id="content", style="background-color: white") rows = [] rows.append(tuple(['%s' % (subj)])) rows.append(tuple([renderBody(body)])) rows.append(tuple(['<BR/><BR/><BR/><BR/>'])) rows.append( tuple([ self.copyright if (misc.isString(self.copyright)) and (len(self.copyright) > 0) else self.__copyright__ ])) idContent.html_table(rows) pass else: logMessage( 'subj must be of type str and body must be of type list rather than of types "%s" and "%s", respectively.' % (type(subj), type(body)), ObjectTypeName.typeName(self), misc.funcName(), _logging=standardLogging.LoggingLevels.warning) return h_html.toHtml()
def as_html(self, request=None, width='100%', max_length=40, context={}): h = oohtml.Html() _no_show_fields = [] _action = self.action.split('/') for k, v in self.__hidden_fields__.iteritems(): if (str(v).isdigit()) and (int(v) > -1): _action.insert( len(_action) - (1 if (_action[-1] == '') else 0), '%s' % (v)) else: _no_show_fields.append(k) form = h.tag(oohtml.oohtml.FORM, name=self.form_name, id="%sForm" % (self.form_name), target=self.target, action='/'.join(_action), enctype="application/x-www-form-urlencoded", method="post") _remaining_fields = list( set(self.fields.keyOrder) - set(self.__field_ordering__) - set(_no_show_fields)) for k in self.__field_ordering__ + _remaining_fields: _k = "VALUE_%s" % (k.upper()) v = self.fields[k] _is_BooleanField = self.is_BooleanField(v) _is_DateTimeField = self.is_DateTimeField(v) _tr = form.tag(oohtml.oohtml.TR) _th = _tr.tag(oohtml.oohtml.TH, width="*", align="right") _nobr = _th.tagNOBR() _nobr.tagLABEL('id_%s' % k, '%s: ' % (v.label)) _td = _tr.tag(oohtml.oohtml.TD, align="left") ds = self.get_datasource_for_field_by_name(k) if (self.is_ModelChoiceField(v)) or (_is_BooleanField): _value_id = 'value' _text_id = 'text' choice_model = self.get_choice_model_for_field_by_name(k) if (choice_model is not None): _value_id = choice_model.value_id _text_id = choice_model.text_id else: try: keys = [ kk for kk in v.queryset[0].__dict__.keys() if (kk != 'version') ] for kk, vv in v.queryset[0].__dict__.iteritems(): if (kk in keys): if (misc.isString(vv)): _text_id = kk else: _value_id = kk if (len(_value_id) > 0) and (len(_text_id) > 0): break except: # possibly there is no data to populate so we do nothing here... pass _selected = self.get_choice_model_default_for_field_by_name(k) _selected = _selected if ( not context.has_key(_k)) else context[_k] _selected = _selected if (_selected is not None) else '' if (len(_selected) == 0) and (request is not None): _selected = request.POST[k] oohtml.render_select_content( v.queryset if (not _is_BooleanField) else [{ 'value': 'True', 'text': 'True' }, { 'value': 'False', 'text': 'False' }], tag=_td, id='id_%s' % (k), name=k, text_id=_text_id, value_id=_value_id, defaultChoose=True, selected=_selected) elif (_is_DateTimeField): _td.tagDIV( django_utils.render_from_string( self.datetime_field_content, context=context) + ' * Required' if ( v.required) else '') v.required = False elif (callable(ds)): oohtml.render_select_content( ds(), tag=_td, id='id_%s' % (k), name=k, text_id=_text_id, value_id=_value_id, defaultChoose=True, selected=self.get_choice_model_default_for_field_by_name( k)) else: _max_length = max_length try: _max_length = min(v.max_length, max_length) except: # Account for differences between various Django releases in this regard. pass _td.tagOp(oohtml.oohtml.INPUT, type=oohtml.oohtml.TEXT, name=k, size=_max_length, maxlength=_max_length, value="{{ %s }}" % (_k)) l = [] if (v.required): l.append('* Required') try: if (v.min_length) and (not self.is_ModelChoiceField(v)): l.append(' minimum %d chars' % (v.min_length)) except: pass _td.tagSPAN(' %s%s{{ ERROR_%s }}%s' % ('(' if (len(l) > 0) else '', ','.join(l), k.upper(), ')' if (len(l) > 0) else '')) tr = form.tag(oohtml.oohtml.TR) td = tr.tag(oohtml.oohtml.TD, align="left", colspan="2") if (misc.isString(self.captcha_form_name)) and (misc.isString( self.captcha_font_name)): td.tagDIV( captcha.render_captcha_form(self.request, form_name=self.captcha_form_name, font_name=self.captcha_font_name, font_size=self.captcha_font_size, choices=self.captcha_choices, fill=self.captcha_fill, bgImage=self.captcha_bgImage)) tr = form.tag(oohtml.oohtml.TR) td = tr.tag(oohtml.oohtml.TD, align="center", colspan="2") td.tagSUBMIT(self.submit_button_title, value=self.submit_button_value, onclick="this.disabled=true;") return h.toHtml()
def paginate(items, items_name, selector, pageNo=1, numPerPage=10, maxPages=15, callback=None): from vyperlogix.html import myOOHTML as oohtml def navigate_pages(): articles.append(['<hr align="left" color="silver" width="80%"/>']) articles.append(['<h3>More %s...</h3>' % (items_name)]) _get_page_link_ = lambda pg, n, m: oohtml.renderAnchor('%s' % ( '/%s/%s/%s/%d/' % (selector, m, pg, numPerPage)), n, target='_top') _get_page_link = lambda pg, n: _get_page_link_(pg, n, 'page') get_page_link = lambda pg: _get_page_link(pg.replace('+', ''), pg) pageLinks = [ oohtml.renderAnchor('%s' % ('/%s/%s/%s/%d/' % (selector, 'page', 1, numPerPage)), 'Start', target='_top') if (pageNo > 1) else 'Start', oohtml.renderAnchor('%s' % ('/%s/%s/%s/%d' % (selector, 'page', pageNo - 1, numPerPage)), 'Prev', target='_top') if (pageNo > 1) else 'Prev' ] r = [ '%d' % (i) for i in xrange( pageNo, totalPages + 1 if (pageNo > totalPages - numPerPage) else pageNo + numPerPage) ] if (len(r) < numPerPage): pg = pageNo - (numPerPage - len(r)) if (pg < 1): pg = 1 r = ['%d' % (i) for i in xrange(pg, pageNo)] + r isAtEnd = False if (int(r[-1]) < totalPages): r[-1] = '%s+' % (r[-1]) else: isAtEnd = True pageLinks += [ get_page_link(i) if (int(i.replace('+', '')) != pageNo) else '%s' % (i) for i in r ] pageLinks += [ _get_page_link_(pageNo + 1, 'Next', 'next') if (pageNo < totalPages) else 'Next', _get_page_link(totalPages, 'End') if (not isAtEnd) else 'End' ] delim = ' ' * 5 articles.append(['<small>%s</small>' % (delim.join(pageLinks))]) articles.append([ '<center><small>Page %d of %d</small></center>' % (pageNo, totalPages) ]) articles.append(['<hr align="left" color="silver" width="80%"/>']) h = oohtml.Html() articles = [] totalNum = len(items) totalPages = (totalNum / numPerPage) + (1 if ( (totalNum % numPerPage) > 0) else 0) if (totalNum > numPerPage): navigate_pages() iBegin = (pageNo - 1) * numPerPage iEnd = iBegin + numPerPage for item in items[iBegin:iEnd]: try: if (callable(callback)): callback(item, articles, items_name, selector) except Exception as details: info_string = _utils.formattedException(details=details) return info_string if (totalNum > numPerPage): navigate_pages() h.html_simple_table(articles) content = h.toHtml() return content
def _render_the_page(request, _title, template_name, navigation_menu_type, navigation_tabs, styles_context={}, context={}, footer_context={}, template_folder='', js=[], head=[]): ''' request is the Django request. _title is the title for the site. template_name is the template filename for the body of the content, may be a partial. navigation_menu_type is the tabs menu type for the site navigation bar. navigation_tabs is the list of tabs. context is the Context for the main body of the site per the template_name. template_folder is the prefix for the folder in which the templates reside. (template_name may reside in a different folder than the rest of the templates) ''' import urllib from vyperlogix.misc import _utils from vyperlogix.django import tabs now = _utils.timeStamp(format=formatTimeStr()) _yyyy = _utils.timeStamp(format=formatYYYYStr()) url_toks = [ urllib.unquote_plus(t) for t in request.path.split('/') if (len(t) > 0) ] h = oohtml.Html() try: for j in js: h.tagSCRIPT(src=j) except: pass js_head = h.toHtml() styles_content = '' if (styles_context.has_key('ADDITIONAL_JS')): styles_content = styles_context['ADDITIONAL_JS'] else: styles_context['ADDITIONAL_JS'] = styles_content styles_content = '%s%s' % (js_head, styles_content) styles_context['ADDITIONAL_JS'] = styles_content t_styles = get_template(template_filename(template_folder, '_styles.html')) html_styles = t_styles.render(Context(styles_context)) t_tabs_header = get_template( template_filename(template_folder, '_tabs_header.html')) c = Context({ 'id': tabs.tab_num_from_url(url_toks[0] if (len(url_toks) > 0) else '/', navigation_tabs) }) c.update(styles_context) html_tabs_header = t_tabs_header.render(c) head_content = '' try: for item in head: head_content += item except: pass _delta = datetime.timedelta(days=365.25 * 20) _dt = datetime.datetime.fromtimestamp(time.time()) _expires_time = _dt - _delta _expires_ts = time.strftime(formatMetaDateTimeStr(), _expires_time.timetuple()) _last_modified_ts = time.strftime(formatMetaDateTimeStr(), _dt.timetuple()) t_header = get_template( template_filename(template_folder, '_header_for_content.html')) c = Context({ 'the_title': '%s (%s)' % (_title, now), 'STYLES_CONTENT': html_styles, 'TABS_HEADER': html_tabs_header + head_content, 'EXPIRES_TIME': _expires_ts, 'LAST_MODIFIED': _last_modified_ts }) c.update(context) html_header = t_header.render(c) t_footer = get_template( template_filename(template_folder, '_footer_for_content.html')) c = Context({'current_year': _yyyy}) c.update(footer_context) html_footer = t_footer.render(c) t_content = get_template(template_name) html_content = t_content.render(Context(context)) t_tabs_content = get_template( template_filename(template_folder, '_tabs_content.html')) html_tabs_content = t_tabs_content.render( Context({ 'MENU_TYPE': navigation_menu_type, 'NAVIGATION_TABS': get_tabs_nav_html(navigation_tabs), 'NAVIGATION_CONTENT': get_tabs_nav_content_html(navigation_tabs) })) t = get_template( template_filename(template_folder, 'site_content_template.html')) c = Context({ 'current_year': _yyyy, 'the_title': _title, 'HEADER_FOR_CONTENT': html_header, 'FOOTER_FOR_CONTENT': html_footer, 'CONTENT': html_content, 'TABS_CONTENT': html_tabs_content }) html = t.render(c) return html