示例#1
0
 def make_tokens(self):
     session = DBSession()
     batch = TokenBatch()
     session.add(batch)
     session.flush()
     data = simplejson.loads(self.request.body)
     if not 'device_id' in data:
         return Response('You must provide an device_id')
     else:
         device = session.query(Device)\
             .filter_by(device_id=data['device_id']).first()
         if device:
             if not 'tokens' in data:
                 return Response('You must provide an amount of tokens')
             for group in data['tokens']:
                 for i in range(0, group['count']):
                     token = Token(Token.get_random(),
                                   batch=batch,
                                   value=group['denomination'])
                     session.add(token)
                     session.flush()
             return json_response(
                 [{'token_id': int(token.token),
                   'denomination':
                   float(token.value)} for token in batch.getTokens()])
         else:
             return json_response('Not a valid device')
示例#2
0
 def add_tokens(self):
     self.request.params
     batch = TokenBatch()
     self.session.add(batch)
     amount = self.request.params.get("amount", 100)
     value = int(self.request.params.get("value", 10))
     for number in xrange(0, int(amount)):
         self.session.add(Token(
                 token=Token.get_random(),
                 value=value,
                 batch=batch))
     return HTTPFound(location=self.request.application_url)