Esempio n. 1
0
 def get_hotel(id):
     """Return a single hotel with room counts from the database."""
     hotel = Hotels.query.get_or_404(id)
     rooms = hotel.get_room_counts()
     hotel_fields = row2dict(hotel)
     hotel_fields = {**hotel_fields, **rooms}  # merge dictionaries
     return {"fields": hotel_fields, "objects": hotel}
Esempio n. 2
0
 def get_hotels():
     """Return a list of hotels with room counts from the database."""
     hotels = Hotels.query.all()
     hotel_list = []
     for hotel in hotels:
         rooms = hotel.get_room_counts()
         hotel = row2dict(hotel)
         hotel = {**hotel, **rooms}  # merge dictionaries
         hotel_list.append(hotel)
     return {"fields": hotel_list, "objects": hotels}
Esempio n. 3
0
 def serialize(self):
     """
     Serialize sqlalchemy row object into dictionary.
     """
     return row2dict(self)