geholimportapp / main.py

import os

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from status import is_status_down, get_last_status_update
from check_status import UpdateGeholStatus
from coursecalendar import CourseCalendar
from icalrenderer import IcalRenderer
from csvrenderer import CSVRenderer
from studentsetcalendar import StudentSetSummary, StudentSetIcalRenderer
from savedrequests import PreviousRequest, PreviousStudentSetRequests


class MainPage(webapp.RequestHandler):
    def get(self):
        last_fetched_courses = self._get_last_entries_from_store(PreviousRequest)
        last_fetched_studentsets = self._get_last_entries_from_store(PreviousStudentSetRequests)

        template_values = {'last_courses': last_fetched_courses,
                           'last_studentsets':last_fetched_studentsets,
                           'gehol_is_down': is_status_down(),
                           'last_status_update': get_last_status_update()
                        }

        path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
        self.response.out.write(template.render(path, template_values))


    def _get_last_entries_from_store(self, Datastore):
        # TODO : see if we can filter the last 10 entries earlier
        query = Datastore.all().order('-date')
        return query.fetch(10)


class Redirect(webapp.RequestHandler):
    def post(self):
        course_mnemo = self.request.get('course_mnemo')
        if course_mnemo:
            self.redirect("/course/%s" % course_mnemo.upper())
        else:
            gehol_url = self.request.get('gehol_url')
            if gehol_url:
                group_id = StudentSetSummary._extract_group_id(gehol_url)
                self.redirect("/student_set/%s" % group_id)
            else:
                self.redirect("/")



application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                     ('/redirect', Redirect),
                                     ('/course/ical/.*', IcalRenderer),
                                     ('/course/csv/.*', CSVRenderer),
                                     ('/course/.*', CourseCalendar),
                                     ('/geholstatus',  UpdateGeholStatus),
                                     ('/student_set/ical/q./.*\.ics', StudentSetIcalRenderer),
                                     ('/student_set/.*', StudentSetSummary )
                                     ],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.