Пример #1
0
    def get(self):

        pdfId = self.request.get("pdfId")

        committee_items = PreCommitteePage.query(PreCommitteePage.pdf==blobstore.BlobKey(pdfId))
        committee_items = [ { 'pageId' : str(f.page), 'image': images.get_serving_url(f.page,size=900,crop=False) } for f in committee_items ]

        committee = {
            'id': pdfId,
            'committee_items': committee_items,
            'committee_items_json': json.dumps(committee_items),
            'committeeDate': 1388527200000,
            'requestDate': 1388354400000
        } # TODO: get this object from DB

        if pdfId is None:
           template_values = {}
            # TODO: create a page with a list of all requests
        else:
            template_values = {                
                'committee': committee
            }
            template_name = 'committee.html'

        template = JINJA_ENVIRONMENT.get_template(template_name)
        self.response.write(template.render(template_values))
Пример #2
0
    def get(self):

        user = users.get_current_user()
        if not user or user.email() not in ALLOWED_EMAILS:
            self.abort(403)

        pdfId = self.request.get("pdfId")
        comDate = self.request.get("comDate")

        committee_items = PreCommitteePage.query(PreCommitteePage.pdf == blobstore.BlobKey(pdfId))

        committee_items = [
            {
                "pageId": str(f.page),
                "req_ids": f.request_id,
                "kind": f.kind,
                "image": images.get_serving_url(f.page, size=900, crop=False),
            }
            for f in committee_items
        ]
        if len(committee_items) == 0:
            self.abort(404)

        committee = {
            "id": pdfId,
            "committee_items": committee_items,
            "committee_items_json": json.dumps(committee_items),
            "committeeDate": int(comDate),
        }

        template_values = {"committee": committee}
        template_name = "committee.html"

        template = JINJA_ENVIRONMENT.get_template(template_name)
        self.response.write(template.render(template_values))
Пример #3
0
 def get(self,key):
     self.response.headers['Content-Type'] = 'application/json'
     pages = PreCommitteePage.query(PreCommitteePage.pdf==blobstore.BlobKey(key)).fetch(100)
     done = False
     for page in pages:
         if page.last == True:
             done = True
     ret = { 'numPages': len(pages),
             'done' :  done }
     self.response.write(json.dumps(ret))
Пример #4
0
 def get(self, key):
     self.response.headers['Content-Type'] = 'application/json'
     pages = PreCommitteePage.query(
         PreCommitteePage.pdf == blobstore.BlobKey(key)).fetch(100)
     done = False
     pages = list(pages)
     for page in pages:
         if page.last == True:
             done = True
     if len(pages) == 1 and pages[0].page is None:
         ret = 0
     else:
         ret = len(pages)
     ret = {'numPages': ret, 'done': done}
     self.response.write(json.dumps(ret))
Пример #5
0
    def post(self):
        
        comDate = self.request.get("committeeDateVal")
        pdfId = self.request.get("requestFileUrl")

        comDate = datetime.datetime.fromtimestamp(int(comDate)/1000.0)
        to_put = []
        for page in PreCommitteePage.query(PreCommitteePage.pdf==blobstore.BlobKey(pdfId)):
            page.date = comDate
            page.year = comDate.year
            to_put.append(page)
        ndb.put_multi(to_put)
        
        query_params = {'pdfId': pdfId}  
        self.redirect('/change_input/committee?' + urllib.urlencode(query_params))
Пример #6
0
 def get(self,key):
     self.response.headers['Content-Type'] = 'application/json'
     pages = PreCommitteePage.query(PreCommitteePage.pdf==blobstore.BlobKey(key)).fetch(100)
     done = False
     pages = list(pages)
     for page in pages:
         if page.last == True:
             done = True
     if len(pages)==1 and pages[0].page is None:
         ret = 0
     else:
         ret = len(pages)
     ret = { 'numPages': ret,
             'done' :  done }
     self.response.write(json.dumps(ret))
Пример #7
0
    def post(self):

        user = users.get_current_user()
        if not user or user.email() not in ALLOWED_EMAILS:
            self.abort(403)

        comDate = self.request.get("committeeDateVal")
        pdfId = self.request.get("requestFileUrl")

        comDate = datetime.datetime.fromtimestamp(int(comDate) / 1000.0 + 86400)
        to_put = []
        for page in PreCommitteePage.query(PreCommitteePage.pdf == blobstore.BlobKey(pdfId)):
            page.date = comDate
            page.year = comDate.year
            to_put.append(page)
        ndb.put_multi(to_put)

        query_params = {"pdfId": pdfId, "comDate": self.request.get("committeeDateVal")}
        self.redirect("/change_input/committee?" + urllib.urlencode(query_params))
