Example #1
0
 def post(self):
     body_json = json.loads(cgi.escape(self.request.body))
     if 'email' not in body_json or 'reg_id' not in body_json:
         self.error(400)
         return
     email_addr = body_json['email']
     gcm_reg_id = body_json['reg_id']
     datastore.update(email_addr, gcm_reg_id)
Example #2
0
 def put(self):
     props = {k:v.getval() for k,v in self.properties.items()}
     if self.__class__.key(self.getval(self._primarykey)):
         datastore.update(self.__tablename__,where='%s=%s'%(self._primarykey,self.getval(self._primarykey)),**props)
     else:
         del props[self._primarykey]
         rowid = datastore.insert(self.__tablename__,**props)
         self.setval(self._primarykey,rowid)
     
     return self.getval(self._primarykey)
Example #3
0
File: orm.py Project: djfroese/orm
 def put(self):
     """Updates or Inserts the object into the database depending if it already exists or not.
     This is the one place where caching should absolutely NOT be done."""
     props = { k:v.getval() for k,v in self.properties.items() }
     
     where_key = {k:self.getval(k) for k in self._primarykeys}
     if self.__class__.key(**where_key):
         datastore.update(self.__tablename__,where=web.db.sqlwhere(where_key),**props)
     else:
         for key in self._primarykeys:
             del props[key]
         rowid = datastore.insert(self.__tablename__,**props)
         self.setval(self._primarykeys[0],rowid)
     ## return needs to handle no primary key, one primary key, multiple primary keys
     return self
Example #4
0
 def post(self):
     body_json = json.loads(cgi.escape(self.request.body))
     email_addr = body_json['payer_email']
     gcm_reg_id = datastore.retrieve(email_addr)
     if gcm_reg_id:
         result, message = gcm.send(gcm_reg_id, body_json)
         if message:
             logging.debug(result + ': ' + message)
         else:
             logging.debug(result)
         if result == 'success':
             if message is not None:
                 gcm_reg_id = message
                 datastore.update(email_addr, gcm_reg_id)
             self.response.set_status(200)
             self.response.write('OK')
         else:
             self.response.set_status(500)
             self.response.write(message)
     else:
         self.response.set_status(402)
         self.response.write(
                 "Email Not Found. Might haven't installed the app!")
Example #5
0
        if len(chal['members']) == 0:
            print("[WARN] challenge " + chal['name'] +
                  " was solved, but it doesn't have any member.")
            continue
        if len(chal['members']) == 1:
            ps = chal['score']
        else:
            #if not CheckScoreParam(chal['score_param'], chal['members']):
            #    print("[WARN] challenge "+chal['name']+" doesn't have score param or the people in the score param doesn't match the members. So the score will be divided equally to members in the card.")
            #    ps = int(round(chal['score']/len(chal['members'])))
            if m in chal['score_param']:
                ps = int(
                    round(chal['score'] *
                          (chal['score_param'][m] / chal['score_param_sum'])))
            elif len(chal['score_param']) == 0:
                ps = int(round(chal['score'] * (1 / len(chal['members']))))

        People[m]['score_list'][chal['name']] = ps
        People[m]['score'] += ps
import json
#print(People)

for p in People:
    r = Contest['rating'] * 10.0 * (People[p]['score'] /
                                    Contest['total_score'])
    r = round(r, 2)
    People[p]['rating'] = r

update(Contest, People, Challenges)

print(json.dumps(People, indent=2))