示例#1
0
 def cl(self):
     if self._cl:
         return self._cl
     if self.clid:
         clid = self.clid
     else:
         clName = self.request.REQUEST.get('cl')
         if clName:
             self.clid = clid = clName
         else:
             return False
     cl = memcache.get(clid.encode('utf8'))
     if cl is None:
         if clid.isdigit() and len(clid)<4:
             logger.warn("User requested a random classification, not fully implemented")
             cl = classification.random(self.ts.numregions,min(int(clid)+2,MAX_n))
             self._cl = cl
             return cl
         else:
             cl = Classification.get_by_key_name(clid)
             if cl is not None and not memcache.add(clid.encode('utf8'), cl):
                 logger.error("Memcache set failed [ %s ]"%clid)
     if cl is not None:
         if cl.public or cl.owner == self.request.user.username:
             self._cl = cl
             return self._cl
     return False
示例#2
0
 def real_get(self):
     values = self.request.REQUEST.get('values')
     if not values and self.cl:
         C = Classification.get_by_key_name(self.clid)
         if C and hasattr(C,'notes'):
             values = C.notes
         else:
             values = ','.join(map(str,range(self.cl.n)))
     if self.cs and values:
         delim = self.request.REQUEST.get('delim')
         if not delim: delim = ','
         title = self.request.REQUEST.get('title')
         values = values.split(delim)
         s = '<div style="width:170px; background-color:#cccccc; padding:5px;">'
         if title: s+='<h3 style="margin:0;border:0;padding:0;">%s</h3>'%title
         #for i in range(2,self.cs.n):
         for i,val in enumerate(values):
             r,g,b = map(ord,self.cs.colors[i+2])
             s += '<div style="clear:both; float:left; border: 1px black solid; width:20px; height:20px; background-color:#%.2X%.2X%.2X;"> </div>'%(r,g,b)
             #s += '<div style="height:22px;">'+values[i-2]+'</div>'
             s += '<div style="height:22px;">'+val+'</div>'
         s += '</div>'
         callback = self.request.REQUEST.get('callback')
         if callback:
             s = callback+'({"legend":"%s"})'%s.replace('"','\\"')
         self.write(s)
示例#3
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