-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.py
62 lines (54 loc) · 1.94 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# Opportunity Portal
#
# https://github.com/PeaceCorps/Opportunity-Portal
#
#
# For Questions email:[email protected]
# ------ Basic component ------
from __future__ import with_statement
import os
import webapp2
from google.appengine.ext.webapp import template
# ------ GAE Datastore -----
from google.appengine.ext import db
import dbmodel
class BaseHandler(webapp2.RequestHandler):
def render_template(self, file, template_args):
path = os.path.join(os.path.dirname(__file__), file)
self.response.out.write(template.render(path, template_args))
# Index
# -------------------
# We shouldd maintain the same file explore.html instead of copy and replace the old index.html
class indexHandler(BaseHandler):
def get(self):
self.render_template("explore.html", dict())
# Opportunity Handler
# -------------------
# This should display different opportunity base on the request get from filter page
# Use /opportunity instead of /opportunity/ is easier to develop without set up the GAE environment.
class opportunityHandler(BaseHandler):
def get(self):
self.render_template("opportunity.html", dict())
# Static File Handler
# -------------------
# This should be temporary handler for static files
# eventually we should decide which pages we are going to keep in our opt-finder
class staticFileHandler(BaseHandler):
def get(self, filename):
# Temporary host static filelist in this way
filelist = ["apply.html","about.html","contact.html","explore.html"]
if filename not in filelist:
self.error(404)
# Borrow 404 from github
self.render_template("404.html", dict())
return
self.render_template(filename, dict())
app = webapp2.WSGIApplication([
('/', indexHandler),
('/index.html', indexHandler),
('/opportunity', opportunityHandler),
('/([^/]+)?', staticFileHandler)
], debug=True)