Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 189 lines (159 sloc) 6.37 kb
99155172 »
2011-12-15 First commit
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
98486648 »
2012-05-04 fixed a bug - adding random lib
6 import logging, urllib, os, random
99155172 »
2011-12-15 First commit
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()))
7bc3dd02 »
2012-05-08 encrypted the html page sources, but pages are not displayed properly
32
99155172 »
2011-12-15 First commit
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'))
204f77fe »
2012-05-04 added encryption
54 hashcode = random_string()
99155172 »
2011-12-15 First commit
55 issue = Issue(
56 title = cgi.escape(self.request.get('title')),
57 description = cgi.escape(self.request.get('description')),
58 duration = duration_amount * multiplier,
7bc3dd02 »
2012-05-08 encrypted the html page sources, but pages are not displayed properly
59 urlcode = hashcode)
99155172 »
2011-12-15 First commit
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
204f77fe »
2012-05-04 added encryption
72 #self.redirect('/issue/%s' % (issue.key().id()))
7bc3dd02 »
2012-05-08 encrypted the html page sources, but pages are not displayed properly
73 self.redirect('/issue/%s' % issue.urlcode)
99155172 »
2011-12-15 First commit
74
75 class EditHandler(webapp.RequestHandler):
3cb829c4 »
2012-05-08 the logo is displayed
76 def get(self,urlcode):
99155172 »
2011-12-15 First commit
77 user = users.get_current_user()
78 if user:
79 logout_url = users.create_logout_url('/')
80 else:
81 self.redirect(users.create_login_url(self.request.uri))
82 return
7bc3dd02 »
2012-05-08 encrypted the html page sources, but pages are not displayed properly
83 #issue = Issue.get_by_id(int(id))
3cb829c4 »
2012-05-08 the logo is displayed
84 #issue = Issue.get_by_urlcode(urlcode)
85 #issue = Issue.get_issue_by_urlcode(urlcode)
99155172 »
2011-12-15 First commit
86 choices = issue.choices
87 self.response.out.write(template.render('templates/edit.html', locals()))
88
3cb829c4 »
2012-05-08 the logo is displayed
89 def post(self,urlcode):
99155172 »
2011-12-15 First commit
90 user = users.get_current_user()
91 if user:
92 logout_url = users.create_logout_url('/')
93 else:
94 self.redirect(users.create_login_url(self.request.uri))
95 return
7bc3dd02 »
2012-05-08 encrypted the html page sources, but pages are not displayed properly
96 #issue = Issue.get_by_id(int(id))
3cb829c4 »
2012-05-08 the logo is displayed
97 #issue = Issue.get_by_urlcode(urlcode)
98 #issue = Issue.get_issue_by_urlcode(urlcode)
99
99155172 »
2011-12-15 First commit
100 if self.request.get('extend'):#if extending vote
101 choices = issue.choices
102 extend_amount = int(self.request.get('extend_amount')) * int(self.request.get('extend_multiplier'))
103 issue.extend_duration(extend_amount)
104 self.response.out.write(template.render('templates/edit.html', locals()))
105
106 else:#otherwise we are saving changes
107 duration_amount = int(self.request.get('duration_amount'))
108 multiplier = int(self.request.get('duration_multiplier'))
109 issue.duration = duration_amount * multiplier
110 if self.request.get('title'):
111 issue.title = cgi.escape(self.request.get('title'))
112 if self.request.get('description'):
113 issue.description = cgi.escape(self.request.get('description'))
114 if self.request.get('option1') and self.request.get('option2'):
115 choices = issue.choices
116 db.delete(choices)
117 issue.add_choice(cgi.escape(self.request.get('option1')))
118 issue.add_choice(cgi.escape(self.request.get('option2')))
119 if self.request.get('option3'):
120 issue.add_choice(cgi.escape(self.request.get('option3')))
121 if self.request.get('option4'):
122 issue.add_choice(cgi.escape(self.request.get('option4')))
123 if self.request.get('option5'):
124 issue.add_choice(cgi.escape(self.request.get('option5')))
125 issue.put()
126 #choices = issue.choices
7bc3dd02 »
2012-05-08 encrypted the html page sources, but pages are not displayed properly
127 self.redirect('/issue/%s' % issue.urlcode)
99155172 »
2011-12-15 First commit
128 #self.response.out.write(template.render('templates/edit.html', locals()))
129
130
131
132 class IssueHandler(webapp.RequestHandler):
3cb829c4 »
2012-05-08 the logo is displayed
133 def get(self,urlcode):
134 # user = users.get_current_user()
135 # if user:
136 # logout_url = users.create_logout_url('/')
137 #else:
138 # self.redirect(users.create_login_url(self.request.uri))
139 # return
99155172 »
2011-12-15 First commit
140
7bc3dd02 »
2012-05-08 encrypted the html page sources, but pages are not displayed properly
141 #issue = Issue.get_by_id(int(id))
3cb829c4 »
2012-05-08 the logo is displayed
142 #issue = Issue.get_issue_by_urlcode(urlcode)
143 #issue = Issue.get_by_urlcode(urlcode)
144 #issue.update_status()
99155172 »
2011-12-15 First commit
145
3cb829c4 »
2012-05-08 the logo is displayed
146 #vote = issue.vote_for_member(user)
99155172 »
2011-12-15 First commit
147
3cb829c4 »
2012-05-08 the logo is displayed
148 #issueUrl = self.request.uri
149 #self.response.out.write(urlcode + '4')
150
151 self.response.out.write(template.render('templates/issue.html', locals()))
99155172 »
2011-12-15 First commit
152
153
3cb829c4 »
2012-05-08 the logo is displayed
154 def post(self,urlcode):
99155172 »
2011-12-15 First commit
155 user = users.get_current_user()
156 if not user: #don't want someone who is not authenticated to be able to vote
157 self.redirect(users.create_login_url(self.request.uri))
158 return
159
7bc3dd02 »
2012-05-08 encrypted the html page sources, but pages are not displayed properly
160 #issue = Issue.get_by_id(int(id))
3cb829c4 »
2012-05-08 the logo is displayed
161 #issue = Issue.get_by_url(urlcode)
162 #issue = Issue.get_issue_by_urlcode(urlcode)
99155172 »
2011-12-15 First commit
163 #vote = issue.vote_for_member()
164
165 new_choice = Choice.get_by_id(int(self.request.get('choice')))
166 was_updated = issue.register_vote(new_choice)
167
168 if was_updated:
169 self.redirect('/?success=updated')
170 else:
171 self.redirect('/?success=vote')
172
173
204f77fe »
2012-05-04 added encryption
174 def random_string():
175 hashbase = 'abcd1234'
176 return ''.join(random.sample(hashbase,len(hashbase)))
99155172 »
2011-12-15 First commit
177
178 def main():
179 application = webapp.WSGIApplication([
180 ('/',MainPage),
181 ('/new',NewHandler),
182 ('/issue/(\d+).*',IssueHandler),
183 ('/edit/(\d+).*',EditHandler)],
184 debug=True)
185 util.run_wsgi_app(application)
186
187 if __name__ == '__main__':
188 main()
Something went wrong with that request. Please try again.