Commit c6dcfd09 authored by Dominik Rosiek's avatar Dominik Rosiek

it works!

parent 2932d3dc
......@@ -203,6 +203,7 @@ class DDBTable(object):
message = yield gen.Task(self._dynamodb(operation='Scan').call,
TableName=self._get_table_name())
data = [self.decode_item(item=item) for item in message['Items']]
raise gen.Return(data)
......
......@@ -18,13 +18,11 @@ class MainHandler(tornado.web.RequestHandler):
#stations = self.get_stations()
#stations = models.Station.get_all()
#stations = models.Station.getall()
stations = yield models.Station.get("b1d12bb6-a3b7-43b8-b6ab-6d6e62cb794e")
s = stations.result()
stations = yield models.Station.get_all()
measurement = yield models.Measurement.get("5c2be10b-5d33-47d7-95fe-b3f6fc29a3af")
m = measurement.result()
self.write("{0} {1} {2} {3} {4}<br />".format(s.id, s.city, s.longitude, s.latitude, s.name))
for s in stations:
self.write("{0} {1} {2} {3} {4}<br />".format(s.id, s.city, s.longitude, s.latitude, s.name))
# measurement = models.Measurement.getlast(station=s.id)
# self.write("".format())
......
......@@ -9,7 +9,6 @@ from tornado.ioloop import IOLoop
class DDBobject(object):
@classmethod
@coroutine
def from_dict(cls, data):
return cls(**data)
......@@ -39,6 +38,16 @@ class Station(DDBobject):
result = yield DDBstations().add(station=self)
return result
@classmethod
@coroutine
def get_all(cls):
data = yield DDBstations().get_all()
return_value = []
for station in data:
return_value.append(cls.from_dict(station))
return return_value
class Type(DDBobject):
stored = {}
......@@ -84,11 +93,11 @@ class Measurement(DDBobject):
data = yield DDBmeasurements().get(measurement_id)
station = yield Station.get(data['station_id'])
data['station'] = station.result()
data['station'] = station
del data['station_id']
pollution_type = yield Type.get(data['type_id'])
data['pollution_type'] = pollution_type.result()
data['pollution_type'] = pollution_type
del data['type_id']
return cls.from_dict(data)
......@@ -97,3 +106,8 @@ class Measurement(DDBobject):
def save(self):
result = yield DDBmeasurements().add(measurement=self)
return result
@coroutine
def get_last(self, station_id):
# TODO
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment