Пример #1
0
 def index(self):
     max = DBSession.query(func.max(Sensor.lat)).one()[0]
     min = DBSession.query(func.min(Sensor.lat)).one()[0]
     lat = (max + min) / 2
     max = DBSession.query(func.max(Sensor.lng)).one()[0]
     min = DBSession.query(func.min(Sensor.lng)).one()[0]
     lng = (max + min) / 2
     return dict(page='map', lat=lat, lng=lng)
Пример #2
0
 def update(self, id=1, flooded=False):
     id = int(id)
     try:
         s = DBSession.query(Sensor).filter_by(id=id).one()
     except NoResultFound:
         return str(id) + " not found"
     s.flooded = flooded=='True'
     return "Success", flooded, s.flooded
Пример #3
0
 def sensors(self):
     sens = []
     for row in DBSession.query(Sensor).all():
         s = {}
         s["name"] = row.name
         s["lat"] = row.lat
         s["lng"] = row.lng
         s["flooded"] = row.flooded
         s["id"] = row.id
         sens.append(s)
     return dict(sensors=sens)
Пример #4
0
 def setup(self):
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Пример #5
0
 def test_query_obj(self):
     obj = DBSession.query(self.klass).one()
     for key, value in self.attrs.iteritems():
         assert_equals(getattr(obj, key), value)
Пример #6
0
 def tearDown(self):
     DBSession.rollback()