Example #1
0
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
Example #2
0
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
Example #3
0
 def index(self, format='html'):
     """GET /hunts: All items in the collection"""
     # url('hunts')
     d = []
     for hunt in Session.query(Hunt).all():
         d.append({'name': hunt.name, 'description': hunt.description})
     return dumps(d)
Example #4
0
 def index(self, format='html'):
     """GET /hunts: All items in the collection"""
     # url('hunts')
     d = []
     for hunt in Session.query(Hunt).all():
         d.append({'name': hunt.name, 'description': hunt.description})
     return dumps(d)
Example #5
0
 def create(self):
     """POST /hunts: Create a new hunt"""
     # url('hunts')
     if 'name' in request.params and 'description' in request.params:
         hunt = Hunt(request.params['name'], request.params['description'])
         Session.add(hunt)
         Session.commit()
         d = {
                 'status': 'ok',
                 'message': 'Successfully created hunt "%s"' % request.params['name'],
             }
     else:
         d = {
                 'status': 'failure',
                 'message': 'Name and description not posted.'
             }
     return dumps(d)
Example #6
0
 def new(self, format='html'):
     """GET /targets/new: Form to create a new item"""
     # url('new_target')
     # return "<html><body><form method=post action=/targets/create>name: <input name=name /><br />color: <input name=color /><br />description: <input name=description /><br />secret: <input name=secret /><br />location: <input name=location /><br />order#: <input type=number name=order /><br /><input type=submit></form></body></html>"
     hunts = Session.query(Hunt).all()
     c.hunts = []
     for hunt in hunts:
         c.hunts.append( (hunt.id, hunt.name) )
     return render('/api/codes/new.html')
Example #7
0
 def create(self):
     """POST /hunts: Create a new hunt"""
     # url('hunts')
     if 'name' in request.params and 'description' in request.params:
         hunt = Hunt(request.params['name'], request.params['description'])
         Session.add(hunt)
         Session.commit()
         d = {
             'status':
             'ok',
             'message':
             'Successfully created hunt "%s"' % request.params['name'],
         }
     else:
         d = {
             'status': 'failure',
             'message': 'Name and description not posted.'
         }
     return dumps(d)
Example #8
0
 def create(self):
     """POST /targets: Create a new item"""
     # url('targets')
     newqr = QR()
     Session.add(newqr)
     Session.flush()
     newtarget = HuntCode(0, newqr.id, request.params['name'], request.params['color'], request.params['description'], request.params['secret'], request.params['location'], int(request.params['order']))
     Session.add(newtarget)
     Session.commit()
     response.headers['Content-type'] = 'image/png'
     qr = urllib2.urlopen('http://chart.apis.google.com/chart?chs=480x480&cht=qr&chld=|0&chl='+str(newtarget.id)).read()
     return qr
Example #9
0
 def index(self, format='html'):
     """GET /targets: All items in the collection"""
     # url('targets')
     d = []
     for qr in Session.query(HuntQR).all():
         d.append( {
                 'qr_id': qr.qr_id,
                 'hunt_id': qr.hunt_id,
                 'name': qr.name,
                 } )
     return dumps(d)
Example #10
0
 def index(self, format='html'):
     """GET /targets: All items in the collection"""
     # url('targets')
     d = {}
     d['targets'] = []
     for target in Session.query(HuntCodes).all():
         d['targets'].append( {
                 'id': target.id,
                 'name': target.name,
                 'color': target.color,
                 } )
     return dumps(d)
Example #11
0
    def show(self, id, format='html'):
        """GET /targets/id: Show a specific item"""
        # url('target', id=ID)
        d = {}
        target = Session.query(Target).filter(Target.id==id).all()
        if len(target) == 0:
            d = {
                    'valid': False
                }
            return dumps(d)

        d = {
                'valid': True,
                'name': target[0].name,
                'color': target[0].color,
                'qr': 'http://chart.apis.google.com/chart?chs=480x480&cht=qr&chld=|0&chl='+str(target[0].id),
                }
        return dumps(d)
Example #12
0
    def show(self, id, format='html'):
        """GET /targets/id: Show a specific item"""
        # url('target', id=ID)
        d = {}
        huntqr = Session.query(HuntQR).filter(HuntQR.id==id).all()
        if len(huntqr) == 0:
            d = {
                    'valid': False
                }
            return dumps(d)

        d = {
                'valid': True,
                'name': huntqr[0].name,
                'color': huntqr[0].color,
                'description': huntqr[0].description,
                'secret': huntqr[0].secret,
                'location': huntqr[0].location,
                'order': huntqr[0].order,
                'qr': 'http://chart.apis.google.com/chart?chs=480x480&cht=qr&chld=|0&chl=http%3A%2F%2Fqrios.me%2F%3A%3A'+str(huntqr[0].id),
                }
        return dumps(d)
Example #13
0
 def create(self):
     """POST /targets: Create a new item"""
     # url('targets')
     newqr = QR()
     Session.add(newqr)
     Session.flush()
     Session.refresh(newqr)
     order = len(Session.query(HuntQR).filter_by(hunt_id=int(request.params['hunt'])).all())
     huntqr = HuntQR(
             int(request.params['hunt']), 
             newqr.id, 
             request.params['name'], 
             request.params['image'], 
             request.params['description'], 
             request.params['secret'], 
             request.params['location'], 
             order)
     Session.add(huntqr)
     Session.commit()
     response.headers['Content-type'] = 'image/png'
     qr = urllib2.urlopen('http://chart.apis.google.com/chart?chs=480x480&cht=qr&chld=|0&chl=http%3A%2F%2Fqrios.me%2F%3A%3A'+str(huntqr.id)).read()
     return qr
Example #14
0
def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    Session.configure(bind=engine)