def get(self, rparameters): """Lists all available albums.""" parts = rparameters.split(".") parts.reverse() parts.append('') parts.append('') parts.append('') [ext,lang,aps]=parts[:3] page_name2 = 'menu'+'-'+lang+'.'+fileext page3 = Page.loadnew("kalbos") textaps='' if len(aps)>0: textaps=aps+'.' text='' for name, value in kalbossort: text = text + (_kalbhtml % ('picsearch', textaps+name, ext, name)) page3.content = text """Displays the tag search box and possibly a list of results.""" query = cgi.escape(self.request.get('q')) pics = [] if query: # ListProperty magically does want we want: search for the occurrence # of the term in any of the tags. pics = Picture.all().filter('tags =', query) else: query = '' page2 = Page.load(page_name2) self.render_to_response('pic_search.html',lang, { 'plet': lang+'.'+fileext, 'kalbos': page3, 'menu': page2, 'query': query, 'pics': pics, })
def cont(self,req,modname,rparameters): param=urlparam(rparameters) ext=param['ext'] lang=param['lang'] aps=param['aps'] kalb=param['kalb'] lang1 = gettext.translation (cmstrans2, locale_path, [kalb] , fallback=True) _ = lang1.ugettext modname2 = 'custommodule' page = Page.loadnew(modname2) page.content = "<h1>test %s</h1>test" % (req.request.get('info')) page_name2 = 'menu'+'-'+lang+'.'+fileext page2 = Page.load(page_name2) page3 = Page.loadnew("kalbos") textaps='' if len(aps)>0: textaps=aps+'.' text='' for name, value in kalbossort: text = text + (_kalbhtml % ('mo2'+modname, textaps+name, ext, name, name)) page3.content = text req.generate('view.html', lang, { 'imgshar': False, 'noedit': '1', 'application_name': siteauth(), 'kalbos': page3, 'menu': page2, 'page': page, })
def get(self, rparameters): """Lists all available albums.""" parts = rparameters.split(".") parts.reverse() parts.append('') parts.append('') parts.append('') [ext,lang,aps]=parts[:3] page_name2 = 'menu'+'-'+lang+'.'+fileext page3 = Page.loadnew("kalbos") textaps='' if len(aps)>0: textaps=aps+'.' text='' for name, value in kalbossort: text = text + (_kalbhtml % ('pic', textaps+name, ext, name)) page3.content = text albums = Album.all().order('-created_date') page2 = Page.load(page_name2) self.render_to_response('pic_index.html',lang, { 'plet': lang+'.'+fileext, 'kalbos': page3, 'albums': albums, 'menu': page2, })
def get(self, rparameters, album_key): """Lists all available albums.""" parts = rparameters.split(".") parts.reverse() parts.append('') parts.append('') parts.append('') [ext,lang,aps]=parts[:3] page_name2 = 'menu'+'-'+lang+'.'+fileext page3 = Page.loadnew("kalbos") textaps='' if len(aps)>0: textaps=aps+'.' text='' for name, value in kalbossort: text = text + (_kalbhtml % ('picalbum', textaps+name, ext+'/'+album_key, name)) page3.content = text """Displays a single album. Note that in this and later handlers, the args come from a capturing group in the WSGIApplication specification. See the webapp framework docs for more info. Args: album_key: the datastore key for the Album to view. """ pics = [] num_results = 0 try: album = db.get(album_key) albumkey = album.key() albumname = album.name for picture in album.pictures: if num_results % PICTURES_PER_ROW == 0: current_row = [] pics.append(current_row) current_row.append(picture) num_results += 1 except: albumkey = "error404" albumname = "Not Found 404" page2 = Page.load(page_name2) self.render_to_response('pic_album.html',lang, { 'plet': lang+'.'+fileext, 'kalbos': page3, 'menu': page2, 'num_results': num_results, 'album_key': albumkey, 'pics': pics, 'album_name': albumname })
def pre_handler(r, page_name="MainPage"): mode = r.REQUEST.get('mode', 'view') page = Page.load(page_name or "MainPage") # Default to edit for pages that do not yet exist if not page.entity: mode = 'edit' else: modes = ['view', 'edit'] if not mode in modes: mode = 'view' # User must be logged in to edit if not users.get_current_user() and (r.method == 'POST' or mode == 'edit'): #The GET version of this URI is just the view/edit mode, which is a #reasonable thing to redirect to #self.redirect(users.create_login_url(self.request.uri)) return ("redirect:%s" % users.create_login_url(r.path), ) if r.method == 'POST': page.content = r.POST.get('content', "") page.save() return ("redirect:/wiki/%s" % page_name, ) #mode = "view" return ("wiki_%s.html" % mode, {'page': page, 'user': users.get_current_user(), 'logout_url': users.create_logout_url(r.path), 'login_url': users.create_login_url(r.path) })
def get(self, rparameters, pic_key): """Lists all available albums.""" parts = rparameters.split(".") parts.reverse() parts.append('') parts.append('') parts.append('') [ext,lang,aps]=parts[:3] page_name2 = 'menu'+'-'+lang+'.'+fileext page3 = Page.loadnew("kalbos") textaps='' if len(aps)>0: textaps=aps+'.' text='' for name, value in kalbossort: text = text + (_kalbhtml % ('picshowimage', textaps+name, ext+'/'+pic_key, name)) page3.content = text """Renders the page for a single picture. Args: pic_key: key for the Picture model for the picture to display """ cerr = False try: pic = db.get(pic_key) pictitle = pic.title piccaption = pic.caption pictags = pic.tags pickey = pic.key() picalbumkey = pic.album.key() except: cerr = True if not cerr: page2 = Page.load(page_name2) self.render_to_response('pic_show_image.html',lang, { 'plet': lang+'.'+fileext, 'kalbos': page3, 'menu': page2, 'pic': pic, 'image_key': pic.key(), }) else: self.response.out.write("Error")
def get(self, rparameters): """Lists all available albums.""" parts = rparameters.split(".") parts.reverse() parts.append('') parts.append('') parts.append('') [ext,lang,aps]=parts[:3] page_name2 = 'menu'+'-'+lang+'.'+fileext page3 = Page.loadnew("kalbos") textaps='' if len(aps)>0: textaps=aps+'.' text='' for name, value in kalbossort: text = text + (_kalbhtml % ('picnew', textaps+name, ext, name)) page3.content = text """Displays the album creation form.""" page2 = Page.load(page_name2) self.render_to_response('pic_new.html',lang, {'plet': lang+'.'+fileext,'menu': page2,'kalbos': page3})
def get(self, rparameters, album_key): """Lists all available albums.""" parts = rparameters.split(".") parts.reverse() parts.append('') parts.append('') parts.append('') [ext,lang,aps]=parts[:3] page_name2 = 'menu'+'-'+lang+'.'+fileext page3 = Page.loadnew("kalbos") textaps='' if len(aps)>0: textaps=aps+'.' text='' for name, value in kalbossort: text = text + (_kalbhtml % ('picupload', textaps+name, ext+'/'+album_key, name)) page3.content = text """Display the image upload form. Args: album_key: datastore key for the album to upload the image to """ cerr = False try: album = db.get(album_key) albumname = album.name albumkey = album.key() except: cerr = True if not cerr: page2 = Page.load(page_name2) self.render_to_response('pic_upload.html',lang, { 'plet': lang+'.'+fileext, 'kalbos': page3, 'menu': page2, 'album_key': album.key(), 'album_name': album.name }) else: self.response.out.write("Error")
def cont(self,req,modname,rparameters): param=urlparam(rparameters) ext=param['ext'] lang=param['lang'] aps=param['aps'] kalb=param['kalb'] lang1 = gettext.translation (cmstrans2, locale_path, [kalb] , fallback=True) _ = lang1.ugettext modname2 = 'custommodule' if not req.request.get('cmd'): page = Page.loadnew(modname2) greeting = '' bio_cgi_url = "/bioview" bio_cgi_url = ("%s/%s-mo2%s-%s.%s" % (urlhost2(), cmspath2,modname,lang, fileext)) gimmet='' gimmen='' gimdien='' simbsafe = re.compile("[^0-9a-zA-Z]") mazosios = re.compile("[^a-z]") skaic = re.compile("[^0-9]") handler = {} if 'HTTP_COOKIE' in os.environ: cookies = os.environ['HTTP_COOKIE'] cookies = cookies.split('; ') for cookie in cookies: cookie = cookie.split('=') handler[cookie[0]] = cookie[1] if 'terebasGimd' in handler: gimd = handler['terebasGimd'] gimd = "%s" % (skaic.sub("", gimd)) try: gimmet=gimd[0,4] gimmen=gimd[4,6] gimdien=gimd[6,8] except: zerr = True unixtime=time.time() d = datetime.datetime.fromtimestamp(unixtime) lang = req.request.get('lang') or 'lt' gimmet = req.request.get('gmet') or gimmet gimmen = req.request.get('gmem') or gimmen gimdien = req.request.get('gdien') or gimdien siemet = req.request.get('smet') or d.strftime('%Y') men = req.request.get('men') or d.strftime('%m') biohtml='' if not lang: lang = 'lt' else: lang = mazosios.sub("", lang) if not gimmet: gimmet = '1970' else: gimmet = skaic.sub("", gimmet) if not gimmen: gimmen = '06' else: gimmen = skaic.sub("", gimmen) if not gimdien: gimdien = '20' else: gimdien = skaic.sub("", gimdien) if not siemet: format = '%Y' siemet = d.strftime(format) else: siemet = skaic.sub("", siemet) if not men: format = '%m' men = d.strftime(format) else: men = skaic.sub("", men) if req.request.get('gmet') and req.request.get('gmem') and req.request.get('gdien'): bioduom = "lang="+lang+"&gmet="+gimmet+"&gmem="+gimmen+"&gdien="+gimdien+"&smet="+siemet+"&men="+men biohtml = "<img src=\""+bio_cgi_url+"?cmd=1&"+bioduom+"\" height=\"256\" width=\"256\" alt=\"\" />\n" template_values2 = { 'biohtml': biohtml, 'gimmet': gimmet, 'gimmen': gimmen, 'gimdien': gimdien, 'siemet': siemet, 'men': men } directory = os.path.dirname(__file__) path = os.path.join(directory, "bio.html") cont1 = template.render(path, template_values2, debug=_DEBUG) page.content = cont1 page_name2 = 'menu'+'-'+lang+'.'+fileext page2 = Page.load(page_name2) page3 = Page.loadnew("kalbos") textaps='' if len(aps)>0: textaps=aps+'.' text='' for name, value in kalbossort: text = text + (_kalbhtml % ('mo2'+modname, textaps+name, ext, name, name)) page3.content = text req.generate('view.html', lang, { 'imgshar': False, 'noedit': '1', 'application_name': siteauth(), 'kalbos': page3, 'menu': page2, 'page': page, }) elif req.request.get('cmd') == '1': unixtime=time.time() d = datetime.datetime.fromtimestamp(unixtime) lang = req.request.get('lang') or 'lt' gimmet = req.request.get('gmet') or '1970' gimmen = req.request.get('gmem') or '06' gimdien = req.request.get('gdien') or '20' siemet = req.request.get('smet') or d.strftime('%Y') men = req.request.get('men') or d.strftime('%m') simbsafe = re.compile("[^0-9a-zA-Z]") mazosios = re.compile("[^a-z]") skaic = re.compile("[^0-9]") if not lang: lang = 'lt' else: lang = mazosios.sub("", lang) if not gimmet: gimmet = '1970' else: gimmet = skaic.sub("", gimmet) if not gimmen: gimmen = '06' else: gimmen = skaic.sub("", gimmen) if not gimdien: gimdien = '20' else: gimdien = skaic.sub("", gimdien) if not siemet: format = '%Y' siemet = d.strftime(format) else: siemet = skaic.sub("", siemet) if not men: format = '%m' men = d.strftime(format) else: men = skaic.sub("", men) format = '%H:%i:%s %m/%d/%Y %O' date = d.strftime(format) if lang == 'en': bio_new = 'bio_en8.png' strbio = "Biorhythms" strfiz = "Physical State" stremo = "Emotional State" strint = "Intellect" strmd = "Days of the Month" strid = "Survived Days" strgd = "Date of Birth" strm = "Month" else: bio_new = 'bio_lt8.png' strbio = "Bioritmai" strfiz = "Fizin\xEB bukl\xEB" stremo = "Emocin\xEB b\xFBsena" strint = "Intelektas" strmd = "Menesio dienos" strid = "I\xF0gyventa dien\xF8" strgd = "Gimimo data" strm = "M\xEBnuo" bio_new = '1m.png' color1 = [106, 0,0,0] color2 = [0xff, 0xff, 0, 0xff] color3 = [128, 255, 0, 0xff] color4 = [0,128,255, 0xff] color5 = [255,128,255, 0xff] color6 = [255,255,0, 0xff] color1 = [0x00, 0x30,0xd2,0xFF] color2 = [0xf6, 0xf3, 0x00, 0xff] color3 = [0xfe, 0x7f, 0xfe, 0xff] color4 = [0x7f, 0xfe, 0x00, 0xff] color5 = [255,128,255, 0xff] color6 = [255,255,0, 0xff] color1 = [0xAC, 0x2F,0x93,0xFF] color1 = [0x00, 0x00,0x8e,0xFF] color2 = [0xCA, 0x45, 0x46, 0xff] color3 = [0xd3, 0xa5, 0x6a, 0xff] color4 = [0x71, 0xa4, 0xcf, 0xff] color5 = [0xfd, 0xd9, 0x13, 0xff] color1 = [0x00, 0x00,0x8e,0xFF] color2 = [0x2b, 0xf6, 0x42, 0xff] color3 = [0xfc, 0xf1, 0x33, 0xff] color4 = [0xf8, 0x01, 0xd6, 0xff] color5 = [0xff, 0x0e, 0x06, 0xff] color6 = [255,255,0, 0xff] #f6f300 #fe7ffe #000000 #7ffe00 #0030d2 #00008e - fonas melyna # ff0e06 raud #2bf642 zalia #fcf133 gel #f801d6 viol cikfiz = 23 cikemo = 28 cikint = 33 ilg = [0,31,28,31,30,31,30,31,31,30,31,30,31] ys=0 derr = False if gimmet<1970: ys=1970-int(gimmet) try: year=int(gimmet)+ys tt1 = datetime.date(int(year), int(gimmen), int(gimdien)) year=int(siemet)+ys tt2 = datetime.date(int(year), int(men), 1) t1=time.mktime(tt1.timetuple()) t2=time.mktime(tt2.timetuple()) dienu=int((int(t2)-int(t1))/86400) except: derr = True # errtext = cgi.escape(str(sys.exc_info()[0])) + ' ' + cgi.escape(str(sys.exc_info()[1])) + ' ' + cgi.escape(str(sys.exc_info()[2])) # req.response.out.write(errtext) # sys.exit(0) if derr: dienu=0 ref=False if 'HTTP_REFERER' in os.environ: for referer in referers: pos = os.environ['HTTP_REFERER'].find(referer) # The offset is optional if not(pos < 0): # not found ref = True else: ref = True if not ref: #if uselog: #log() width = 256 height = 256 im = PNGCanvas(256, 256, [255, 255,255,255]) im.color = [0xff,0,0,0xff] im.rectangle(0,0,width-1,height-1) im.verticalGradient(1,1,width-2, height-2,[0xff,0,0,0xff],[0x20,0,0xff,0x80]) im.color = [0,0,0,0xff] im.line(0,0,width-1,height-1) im.line(0,0,width/2,height-1) im.line(0,0,width-1,height/2) im.copyRect(1,1,width/2-1,height/2-1,0,height/2,im) im.blendRect(1,1,width/2-1,height/2-1,width/2,0,im) str = "Bad referer" y = 5 x = 256 / 2 - len(str) * 9 / 2 x = "%u" % x font=GDFont() font.load( 'giant_w57.gd','gdfonts') im=GDFont.gdfontstring(font,im,str,x,y,[0, 0, 0, 0xff]) else: zerr=False im = False try: directory = os.path.dirname(__file__) path = os.path.join(directory, os.path.join('gdfonts', bio_new)) imghex=file(path,'rb').read() f = cStringIO.StringIO(imghex) im = PNGCanvas(256, 256, [0, 0,0,0]) im.load(f) except: zerr = True if zerr: # im = PNGCanvas(256, 256, [0, 0,0,0]) im = PNGCanvas(256, 256, color1) zerr=True str = strbio y = 10 x = 256 / 2 - len(str) * 9 / 2 x = "%u" % x font5=GDFont() font5.load( 'giant_w57.gd','gdfonts') font4=GDFont() font4.load( 'large_w57.gd','gdfonts') font3=GDFont() font3.load( 'medium_w57.gd','gdfonts') font2=GDFont() font2.load( 'small_w57.gd','gdfonts') font1=GDFont() font1.load( 'tiny_w57.gd','gdfonts') if zerr: im=GDFont.gdfontstring(font5,im,str,x,y,color2) str = strfiz y = 130 + 10 x = 256 / 2 - len(str) * 6 / 2 x = "%u" % x if zerr: im=GDFont.gdfontstring(font2,im,str,x,y,color3) str = stremo y = 130 + 10 + 5 + 12 x = 256 / 2 - len(str) * 6 / 2 x = "%u" % x if zerr: im=GDFont.gdfontstring(font2,im,str,x,y,color4) str = strint y = 130 + 10 + 5 + 12 + 5 + 12 x = 256 / 2 - len(str) * 6 / 2 x = "%u" % x if zerr: im=GDFont.gdfontstring(font2,im,str,x,y,color5) str = strmd y = 82 + 4 + 8 + 4 x = 256 / 2 - len(str) * 5 / 2 x = "%u" % x if zerr: im=GDFont.gdfontstring(font1,im,str,x,y,color2) str = strid+':' y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 x = 256 / 2 - len(str) * 6 x = "%u" % x if zerr: im=GDFont.gdfontstring(font2,im,str,x,y,color2) str = " %s" % dienu y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 x = 256 / 2 x = "%u" % x im=GDFont.gdfontstring(font2,im,str,x,y,color2) str = strgd+':' y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 + 8 + 12 x = 256 / 2 - len(str) * 7 x = "%u" % x if zerr: im=GDFont.gdfontstring(font3,im,str,x,y,color2) str = " %s/%s/%s" % (gimmet, gimmen, gimdien) y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 + 8 + 12 x = 256 / 2 x = "%u" % x im=GDFont.gdfontstring(font3,im,str,x,y,color2) str = strm+':' y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 + 8 + 12 + 6 + 13 x = 256 / 2 - len(str) * 7 x = "%u" % x if zerr: im=GDFont.gdfontstring(font3,im,str,x,y,color2) str = " %s/%s" % (siemet,men) y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 + 8 + 12 + 6 + 13 x = 256 / 2 x = "%u" % x im=GDFont.gdfontstring(font3,im,str,x,y,color2) prad = 10 gal = 256 - prad im.color = color2 im.line(prad,80,gal,80) ii = ilg[int(men)] if int(men) == 2 and int(int(siemet) % 4) == 0: ii+=1 y = 82 + 4 str = 1 x = prad - len("%s" % str) * 5 / 2 x = "%u" % x im=GDFont.gdfontstring(font1,im,str,x,y,color2) for i in range(5, ii, 5): str = i x = prad + (i - 1) * (256 - prad - prad) / (ii - 1) x = x - len("%s" % str) * 5 / 2 x = "%u" % x im=GDFont.gdfontstring(font1,im,str,x,y,color2) pi = math.pi x = prad xsen = "%u" % x y = 80 - 50 * math.sin((1 + dienu) * 2 * pi / cikfiz) yfiz = "%u" % y y = 80 - 50 * math.sin((1 + dienu) * 2 * pi / cikemo) yemo = "%u" % y y = 80 - 50 * math.sin((1 + dienu) * 2 * pi / cikint) yint = "%u" % y for i in range(1, ii): x = prad + (i - 1) * (256 - prad - prad) / (ii - 1) x = "%u" % x im.color = color2 im.line(x,78,x,82) y = 80 - 50 * math.sin((i + dienu) * 2 * pi / cikfiz) y = "%u" % y im.color = color3 im.line(xsen,yfiz,x,y) yfiz = y y = 80 - 50 * math.sin((i + dienu) * 2 * pi / cikemo) y = "%u" % y im.color = color4 im.line(xsen,yemo,x,y) yemo = y y = 80 - 50 * math.sin((i + dienu) * 2 * pi / cikint) y = "%u" % y im.color = color5 im.line(xsen,yint,x,y) yint = y xsen = x sgimmet = "%04d" % int(gimmet) sgimmen = "%02d" % int(gimmen) sgimdien = "%02d" % int(gimdien) gimd=sgimmet+sgimmen+sgimdien expiration = datetime.datetime.now() + timedelta(seconds=3600*24*90) exp=expiration.strftime("%a, %d-%b-%Y %H:%M:%S PST") req.response.headers['Content-Type'] = "image/png" req.response.headers['Set-Cookie'] = "terebasGimd=%s; path=/; expires=%s" % (gimd,exp) req.response.out.write(im.dump())