Пример #1
0
 def cl(self):
     """ Search for the Classification Name in the Request and try and load it from Memcache or DataStore, return True or False """
     if self._cl:
         return self._cl
     classificationName = self.request.REQUEST.get('cl','DEFAULT')
     if classificationName == 'random':
         self.clid = clid = "cl:random"
     elif classificationName.isdigit():
         self.clid = clid = "cl:__digit:"+self.ts.name+":"+classificationName
     elif self.ts:
         self.clid = clid = "cl:"+self.ts.name+":"+classificationName
     else:
         return False
     cl = memcache.get(clid)
     if cl is not None:
         self._cl = cl
     else:
         cl = None
         if self.ts:
             N = self.ts.idlen
             if clid == 'cl:random':
                 cl = classification.random(N,min(N,MAX_n))
             elif clid.startswith('cl:__digit:'):
                 cl = classification.random(N,min(int(classificationName)+2,MAX_n))
             elif clid.startswith('cl:key_'):
                 C = Classification.get(classificationName[4:])
                 if C:
                     cl = classification.Classification(C.a)
             elif clid:
                 C = Classification.get_by_key_name(clid)
                 if C:
                     cl = classification.Classification(C.a)
             #if cl and clid != 'cl:random':
                 #if not memcache.add(clid, cl, 60):
                 #    logging.error("Memcache set failed [ %s ]"%clid)
             if not cl:
                 cl = classification.random(N,3)
         self._cl = cl
     if cl is not None:
         return cl
     else:
         return False
Пример #2
0
 def real_get(self):
     ts = self.ts
     if ts:
         self.write("Found TileSet: "+ts.name)
         self.write("<br />")
         img_src = '/o.png?ts='+ts.name
         if self.request.get('cl'):
             img_src+= '&cl='+self.request.get('cl')
         if self.request.get('cs'):
             img_src+= '&cs='+self.request.get('cs')
         gmap = self.request.url.replace('/m/','/gmap/')
         self.write("<a href='%s'><img src='%s' /></a><br />"%(gmap,img_src))
         args = {}
         args['name'] = ts.name
         args['pub'] = "Public" if ts.public else "Private"
         args['cLat'] = ts.cLat
         args['cLng'] = ts.cLng
         args['maxZoom'] = ts.maxZoom
         self.write("<b>%(name)s</b> is a <b>%(pub)s</b> TileSet with a centriod of <b>(%(cLng).4f , %(cLat).4f)\
                     </b> and a maximium zoom level of <b>%(maxZoom)d</b>.<br />"%args)
         self.write("Notes: %s<br />"%ts.notes)
         self.write("Source: %s<br />"%ts.source)
         self.write("ID Spreadsheet: <a href='/ids.csv?ts=%s'>ids.csv </a>"%ts.name)
         self.write('<br><br><hr>')
         self.write('<a href="classify?ts=%s">Classify this Tile Set.</a>'%ts.name)
         q = Classification.all(keys_only=True)
         q.filter('tileset',ts)
         q.filter('public',True)
         if q.count():
             self.write("Classifications for this TileSet:<br>")
         #q.filter('expires',Flase)
         for cl_key in q:
             cl = Classification.get(cl_key)
             if cl.name:
                 cl = cl.name
             else:
                 cl = 'key_%s'%cl_key
             self.write('<A href="/m/?ts=%s&cl=%s">%s</a><br>'%(ts.name,cl,cl))