Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 181 lines (147 sloc) 5.801 kB
9915517 @jonhull First commit
jonhull authored
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
6 import logging, urllib, os
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('/')
84f2ac5 @dustball Added some styling, public/private as well as showing public on home …
dustball authored
19 issues = Issue.all().order('-creation_date').filter('visibility',"public").fetch(30)
9915517 @jonhull First commit
jonhull authored
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!'
84f2ac5 @dustball Added some styling, public/private as well as showing public on home …
dustball authored
26 #created_by = Issue.issues_created_by(member=user,limit=20)
27 #voted_on = Issue.issues_voted_on(member=user,limit=20)
9915517 @jonhull First commit
jonhull authored
28 #recent_results = [issue for issue in voted_on if issue.has_results]
84f2ac5 @dustball Added some styling, public/private as well as showing public on home …
dustball authored
29 #recent_voted = [issue for issue in voted_on if issue.is_active()]
30 #recent_results = Issue.recent_results(limit=20)
9915517 @jonhull First commit
jonhull authored
31 self.response.out.write(template.render('templates/overview.html', locals()))
32
33
34
35 class NewHandler(webapp.RequestHandler):
36 def get(self):
37 user = users.get_current_user()
38 if user:
39 logout_url = users.create_logout_url('/')
40 else:
41 self.redirect(users.create_login_url(self.request.uri))
42 return
43 option_one = "Yes"
44 option_two = "No"
45 self.response.out.write(template.render('templates/new.html', locals()))
46
47 def post(self):
48 user = users.get_current_user()
49 if not user:
50 self.redirect(users.create_login_url(self.request.uri))
51 return
52
53 duration_amount = int(self.request.get('duration_amount'))
54 multiplier = int(self.request.get('duration_multiplier'))
84f2ac5 @dustball Added some styling, public/private as well as showing public on home …
dustball authored
55 visibility = self.request.get('visibility')
9915517 @jonhull First commit
jonhull authored
56 issue = Issue(
84f2ac5 @dustball Added some styling, public/private as well as showing public on home …
dustball authored
57 visibility = visibility,
9915517 @jonhull First commit
jonhull authored
58 title = cgi.escape(self.request.get('title')),
59 description = cgi.escape(self.request.get('description')),
60 duration = duration_amount * multiplier,
61 )
62 issue.put()
63 if self.request.get('option1'):
64 issue.add_choice(cgi.escape(self.request.get('option1')))
65 if self.request.get('option2'):
66 issue.add_choice(cgi.escape(self.request.get('option2')))
67 if self.request.get('option3'):
68 issue.add_choice(cgi.escape(self.request.get('option3')))
69 if self.request.get('option4'):
70 issue.add_choice(cgi.escape(self.request.get('option4')))
71 if self.request.get('option5'):
72 issue.add_choice(cgi.escape(self.request.get('option5')))
73
74 self.redirect('/issue/%s' % (issue.key().id()))
75
76
77
78 class EditHandler(webapp.RequestHandler):
79 def get(self,id):
80 user = users.get_current_user()
81 if user:
82 logout_url = users.create_logout_url('/')
83 else:
84 self.redirect(users.create_login_url(self.request.uri))
85 return
86 issue = Issue.get_by_id(int(id))
87 choices = issue.choices
88 self.response.out.write(template.render('templates/edit.html', locals()))
89
90 def post(self,id):
91 user = users.get_current_user()
92 if user:
93 logout_url = users.create_logout_url('/')
94 else:
95 self.redirect(users.create_login_url(self.request.uri))
96 return
97 issue = Issue.get_by_id(int(id))
98
99
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
127 self.redirect('/issue/%s' % (id))
128 #self.response.out.write(template.render('templates/edit.html', locals()))
129
130
131
132 class IssueHandler(webapp.RequestHandler):
133 def get(self,id):
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
140
141 issue = Issue.get_by_id(int(id))
142 issue.update_status()
143
144 vote = issue.vote_for_member(user)
145
146 issueUrl = self.request.uri
6da2c88 @dustball Fix typo
dustball authored
147 self.response.out.write(template.render('templates/issue.html', locals()))
9915517 @jonhull First commit
jonhull authored
148
149
150 def post(self,id):
151 user = users.get_current_user()
152 if not user: #don't want someone who is not authenticated to be able to vote
153 self.redirect(users.create_login_url(self.request.uri))
154 return
155
156 issue = Issue.get_by_id(int(id))
157 #vote = issue.vote_for_member()
158
159 new_choice = Choice.get_by_id(int(self.request.get('choice')))
160 was_updated = issue.register_vote(new_choice)
161
162 if was_updated:
163 self.redirect('/?success=updated')
164 else:
165 self.redirect('/?success=vote')
166
167
168
169
170 def main():
171 application = webapp.WSGIApplication([
172 ('/',MainPage),
173 ('/new',NewHandler),
174 ('/issue/(\d+).*',IssueHandler),
175 ('/edit/(\d+).*',EditHandler)],
176 debug=True)
177 util.run_wsgi_app(application)
178
179 if __name__ == '__main__':
180 main()
Something went wrong with that request. Please try again.