Changeset 1373 for Trunk/TurtolCMS/Types/HtmlPage.py
- Timestamp:
- 09/26/09 10:45:22 (3 years ago)
- Files:
-
- 1 modified
-
Trunk/TurtolCMS/Types/HtmlPage.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Trunk/TurtolCMS/Types/HtmlPage.py
r1369 r1373 62 62 req.write ('\n') 63 63 64 class ContentTypeWidget (Asset): 65 def __init__ (self, charset, ctx): 66 Asset.__init__ (self, '', ctx) 67 self._charset = charset 68 self['TurtolCMS.Types.Widget.position'] = 2 69 70 def Render (self, ctx, req): 71 req.write ('''<meta http-equiv="Content-type" content="text/html;charset=%s" />\n''' % self._charset) 72 64 73 class GeneratorWidget (Asset): 65 74 def __init__ (self, close, ctx): … … 90 99 91 100 def Render (self, ctx, req): 92 # FIXME: need baselocation working 93 req.write ('''<div id="tcms_logo"><img src="/tcms/logo.png"/></div>\n''') 101 req.write ('''<div id="tcms_logo"><img src="%s/tcms/logo.png"/></div>\n''' % ctx.BaseLocation()) 94 102 95 103 class HtmlPage (AssetType): … … 109 117 asset['$.layout'] = asset['parent'] 110 118 119 # Set the asset's doctype 120 asset['$.dtd'] = HtmlPage._DocTypes.get (asset['$.doctype'], None) 121 if asset['$.dtd'] is None: 122 asset['$.dtd'] = HtmlPage._DocTypes.get ('html') 123 111 124 asset['$.layercount'] = 1 112 125 while (asset['$.layout.parent']): … … 119 132 120 133 # Calculate our document type 121 asset['$.doctype'] = asset['$.layout'].get ('TurtolCMS.Types.HtmlLayout.docType', ' xml10trans')134 asset['$.doctype'] = asset['$.layout'].get ('TurtolCMS.Types.HtmlLayout.docType', 'html') 122 135 123 136 # Construct an list of widgets broken down by div … … 151 164 pass # TODO: this should be an error, but how to handle? 152 165 166 # Add the content-type widget 167 divs['head'].addWidget (ContentTypeWidget ('UTF-8', ctx)) 153 168 # Add the generator meta widget 154 divs['head'].addWidget (GeneratorWidget (asset['$.doctype'][:3] == 'xml', ctx)) 155 169 divs['head'].addWidget (GeneratorWidget (asset['$.dtd'][2], ctx)) 156 170 # Add the title widget 157 171 divs['head'].addWidget (TitleWidget (asset['$.title'], ctx)) 158 172 159 173 # gather all our widgets and put them into the divs structure 160 # TODO: collect prereqs from our widgets, reduce and insert into head?161 174 iLayer = asset['$.layercount'] 162 175 layer = asset … … 179 192 @staticmethod 180 193 def Head (ctx, req, asset): 181 req.SetResponseHeader ('Content-Type', 'text/html ')194 req.SetResponseHeader ('Content-Type', 'text/html; charset=UTF-8') 182 195 183 196 @staticmethod … … 185 198 layout = asset['$.layout'] 186 199 187 # Set our doctype 188 dtd = HtmlPage._DocTypes.get (asset['$.doctype'], None) 189 if dtd is None: 190 dtd = HtmlPage._DocTypes.get ('xml10trans') 191 req.write (dtd) 200 # write our dtd 201 req.write (asset['$.dtd'][0]) 192 202 193 203 # Open the html 194 if 'xhtml' in dtd: 195 req.write ('''<html xmlns="http://www.w3.org/1999/xhtml">\n''') 196 else: 197 req.write ('''<html>\n''') 204 req.write (asset['$.dtd'][1]) 198 205 199 206 # render each tagged container … … 211 218 # Raw data begins here 212 219 #========================================================================== 213 _DocTypes = { 'xml10trans' : '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 214 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>\n''' 215 , 'xml10strict' : '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 216 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n''' 217 , 'html40strict' : '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 218 "http://www.w3.org/TR/html4/strict.dtd">\n''' 219 , 'html40trans' : '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 220 "http://www.w3.org/TR/html4/loose.dtd">\n''' 220 # _DocTypes lists the "types" of documents we can output 221 # each entry in the dictionary is a tuple of: 222 # (doctype declaration, html open tag, bool: use xml-style tag closes) 223 _DocTypes = { 'html' : ( '''<!DOCTYPE html>\n''' 224 , '''<html>\n''' 225 , False 226 ) 227 , 'xml10trans' : ( '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 228 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>\n''' 229 , '''<html xmlns="http://www.w3.org/1999/xhtml\n''' 230 , True 231 ) 232 , 'xml10strict' : ( '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 233 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n''' 234 , '''<html xmlns="http://www.w3.org/1999/xhtml\n''' 235 , True 236 ) 237 , 'html40strict' : ( '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 238 "http://www.w3.org/TR/html4/strict.dtd">\n''' 239 , '''<html>\n''' 240 , False 241 ) 242 , 'html40trans' : ( '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 243 "http://www.w3.org/TR/html4/loose.dtd">\n''' 244 , '''<html>\n''' 245 , False 246 ) 221 247 } 222 248