Ejemplo n.º 1
0
 def get(self):
     count = self.request.get("count",default_value=10)
     templatevars = {}
     l = SavedList.all().order("-created").fetch(count)
     templatevars["list"] = l
     templatevars["totalhere"] = len(l)
     templatevars["overalltotal"] = get_count("/work/list")
     self.generate("readlist.html",templatevars)
Ejemplo n.º 2
0
 def get(self,id):
     keylist = SavedList.get_by_id(int(id))
     templatevars = {"works":Work.get(keylist.keys)}
     templatevars["overalltotal"] = get_count("Work")
     templatevars["totalhere"] = len(keylist.keys)
     templatevars["listname"] = keylist.name
     templatevars["id"] = id
     self.generate("listofworks.html",templatevars)
     pass
Ejemplo n.º 3
0
 def get(self,id):
     self.enforce_admin()
     keylist = SavedList.get_by_id(int(id))
     templatevars = {"works":Work.get(keylist.keys)}
     templatevars["url"] = self.request.uri
     templatevars["generatedtime"] = datetime.now()
     templatevars["listid"] = id
     if not self.request.get("download",None) is None:
         self.response.headers['Content-Type'] = 'application/download'
         self.response.headers['Content-disposition'] = \
                 'attachment; filename=%s.sh'%keylist.name
     else:
         self.response.headers['Content-Type'] = 'text/plain'
     self.generate("wgetscript.sh",templatevars)
Ejemplo n.º 4
0
    def get(self):
        self.enforce_admin()
        pagesize = 1000
        count = int(self.request.get("size",default_value=10))
        site = self.request.get("site",default_value=None)
        name = self.request.get("name",default_value=None)
        if name is None:
            self.jsonout(status="error",msg="Name is not specified for list")
            return
        else:
            name = name.strip()

        wq = db.Query(Work,keys_only=True).order("__key__")

        if site is None:
            workcount=int(get_count("Work"))
        else:
            wq.filter("site =",site)
            workcount=int(get_count("Work-%s"%site))

        if count > workcount:
            self.jsonout(status="error",msg="Tried to find %s out of %s. Not possible", 
                         format=(count,workcount))
            return


        # select $count from the complete set
        numberlist = random.sample(range(0,workcount-1),count)
        numberlist.sort()

        #initbuckets
        buckets = [ [] for i in xrange(int(max(numberlist)/pagesize)+1) ]
        for k in numberlist:
            thisb = int(k/pagesize)
            buckets[thisb].append(k-(thisb*pagesize))
        logging.debug("Numbers: %s. Buckets %s",numberlist,buckets)

        #page through results.
        result = []
        baseq =  wq
        for b,l in enumerate(buckets):
            if len(l) > 0:
                result += [ wq.fetch(limit=1,offset=e)[0] for e in l ]

            if b < len(buckets)-1: # not the last bucket
                lastkey  = wq.fetch(1,pagesize-1)[0]
                wq = baseq.filter("__key__ >",lastkey)

        s = SavedList(name=name,keys=result,size=len(result),site=site,ids=numberlist)
        increment("/work/list")
        if not site is None:
            increment("/work/%s/list"%site)
        s.put()
        self.jsonout(status="ok", msg="Created list %s with %d items.List id %d",
                     format=(s.name,s.size,s.key().id()),id=s.key().id())