Commits

Juarez Bochi committed e271a1f

Handling departures properly

  • Participants
  • Parent commits 3e1455e

Comments (0)

Files changed (3)

 from google.appengine.ext.webapp.util import run_wsgi_app
 import os
 
-from models import Airport, Arrival, Departure
+from models import Airport, Arrival, Departure, Event
 from util import prefetch_refprop
 
 class MyRequestHandler(webapp.RequestHandler):
 class EventHandler(MyRequestHandler):
     def get_by_event_type(self, iata_code, departure):
         airport = Airport.all().filter('iata_code =', iata_code).get()
-        EventModel = Departure if departure else Arrival
+        if departure:
+            query = Departure.all().filter('source =', airport)
+        else:
+            query = Arrival.all().filter('destination =', airport)
 
-        events = EventModel.all().filter('destination =', airport)\
-                                 .filter('date =', date.today())\
-                                 .order('confirmed').fetch(1000)
+        events = query.filter('date =', date.today())\
+                      .order('confirmed').fetch(1000)
 
-        prefetch_refprop(events, EventModel.company)
-        prefetch_refprop(events, EventModel.source)
+        prefetch_refprop(events, Event.company)
+        prefetch_refprop(events, Event.source)
 
         template_values = {'airport': airport,
                            'events': events,

File src/index.yaml

   - name: date
   - name: destination
   - name: confirmed
+
+- kind: Event
+  properties:
+  - name: class
+  - name: date
+  - name: source
+  - name: confirmed

File src/templates/panel.html

                         <td>{{ event.flight_number|floatformat }}</td>
                         <td>{{ event.estimation|time:"H:i" }}</td>
                         <td>{{ event.confirmed|time:"H:i" }}</td>
-                        <td class="airport">{{ event.source.infraero_name }}</td>
+                        <td class="airport">
+                            {% if departure %}
+                                {{ event.destination.infraero_name }}
+                            {% else %}
+                                {{ event.source.infraero_name }}
+                            {% endif %}
+                        </td>                        
                         <td class="status">{{ event.status }}</td>
                     </tr>
                 {% endfor %}