pages.py

Go to the documentation of this file.
00001 __copyright__ = """\
00002 (c). Copyright 1990-2008, Vyper Logix Corp., 
00003 
00004                    All Rights Reserved.
00005 
00006 Published under Creative Commons License 
00007 (http://creativecommons.org/licenses/by-nc/3.0/) 
00008 restricted to non-commercial educational use only., 
00009 
00010 See also: http://www.VyperLogix.com and http://www.pypi.info for details.
00011 
00012 THE AUTHOR VYPER LOGIX CORP DISCLAIMS ALL WARRANTIES WITH REGARD TO
00013 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
00014 FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
00015 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
00016 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00017 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
00018 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
00019 
00020 USE AT YOUR OWN RISK.
00021 """
00022 
00023 from django.template.loader import get_template
00024 from django.template import Context
00025 from django.http import HttpResponse
00026 
00027 from vyperlogix import misc
00028 from vyperlogix.misc import ObjectTypeName
00029 
00030 import os
00031 import time
00032 import datetime
00033 
00034 from vyperlogix.html import myOOHTML as oohtml
00035 
00036 template_filename = lambda template_folder,fname:'%s%s%s' % (template_folder,os.sep if (len(template_folder) > 0) else '',fname)
00037 
00038 def formatTimeStr():
00039     return '%m/%d/%Y %H:%M:%S'
00040 
00041 def formatYYYYStr():
00042     return '%Y'
00043 
00044 def formatMetaDateTimeStr():
00045     return '%a, %d %b %Y %H:%M:%S'
00046 
00047 def get_tabs_nav_html(navigation_tabs,request=None,content=''):
00048     h = oohtml.Html()
00049     ul = h.tag(oohtml.oohtml.UL)
00050     i = 1
00051     request_path = request.path if (ObjectTypeName.typeClassName(request).find('django.core.handlers.wsgi.WSGIRequest') > -1) else ''
00052     for tab in navigation_tabs:
00053         _url, _text1, _text2 = tab
00054         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 ''))
00055         i += 1
00056     ul._tagLI(content if (misc.isString(content)) else '')
00057 
00058     return h.toHtml()
00059 
00060 def get_tabs_nav_content_html(navigation_tabs):
00061     h = oohtml.Html()
00062     i = 1
00063     for tab in navigation_tabs:
00064         _url, _text1, _text2 = tab
00065         div = h.tag(oohtml.oohtml.DIV, id='sb%d'%i, class_="tabcontent")
00066         span = div.tag(oohtml.oohtml.SPAN, class_="tabTitle")
00067         span.text(_text2)
00068         i += 1
00069 
00070     return h.toHtml()
00071 
00072 ##
00073 # 
00074 #     request is the Django request.
00075 #     _title is the title for the site.
00076 #     template_name is the template filename for the body of the content, may be a partial.
00077 #     navigation_menu_type is the tabs menu type for the site navigation bar.
00078 #     navigation_tabs is the list of tabs.
00079 #     context is the Context for the main body of the site per the template_name.
00080 #     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)
00081 #     
00082 def _render_the_page(request,_title,template_name,navigation_menu_type,navigation_tabs,styles_context={},context={},footer_context={},template_folder='',js=[],head=[]):
00083     import urllib
00084 
00085     from vyperlogix.misc import _utils
00086     from vyperlogix.django import tabs
00087     
00088     now = _utils.timeStamp(format=formatTimeStr())
00089     _yyyy = _utils.timeStamp(format=formatYYYYStr())
00090 
00091     url_toks = [urllib.unquote_plus(t) for t in request.path.split('/') if (len(t) > 0)]
00092 
00093     h = oohtml.Html()
00094     try:
00095         for j in js:
00096             h.tagSCRIPT(src=j)
00097     except:
00098         pass
00099     js_head = h.toHtml()
00100 
00101     styles_content = ''
00102     if (styles_context.has_key('ADDITIONAL_JS')):
00103         styles_content = styles_context['ADDITIONAL_JS']
00104     else:
00105         styles_context['ADDITIONAL_JS'] = styles_content
00106     styles_content = '%s%s' % (js_head,styles_content)
00107     styles_context['ADDITIONAL_JS'] = styles_content
00108         
00109     t_styles = get_template(template_filename(template_folder,'_styles.html'))
00110     html_styles = t_styles.render(Context(styles_context))
00111 
00112     t_tabs_header = get_template(template_filename(template_folder,'_tabs_header.html'))
00113     c = Context({'id':tabs.tab_num_from_url(url_toks[0] if (len(url_toks) > 0) else '/',navigation_tabs)})
00114     c.update(styles_context)
00115     html_tabs_header = t_tabs_header.render(c)
00116 
00117     head_content = ''
00118     try:
00119         for item in head:
00120             head_content += item
00121     except:
00122         pass
00123     
00124     _delta = datetime.timedelta(days=365.25*20)
00125     _dt = datetime.datetime.fromtimestamp(time.time())
00126     _expires_time = _dt - _delta
00127     _expires_ts = time.strftime(formatMetaDateTimeStr(),_expires_time.timetuple())
00128     _last_modified_ts = time.strftime(formatMetaDateTimeStr(),_dt.timetuple())
00129 
00130     t_header = get_template(template_filename(template_folder,'_header_for_content.html'))
00131     c = Context({'the_title': '%s (%s)' % (_title,now),
00132                  'STYLES_CONTENT':html_styles,
00133                  'TABS_HEADER':html_tabs_header+head_content,
00134                  'EXPIRES_TIME':_expires_ts,
00135                  'LAST_MODIFIED':_last_modified_ts
00136                  })
00137     c.update(context)
00138     html_header = t_header.render(c)
00139     
00140     t_footer = get_template(template_filename(template_folder,'_footer_for_content.html'))
00141     c = Context({'current_year': _yyyy})
00142     c.update(footer_context)
00143     html_footer = t_footer.render(c)
00144 
00145     t_content = get_template(template_name)
00146     html_content = t_content.render(Context(context))
00147     
00148     t_tabs_content = get_template(template_filename(template_folder,'_tabs_content.html'))
00149     html_tabs_content = t_tabs_content.render(Context({'MENU_TYPE':navigation_menu_type,
00150                                                        'NAVIGATION_TABS':get_tabs_nav_html(navigation_tabs),
00151                                                        'NAVIGATION_CONTENT':get_tabs_nav_content_html(navigation_tabs)
00152                                                        }))
00153     
00154     t = get_template(template_filename(template_folder,'site_content_template.html'))
00155     c = Context({'current_year': _yyyy,
00156                  'the_title': _title,
00157                  'HEADER_FOR_CONTENT':html_header,
00158                  'FOOTER_FOR_CONTENT':html_footer,
00159                  'CONTENT':html_content,
00160                  'TABS_CONTENT':html_tabs_content
00161                  })
00162     html = t.render(c)
00163     return html
00164 
00165 ##
00166 # 
00167 #     request is the Django request.
00168 #     _title is the title for the site.
00169 #     template_name is the template filename for the body of the content, may be a partial.
00170 #     navigation_menu_type is the tabs menu type for the site navigation bar.
00171 #     navigation_tabs is the list of tabs.
00172 #     context is the Context for the main body of the site per the template_name.
00173 #     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)
00174 #     
00175 def render_the_page(request,_title,template_name,navigation_menu_type,navigation_tabs,styles_context={},context={},footer_context={},template_folder='',js=[],head=[]):
00176     return HttpResponse(_render_the_page(request,_title,template_name,navigation_menu_type,navigation_tabs,styles_context=styles_context,context=context,footer_context=footer_context,template_folder=template_folder,js=js,head=head))
00177 
00178 def _render_the_template(request,_title,template_name,context={},template_folder=''):
00179     t_page = get_template(template_filename(template_folder,template_name))
00180     html_page = t_page.render(Context(context, autoescape=False))
00181     return html_page
00182 
00183 def render_the_template(request,_title,template_name,context={},template_folder=''):
00184     s = _render_the_template(request,_title,template_name,context=context,template_folder=template_folder)
00185     return HttpResponse(s,mimetype='text/html')
00186 
00187 if (__name__ == '__main__'):
00188     import sys
00189     print >>sys.stdout, __copyright__
00190     print >>sys.stderr, __copyright__
00191 
00192 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...