Пример #8
0
    def post(self,what):
        self.response.headers['Content-Type'] = 'text/plain'
        to_update = self.request.body.split('\n')
        to_update = [ json.loads(x) for x in to_update ]
        to_put = []
        to_delete = []
        for item in to_update:
            dbitem = None
            if what == "bl":
                dbitem = BudgetLine.query(BudgetLine.year==item['year'],BudgetLine.code==item['code']).fetch(1)
                if len(dbitem) == 0:
                    self.response.write("No budget item for year=%d, code=%s" % (item['year'],item['code']))
                    dbitem = BudgetLine()
                else:
                    for x in dbitem[1:]:
                        to_delete.append(x)
                    dbitem = dbitem[0]
                code = item['code']
                prefixes = [ code[:l] for l in range(2,len(code),2) ]
                prefixes.append(code)
                #self.response.write("%s==>%s\n" % (code,prefixes))
                item["prefixes"] = prefixes
                item["depth"] = len(code)/2 - 1

            if what == "cl":
                dbitem = ChangeLine.query(ChangeLine.year==item['year'],
                                          ChangeLine.leading_item==item['leading_item'],
                                          ChangeLine.req_code==item['req_code'],
                                          ChangeLine.budget_code==item['budget_code']).fetch(1)
                if len(dbitem) == 0:
                    self.response.write("No change item for year=%(year)d, leading_item=%(leading_item)d, req_code=%(req_code)d, code=%(budget_code)s" % item)
                    dbitem = ChangeLine()
                else:
                    for x in dbitem[1:]:
                        to_delete.append(x)
                    dbitem = dbitem[0]
                code = item['budget_code']
                prefixes = [ code[:l] for l in range(2,len(code),2) ]
                prefixes.append(code)
                #self.response.write(code+"==>"+repr(prefixes)+"\n")
                item["prefixes"] = prefixes
                if item.get('date') is not None and item['date'] != "":
                    try:
                        item['date'] = datetime.datetime.strptime(item['date'],'%d/%m/%Y')
                    except:
                        item['date'] = datetime.datetime.fromtimestamp(item['date']/1000.0)

            if what == "sh":
                dbitem = SearchHelper.query(SearchHelper.kind==item['kind'],SearchHelper.value==item['value'],SearchHelper.year==max(item['year'])).fetch(1000,batch_size=1000)
                if len(dbitem) == 0:
                    self.response.write("No searchhelper for kind=%(kind)s, value=%(value)s, year=%(year)r\n" % item)
                    dbitem = SearchHelper()
                else:
                    for x in dbitem[1:]:
                        to_delete.append(x)
                    dbitem = dbitem[0]                  
                item["prefix"] = None

            if what == "pcp":
                dbitem = PreCommitteePage.query(PreCommitteePage.pdf==blobstore.BlobKey(item['pdf']), PreCommitteePage.page==blobstore.BlobKey(item['page'])).fetch(100)
                if len(dbitem) == 0:
                    self.response.write("No PreCommitteePage for pdf=%(pdf)s, page=%(page)s\n" % item)
                    dbitem = PreCommitteePage()
                else:
                    for x in dbitem[1:]:
                        to_delete.append(x)
                    dbitem = dbitem[0]                  
                del item["pdf"]
                del item["page"]

            def mysetattr(i,k,v):
                orig_v = i.__getattribute__(k)
                if type(orig_v) == list and type(v) == list: 
                    orig_v.sort()
                    v.sort()
                    if json.dumps(orig_v) != json.dumps(v):
                        i.__setattr__(k,v)
                        self.response.write("%s: %s: %r != %r\n" % (i.key, k,orig_v,v))
                        return True
                else:
                    if orig_v != v:
                        i.__setattr__(k,v)
                        self.response.write("%s: %s: %r != %r\n" % (i.key, k,orig_v,v))
                        return True
                return False

            if dbitem is not None:
                dirty = False
                for k,v in item.iteritems():
                    dirty = mysetattr(dbitem,k,v) or dirty
                if dirty:
                    to_put.append(dbitem)

        if len(to_put) > 0:
            ndb.put_multi(to_put)
        if len(to_delete) > 0:
            ndb.delete_multi([x.key for x in to_delete])
        self.response.write("OK %d/%d-%d\n" % (len(to_put),len(to_update),len(to_delete)))