Ejemplo n.º 1
0
 def post_csv(self,bg=0,br=1):
     user = self.request.user
     POST = self.request.POST
     if 'dat' in POST:
         a = array.array(UNSIGNED_ITEM_TYPES[1])
         dat = map(int,POST['dat'].split(','))
         a.fromlist([bg,br])
         a.fromlist(dat)
         astring = a.tostring()
         cl = Classification("%s:%s"%(user.username,hashlib.md5(astring).hexdigest()))
         cl.tileset = self.ts.key_name
         cl.dat = zlib.compress(astring)
         cl.N = len(a)
         assert (cl.N-2) == self.ts.numregions
         cl.n = max(a)+1
         cl.owner = user.username
         cl.public = True
         cl.expires = False
         cl.date = time.mktime(time.gmtime())
         return cl.put()
Ejemplo n.º 2
0
 def real_post(self):
     """ Handles /classify POST requests/
         The POST data must contain "classifcation" and "ts"
         'classification': a string of integers in the range >=2 and <=255.
                             0 and 1 are reserved for background and borders
                             each integer represents the classID of a region,
                             the order of the class ids MUST match the order
                             of the IDS provided by the GET ?noform=1 handler.
     """
     if self.ts:
         cl = self.request.REQUEST.get('classification')
         b64 = self.request.REQUEST.get('b64encode')
         if not cl:
             self.write("Bad Request")
             return self.die(400)
         try:
             if b64 == 'True':
                 a = array.array('B')
                 a.fromstring(b64decode(cl))
                 cl = a.tolist()
             else:
                 cl = cl.strip().split(',')
                 cl = map(int,cl)
             assert len(cl) == self.ts.idlen
             cl = [0,1]+cl
             a = array.array(UNSIGNED_ITEM_TYPES[1])
             a.fromlist(cl)
             a = zlib.compress(a.tostring())
             name = self.request.REQUEST.get('name')
             exp = False
             if not name:
                 name = 'user_%s'%str(time()).replace('.','')
                 exp = True
             if name:
                 clid = 'cl:%s:%s'%(self.ts.name,name)
                 memcache.delete(clid)
                 C = Classification(key_name=clid)
                 C.name = name
                 C.expires = exp
             #else:
             #    key_name = 'cs:%s:%s'%(self.ts.name,str(time()).replace('.',''))
             #    C = Classification(key_name)
             C.tileset = self.ts.key()
             C.a = a
             C.N = len(cl)-2
             C.n = max(cl)+1
             title = self.request.REQUEST.get('title')
             if title:
                 C.title = title
             notes = self.request.REQUEST.get('notes')
             if notes:
                 C.notes = notes
             public = self.request.REQUEST.get('public')
             if public and public == 'False':
                 C.public = False
             elif public:
                 C.public = True
             try:
                 key = C.put()
             except CapabilityDisabledError:
                 logging.error("Capability has been disabled")
                 self.dir(500)
             callback = self.request.REQUEST.get("callback")
             if name:
                 if callback:
                     self.write('%s({"key":"%s"})'%(callback,name))
                 else:
                     self.write("Put: %s"%name)
             else:
                 if callback:
                     self.write('%s({"key":"%s"})'%(callback,key))
                 else:
                     self.write("Put: key_%s"%key)
         except:
             raise 
     else:
         self.die(400)