lkcl / pyjamas-desktop

Google's Webkit, ported to Python, ported to Desktops.

This URL has Read+Write access

pyjamas-desktop / pyjamas-web / mainpage.py
ac478c87 » lkcl 2008-09-05 first revision of pyjamas-w... 1 __access__ = 0
2
3 from urllib import urlencode, quote_plus, quote
4 from copy import copy
5 from lxml import etree
6
7 import sys
8 sys.path.append("/home/lkcl/src/pyjamas-desktop/pyjamas-web/library")
9
26ca332d » lkcl 2008-09-05 hello world works! 10 from __pyjamas__ import init_doc, doc, doc_process
ac478c87 » lkcl 2008-09-05 first revision of pyjamas-w... 11
12 #this is the folderish class that manages ZODB-based chats
13 class ZCTmainpage:
14 """ ZCT main page.
15 """
16
17 def index(self, REQUEST):
18 """ returns the index page
19 """
20
84d19eb7 » lkcl 2008-09-05 grid test partially working 21 #sys.path.append("/home/lkcl/src/pyjamas-desktop/pyjamas-web/examples/helloworld/")
22 #from Hello import Hello
23 #init_doc("/home/lkcl/src/pyjamas-desktop/pyjamas-web/examples/helloworld/Hello.html")
24 #m = Hello()
25 sys.path.append("/home/lkcl/src/pyjamas-desktop/pyjamas-web/examples/gridtest/")
26 from GridTest import GridTest
27 init_doc("/home/lkcl/src/pyjamas-desktop/pyjamas-web/examples/gridtest/GridTest.html")
28 m = GridTest()
de9c54ad » lkcl 2008-09-06 pickling experiment 29 return doc_process(GridTest, REQUEST)
ac478c87 » lkcl 2008-09-05 first revision of pyjamas-w... 30
31 def registerpage(self, REQUEST):
32 """ returns the register page, which comprises
33 three sections - leftbit, rightbit, mainbit.
34 i've removed mainbit (it used to contain introsearch).
35 """
36
37 links = { 'leftbit': 'registerwelcome',
38 'rightbit': 'register'
39 }
40
41 page = self.tmpl('registerpage')
42 page.staticlink(links)
43
44 return page
45
46 def footer(self, REQUEST):
47
48 loggedin = self.login_check()
49
50 if loggedin:
51 target = 'centercontent'
52 else:
53 target = 'maincontent'
54
55 options = { \
56 'copyright': ("mainmenulink", "copyright", target, "Copyright"),
57 'termsconditions': ("mainmenulink", "termsnconditions", target, "Terms and Conditions"),
58 'faq': ("mainmenulink", "faq", target, "FAQ"),
59 'privacy': ("mainmenulink", "privacy", target, "Privacy"),
60 'contact': ("mainmenulink", "contact", target, "Contact Us"),
61 }
62
63 page = self.tmpl('footer', REQUEST)
64 page.dynamiclink(options)
65
66 return page
67
68 def menu(self, REQUEST):
69
70 loggedin = False #self.login_check()
71
72 if loggedin:
73 target = 'centercontent'
74 else:
75 target = 'maincontent'
76
77 options = { \
78 'veggies': ("mainmenulink", "veggies", target, "Veggies"),
79 'besafe': ("mainmenulink", "besafe", target, "Be Safe!"),
80 'faq': ("mainmenulink", "faq", target, "FAQ"),
81 #'legal': ("mainmenulink", "legal", target, "Legal"),
82 #'privacy': ("mainmenulink", "privacy", target, "Privacy"),
83 #'about': ("mainmenulink", "about", target, "About Us"),
84 'register_hurrah': ("mainmenulink", "registerpage", target, "Join our Community!")
85 }
86
87 if False: #self.login_check():
88 REQUEST['loggedin'] = '1'
89
90 more = { \
91 'home': ("mainmenulink", "userhome", target, "Home"),
92 'search': ("mainmenulink", "search", target, "Search"),
93 'profile': ("mainmenulink", "profile", target, "Profile"),
94 'logout': ("mainmenulink", "logout", target, "Logout")}
95
96 else:
97 more = { \
98 'home': ("mainmenulink", "home", target, "Home"),
99 'register': ("mainmenulink", "registerpage", target, "Register Free"),
100 'login': ("mainmenulink", "login", target, "Member Login"),
101 'about': ("mainmenulink", "about", target, "About Us"),
102 }
103
104 options.update(more)
105
106 links = { 'adcontent': 'menuads' }
107
108 menu_page = self.tmpl('menu', REQUEST)
109 menu_page.staticlink(links)
110 menu_page.dynamiclink(options)
111
112 return menu_page
113
114 def logincontext(self, REQUEST):
115
116 links = { 'messagesmenu': ('messagesunexpand', 'submenustyle') ,
117 'forumsmenu': ('forumsunexpand', 'submenustyle') }
118
119 options = { \
120 'search': ("mainmenulink", "search", "centercontent", "By Profile"),
121 'usersearch': ("mainmenulink", "usersearch", "centercontent", "Find User"),
122 'tagsearch': ("mainmenulink", "tagsearch", "centercontent", "Experimental"),
123 'profile': ("mainmenulink", "profile", "centercontent", "Update"),
124 'uploadimage': ("mainmenulink", "uploadimage", "centercontent", "Upload Picture"),
125 'images': ("mainmenulink", "profileimages", "centercontent", "Pictures"),
126 'profilecomms': ("mainmenulink", "profilecomms", "centercontent", "Options"),
127 'profilecomms': ("mainmenulink", "profilecomms", "centercontent", "Options"),
128 }
129
130 login_page = self.tmpl('logincontext', REQUEST)
131 login_page.dynamiclink(options)
132 login_page.staticlink(links)
133 return login_page
134
135 def context(self, REQUEST):
136 search = str(self.tmpl('quicksearchform', {}))
137 REQUEST['searchform'] = search
138 return str(self.tmpl('context', REQUEST))
139
140 def userhome(self, REQUEST):
141
142 options = { \
143 'search': ("", "search", "centercontent", "search"),
144 'update': ("", "profile", "centercontent", "update")
145 }
146
147 sessionkey = self.get_session_info()
148 res = self.db.check_session(sessionkey)
149 if res:
150 username, userid = res
151 else:
152 userid = None
153 if userid:
154 REQUEST['username'] = username
155 count = int(self.db.s.message(to=userid,read=0).count())
156 if count:
157 REQUEST['unreadinboxcount'] = count
158 REQUEST['messageword'] = 'messages'
159 if count == 1:
160 REQUEST['messageword'] = 'message'
161
162 options['messages'] = \
163 ("", "inbox", "centercontent", REQUEST['messageword'])
164
165 page = self.tmpl('userhome', REQUEST)
166 page.dynamiclink(options)
167 return page
168
169 def imagetestpage(self, REQUEST):
170 """ returns an image test page
171 """
172
173 d = {}
174 d['zoom_window'] = 'zoom_window'
175 d['zoom_frame'] = 'zoom_frame'
176 d['frame_width'] = '400'
177 d['frame_height'] = '300'
178 d['frame_image'] = 'Visionary_jpg'
179
180 frame_popup = self.tmpl('frame_popup', d)
181
182 index_page = self.tmpl('imagetestpage')
183 index_page['frame_popup_test'] = frame_popup
184
185 return str(index_page)
186
187 def home(self, REQUEST):
188 """ displays the anonymous main home page content.
189 this page is a little odd because it uses an
190 actual web-page function (searchresultspage) and
191 sploshes the content into the home page.
192
193 i've removed "mainbit" - the introsearch.
194 """
195
196 links = { 'leftbit': 'homewelcome',
197 'rightbit': 'login'
198 }
199
200 page = self.tmpl('home')
201 page.staticlink(links, override=1)
202
203 return page
204
205 def mainads(self, REQUEST):
206
207 url = REQUEST.get('url', 'vegetarian dating for marriage')
208 d = {}
209 d['loc'] = quote(self.req.uri)
210 d['documenturl'] = quote(url)
211
212 i = self.get_useful_info()
213 if i.get("screenwidth", 630) > 820:
214 d['wide_ads'] = 1
215
216 return str(self.tmpl('mainads', d))
217
218 def advertising(self, REQUEST):
219 url = REQUEST.get('url', 'vegetarian dating for marriage')
220 d = {}
221 d['loc'] = quote(self.req.uri)
222 d['documenturl'] = quote(url)
223 return str(self.tmpl('advertising', d))
224
225 def besafe(self, REQUEST): return self.tmpl('besafe', {})
226 def legal(self, REQUEST): return self.tmpl('legal', {})
227 def faq(self, REQUEST): return self.tmpl('faq', {})
228 def tour(self, REQUEST): return self.tmpl('tour', {})
229 def about(self, REQUEST): return self.tmpl('about', {})
230
231 def registerwelcome(self, REQUEST):
232
233 options = { \
234 'registersafety': ("", "registersafety", 'mainbit', "[More]")
235 }
236
237 page = self.tmpl('registerwelcome', REQUEST)
238 page.dynamiclink(options)
239
240 return page
241
242 def introsearch(self, REQUEST):
243
244 req = copy(REQUEST)
245 if not req:
246 req['latest'] = 12
247
248 url = 'searchresultspage?%s' % urlencode(req)
249 links = { 'searchresultspage': url }
250
251 page = self.tmpl('introsearch')
252 page.staticlink(links)
253
254 return page
255
256 def homewelcome(self, REQUEST):
257 """ displays the anonymous main home page content.
258 this page is a little odd because it uses an
259 actual web-page function (searchresultspage) and
260 sploshes the content into the home page.
261 """
262 options = { \
263 'search': ("", "search", "maincontent", "search"),
264 }
265
266 page = self.tmpl('homewelcome')
267 page.dynamiclink(options)
268
269 return page
270
271
272 def menuads(self, REQUEST):
273 d = {}
274 d['loc'] = quote(self.req.uri)
275 d['documenturl'] = quote('vegetarian dating for marriage')
276
277 i = self.get_useful_info()
278 if i.get("screenwidth", 630) > 820:
279 d['wide_ads'] = 1
280 return str(self.tmpl('menuads', d))
281
282
283 def veggies(self, REQUEST):
284 sessionkey = self.get_session_info()
285 res = self.db.check_session(sessionkey)
286 loggedin = None
287 if res:
288 loggedin = 1
289 d = {'loggedin': loggedin }
290 return str(self.tmpl('veggies', d))
291
292 def resizeevent(self, REQUEST):
293
294 i = self.get_useful_info()
295 i['screenwidth'] = int(REQUEST.get("width", 630))
296 i['screenheight'] = int(REQUEST.get("height", 460))
297 self.set_useful_info(i)
298
299 resize = "ajax_dlink('adcontent', 'menuads');"
300 sessionkey = self.get_session_info()
301 res = self.db.check_session(sessionkey)
302 if res:
303 resize += " ajax_dlink('mainadcontent', 'mainads');"
304
305 return "<script> %s </script> " % resize