Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 99155172fb4da8021a364b7494ddca0e5a5ebc9a @jonhull jonhull committed Dec 16, 2011
@@ -0,0 +1,13 @@
+application: hackerdojo-vote
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /favicon.ico
+ static_files: static/favicon.ico
+ upload: static/favicon.ico
+- url: /static
+ static_dir: static
+- url: /.*
+ script: main.py
@@ -0,0 +1,49 @@
+indexes:
+
+# AUTOGENERATED
+
+# This index.yaml is automatically updated whenever the dev_appserver
+# detects that a new type of query is run. If you want to manage the
+# index.yaml file manually, remove the above marker line (the line
+# saying "# AUTOGENERATED"). If you want to manage some indexes
+# manually, move them above the marker line. The index.yaml file is
+# automatically uploaded to the admin console when you next deploy
+# your application using appcfg.py.
+
+- kind: Issue
+ properties:
+ - name: created_by
+ - name: creation_date
+
+- kind: Issue
+ properties:
+ - name: creator
+ - name: creation_date
+
+- kind: Issue
+ properties:
+ - name: creator
+ - name: creation_date
+ direction: desc
+
+- kind: Issue
+ properties:
+ - name: member
+ - name: creation_date
+
+- kind: Issue
+ properties:
+ - name: status
+ - name: end_time
+ direction: desc
+
+- kind: Vote
+ properties:
+ - name: member
+ - name: update_time
+
+- kind: Vote
+ properties:
+ - name: member
+ - name: update_time
+ direction: desc
178 main.py
@@ -0,0 +1,178 @@
+import cgi
+from google.appengine.ext import webapp, db
+from google.appengine.ext.webapp import util, template
+from google.appengine.api import urlfetch, memcache, users, mail
+
+import logging, urllib, os
+from datetime import datetime, timedelta
+
+from models import Issue, Choice, Vote
+
+
+class MainPage(webapp.RequestHandler):
+ def get(self):
+ user = users.get_current_user()
+ if user:
+ logout_url = users.create_logout_url('/')
+ else:
+ login_url = users.create_login_url('/')
+ issues = Issue.all().order('creation_date').fetch(30)
+ success_type = self.request.get('success')
+ success_msg = None
+ if success_type == 'vote':
+ success_msg = 'Your vote was successfully cast!'
+ if success_type == 'updated':
+ success_msg = 'Your vote was successfully updated!'
+ created_by = Issue.issues_created_by(member=user,limit=20)
+ voted_on = Issue.issues_voted_on(member=user,limit=20)
+ #recent_results = [issue for issue in voted_on if issue.has_results]
+ recent_voted = [issue for issue in voted_on if issue.is_active()]
+ recent_results = Issue.recent_results(limit=20)
+ self.response.out.write(template.render('templates/overview.html', locals()))
+
+
+
+class NewHandler(webapp.RequestHandler):
+ def get(self):
+ user = users.get_current_user()
+ if user:
+ logout_url = users.create_logout_url('/')
+ else:
+ self.redirect(users.create_login_url(self.request.uri))
+ return
+ option_one = "Yes"
+ option_two = "No"
+ self.response.out.write(template.render('templates/new.html', locals()))
+
+ def post(self):
+ user = users.get_current_user()
+ if not user:
+ self.redirect(users.create_login_url(self.request.uri))
+ return
+
+ duration_amount = int(self.request.get('duration_amount'))
+ multiplier = int(self.request.get('duration_multiplier'))
+ issue = Issue(
+ title = cgi.escape(self.request.get('title')),
+ description = cgi.escape(self.request.get('description')),
+ duration = duration_amount * multiplier,
+ )
+ issue.put()
+ if self.request.get('option1'):
+ issue.add_choice(cgi.escape(self.request.get('option1')))
+ if self.request.get('option2'):
+ issue.add_choice(cgi.escape(self.request.get('option2')))
+ if self.request.get('option3'):
+ issue.add_choice(cgi.escape(self.request.get('option3')))
+ if self.request.get('option4'):
+ issue.add_choice(cgi.escape(self.request.get('option4')))
+ if self.request.get('option5'):
+ issue.add_choice(cgi.escape(self.request.get('option5')))
+
+ self.redirect('/issue/%s' % (issue.key().id()))
+
+
+
+class EditHandler(webapp.RequestHandler):
+ def get(self,id):
+ user = users.get_current_user()
+ if user:
+ logout_url = users.create_logout_url('/')
+ else:
+ self.redirect(users.create_login_url(self.request.uri))
+ return
+ issue = Issue.get_by_id(int(id))
+ choices = issue.choices
+ self.response.out.write(template.render('templates/edit.html', locals()))
+
+ def post(self,id):
+ user = users.get_current_user()
+ if user:
+ logout_url = users.create_logout_url('/')
+ else:
+ self.redirect(users.create_login_url(self.request.uri))
+ return
+ issue = Issue.get_by_id(int(id))
+
+
+ if self.request.get('extend'):#if extending vote
+ choices = issue.choices
+ extend_amount = int(self.request.get('extend_amount')) * int(self.request.get('extend_multiplier'))
+ issue.extend_duration(extend_amount)
+ self.response.out.write(template.render('templates/edit.html', locals()))
+
+ else:#otherwise we are saving changes
+ duration_amount = int(self.request.get('duration_amount'))
+ multiplier = int(self.request.get('duration_multiplier'))
+ issue.duration = duration_amount * multiplier
+ if self.request.get('title'):
+ issue.title = cgi.escape(self.request.get('title'))
+ if self.request.get('description'):
+ issue.description = cgi.escape(self.request.get('description'))
+ if self.request.get('option1') and self.request.get('option2'):
+ choices = issue.choices
+ db.delete(choices)
+ issue.add_choice(cgi.escape(self.request.get('option1')))
+ issue.add_choice(cgi.escape(self.request.get('option2')))
+ if self.request.get('option3'):
+ issue.add_choice(cgi.escape(self.request.get('option3')))
+ if self.request.get('option4'):
+ issue.add_choice(cgi.escape(self.request.get('option4')))
+ if self.request.get('option5'):
+ issue.add_choice(cgi.escape(self.request.get('option5')))
+ issue.put()
+ #choices = issue.choices
+ self.redirect('/issue/%s' % (id))
+ #self.response.out.write(template.render('templates/edit.html', locals()))
+
+
+
+class IssueHandler(webapp.RequestHandler):
+ def get(self,id):
+ user = users.get_current_user()
+ if user:
+ logout_url = users.create_logout_url('/')
+ else:
+ self.redirect(users.create_login_url(self.request.uri))
+ return
+
+ issue = Issue.get_by_id(int(id))
+ issue.update_status()
+
+ vote = issue.vote_for_member(user)
+
+ issueUrl = self.request.uri
+ self.response.out.write(template.render('templates/Issue.html', locals()))
+
+
+ def post(self,id):
+ user = users.get_current_user()
+ if not user: #don't want someone who is not authenticated to be able to vote
+ self.redirect(users.create_login_url(self.request.uri))
+ return
+
+ issue = Issue.get_by_id(int(id))
+ #vote = issue.vote_for_member()
+
+ new_choice = Choice.get_by_id(int(self.request.get('choice')))
+ was_updated = issue.register_vote(new_choice)
+
+ if was_updated:
+ self.redirect('/?success=updated')
+ else:
+ self.redirect('/?success=vote')
+
+
+
+
+def main():
+ application = webapp.WSGIApplication([
+ ('/',MainPage),
+ ('/new',NewHandler),
+ ('/issue/(\d+).*',IssueHandler),
+ ('/edit/(\d+).*',EditHandler)],
+ debug=True)
+ util.run_wsgi_app(application)
+
+if __name__ == '__main__':
+ main()
Oops, something went wrong.

0 comments on commit 9915517

Please sign in to comment.