Skip to content
Newer
Older
100644 180 lines (150 sloc) 5.83 KB
9915517 @jonhull First commit
jonhull authored Dec 15, 2011
1 import cgi
2 from google.appengine.ext import webapp, db
3 from google.appengine.ext.webapp import util, template
4 from google.appengine.api import urlfetch, memcache, users, mail
5
9848664 fixed a bug - adding random lib
unknown authored May 4, 2012
6 import logging, urllib, os, random
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
7 from datetime import datetime, timedelta
8
9 from models import Issue, Choice, Vote
10
11
12 class MainPage(webapp.RequestHandler):
13 def get(self):
14 user = users.get_current_user()
15 if user:
16 logout_url = users.create_logout_url('/')
17 else:
18 login_url = users.create_login_url('/')
19 issues = Issue.all().order('creation_date').fetch(30)
20 success_type = self.request.get('success')
21 success_msg = None
22 if success_type == 'vote':
23 success_msg = 'Your vote was successfully cast!'
24 if success_type == 'updated':
25 success_msg = 'Your vote was successfully updated!'
26 created_by = Issue.issues_created_by(member=user,limit=20)
27 voted_on = Issue.issues_voted_on(member=user,limit=20)
28 #recent_results = [issue for issue in voted_on if issue.has_results]
29 recent_voted = [issue for issue in voted_on if issue.is_active()]
30 recent_results = Issue.recent_results(limit=20)
31 self.response.out.write(template.render('templates/overview.html', locals()))
7bc3dd0 encrypted the html page sources, but pages are not displayed properly
unknown authored May 8, 2012
32
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
33
34 class NewHandler(webapp.RequestHandler):
35 def get(self):
36 user = users.get_current_user()
37 if user:
38 logout_url = users.create_logout_url('/')
39 else:
40 self.redirect(users.create_login_url(self.request.uri))
41 return
42 option_one = "Yes"
43 option_two = "No"
44 self.response.out.write(template.render('templates/new.html', locals()))
45
46 def post(self):
47 user = users.get_current_user()
48 if not user:
49 self.redirect(users.create_login_url(self.request.uri))
50 return
51
52 duration_amount = int(self.request.get('duration_amount'))
53 multiplier = int(self.request.get('duration_multiplier'))
204f77f added encryption
unknown authored May 4, 2012
54 hashcode = random_string()
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
55 issue = Issue(
56 title = cgi.escape(self.request.get('title')),
57 description = cgi.escape(self.request.get('description')),
58 duration = duration_amount * multiplier,
7bc3dd0 encrypted the html page sources, but pages are not displayed properly
unknown authored May 8, 2012
59 urlcode = hashcode)
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
60 issue.put()
61 if self.request.get('option1'):
62 issue.add_choice(cgi.escape(self.request.get('option1')))
63 if self.request.get('option2'):
64 issue.add_choice(cgi.escape(self.request.get('option2')))
65 if self.request.get('option3'):
66 issue.add_choice(cgi.escape(self.request.get('option3')))
67 if self.request.get('option4'):
68 issue.add_choice(cgi.escape(self.request.get('option4')))
69 if self.request.get('option5'):
70 issue.add_choice(cgi.escape(self.request.get('option5')))
71
7bc3dd0 encrypted the html page sources, but pages are not displayed properly
unknown authored May 8, 2012
72 self.redirect('/issue/%s' % issue.urlcode)
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
73
74 class EditHandler(webapp.RequestHandler):
3cb829c the logo is displayed
unknown authored May 8, 2012
75 def get(self,urlcode):
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
76 user = users.get_current_user()
77 if user:
78 logout_url = users.create_logout_url('/')
79 else:
80 self.redirect(users.create_login_url(self.request.uri))
81 return
88685e7 final version
unknown authored May 8, 2012
82 issue = Issue.get_issue_by_urlcode(urlcode)
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
83 choices = issue.choices
84 self.response.out.write(template.render('templates/edit.html', locals()))
85
3cb829c the logo is displayed
unknown authored May 9, 2012
86 def post(self,urlcode):
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
87 user = users.get_current_user()
88 if user:
89 logout_url = users.create_logout_url('/')
90 else:
91 self.redirect(users.create_login_url(self.request.uri))
92 return
88685e7 final version
unknown authored May 9, 2012
93 issue = Issue.get_issue_by_urlcode(urlcode)
3cb829c the logo is displayed
unknown authored May 9, 2012
94
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
95 if self.request.get('extend'):#if extending vote
96 choices = issue.choices
97 extend_amount = int(self.request.get('extend_amount')) * int(self.request.get('extend_multiplier'))
98 issue.extend_duration(extend_amount)
99 self.response.out.write(template.render('templates/edit.html', locals()))
100
101 else:#otherwise we are saving changes
102 duration_amount = int(self.request.get('duration_amount'))
103 multiplier = int(self.request.get('duration_multiplier'))
104 issue.duration = duration_amount * multiplier
105 if self.request.get('title'):
106 issue.title = cgi.escape(self.request.get('title'))
107 if self.request.get('description'):
108 issue.description = cgi.escape(self.request.get('description'))
109 if self.request.get('option1') and self.request.get('option2'):
110 choices = issue.choices
111 db.delete(choices)
112 issue.add_choice(cgi.escape(self.request.get('option1')))
113 issue.add_choice(cgi.escape(self.request.get('option2')))
114 if self.request.get('option3'):
115 issue.add_choice(cgi.escape(self.request.get('option3')))
116 if self.request.get('option4'):
117 issue.add_choice(cgi.escape(self.request.get('option4')))
118 if self.request.get('option5'):
119 issue.add_choice(cgi.escape(self.request.get('option5')))
120 issue.put()
121 #choices = issue.choices
7bc3dd0 encrypted the html page sources, but pages are not displayed properly
unknown authored May 8, 2012
122 self.redirect('/issue/%s' % issue.urlcode)
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
123 #self.response.out.write(template.render('templates/edit.html', locals()))
124
125
126
127 class IssueHandler(webapp.RequestHandler):
3cb829c the logo is displayed
unknown authored May 9, 2012
128 def get(self,urlcode):
01a745e clean display
unknown authored May 8, 2012
129 user = users.get_current_user()
130 if user:
131 logout_url = users.create_logout_url('/')
132 else:
133 self.redirect(users.create_login_url(self.request.uri))
134 return
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
135
88685e7 final version
unknown authored May 9, 2012
136 issue = Issue.get_issue_by_urlcode(urlcode)
137 issue.update_status()
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
138
3cb829c the logo is displayed
unknown authored May 9, 2012
139 #vote = issue.vote_for_member(user)
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
140
3cb829c the logo is displayed
unknown authored May 9, 2012
141 #issueUrl = self.request.uri
142
143 self.response.out.write(template.render('templates/issue.html', locals()))
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
144
145
3cb829c the logo is displayed
unknown authored May 9, 2012
146 def post(self,urlcode):
01a745e clean display
unknown authored May 9, 2012
147 user = users.get_current_user()
148 if user:
149 logout_url = users.create_logout_url('/')
150 else:
25ea1da working logo displayed
unknown authored May 8, 2012
151 self.redirect(users.create_login_url(self.request.uri))
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
152
88685e7 final version
unknown authored May 9, 2012
153 issue = Issue.get_issue_by_urlcode(urlcode)
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
154 #vote = issue.vote_for_member()
155
25ea1da working logo displayed
unknown authored May 9, 2012
156 new_choice = Choice.get_by_id(int(self.request.get('choice')))
157 was_updated = issue.register_vote(new_choice)
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
158
25ea1da working logo displayed
unknown authored May 9, 2012
159 if was_updated:
160 self.redirect('/?success=updated')
161 else:
162 self.redirect('/?success=vote')
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
163
164
204f77f added encryption
unknown authored May 5, 2012
165 def random_string():
88685e7 final version
unknown authored May 9, 2012
166 hashbase = '1234567890abcdefghijklmnopqrstuvwxyz'
204f77f added encryption
unknown authored May 5, 2012
167 return ''.join(random.sample(hashbase,len(hashbase)))
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
168
169 def main():
170 application = webapp.WSGIApplication([
171 ('/',MainPage),
172 ('/new',NewHandler),
88685e7 final version
unknown authored May 9, 2012
173 ('/issue/(\w+).*',IssueHandler),
174 ('/edit/(\w+).*',EditHandler)],
9915517 @jonhull First commit
jonhull authored Dec 16, 2011
175 debug=True)
176 util.run_wsgi_app(application)
177
178 if __name__ == '__main__':
179 main()
Something went wrong with that request. Please try again.