예제 #1
0
    def get(self):

		template_values = {
			'results': 'NOPE'
    	}

		utils.fillTemplate(self.response, 'draw.html', template_values)
예제 #2
0
    def get(self):
		user = users.get_current_user()
		if user:
			user_query = Participant.query(Participant.email == user.email())
			saved_user = user_query.fetch(1)
			participants_query = Participant.query().order(-Participant.date)
			participants = participants_query.fetch()
			template_values = {
				'participants': participants
			}
			
			if len(saved_user) > 0:
				template = 'joined.html'
				result_query = DrawResult.query(DrawResult.email == user.email())
				result = result_query.fetch(1)
				if len(result) > 0:
					template_values['result'] = '<h6>Your giftee is <b>%s</b></h6>' % result[0].giftee
				
			else:
				template = 'index.html'
				template_values['name'] = user.nickname()
				template_values['email'] = user.email()

			utils.fillTemplate(self.response, template, template_values)
		else:
			self.redirect(users.create_login_url(self.request.uri))
예제 #3
0
    def get(self):
        user = users.get_current_user()
        if user:
            user_query = Participant.query(Participant.email == user.email())
            saved_user = user_query.fetch(1)
            participants_query = Participant.query().order(-Participant.date)
            participants = participants_query.fetch()
            template_values = {'participants': participants}

            if len(saved_user) > 0:
                template = 'joined.html'
                result_query = DrawResult.query(
                    DrawResult.email == user.email())
                result = result_query.fetch(1)
                if len(result) > 0:
                    template_values[
                        'result'] = '<h6>Your giftee is <b>%s</b></h6>' % result[
                            0].giftee

            else:
                template = 'index.html'
                template_values['name'] = user.nickname()
                template_values['email'] = user.email()

            utils.fillTemplate(self.response, template, template_values)
        else:
            self.redirect(users.create_login_url(self.request.uri))
예제 #4
0
	def draw():

		participants_query = Participant.query()
		participants = participants_query.fetch()

		results = []
		length = len(participants)

		while length > 0:
			index = random.randrange(length)
			results.append(participants[index])
			del participants[index]
			length = len(participants)

		rs = ' -> '.join(str(p) for p in results)

		length = len(results)

		for i in range(0, length):
			result = results[i]
			giftee = ''
			if i == length - 1:
				giftee = results[0].name
			else:
				giftee = results[i+1].name

			draw_result = DrawResult(id=result.email, 
				name=result.name,
				email=result.email,
				giftee=giftee)
			draw_result.put()

			mail.send_mail(sender="*****@*****.**",
				to=result.email,
				subject="#new-york Secret Santya",
				body='Hi %s,\n\nYour secret-santya giftee is %s!\n\nLove,\nSatya' % (result.name, giftee),
				html="""
				<html><body>
				Hi %s,<br><br>
				Your secret-santya giftee is <b>%s</b>!<br><br>
				Love,<br>
				Satya
				</body></html>
				""" % (result.name, giftee))

		template_values = {
			'results': 'OK'
    	}

		utils.fillTemplate(self.response, 'draw.html', template_values)
예제 #5
0
    def post(self):
		user = users.get_current_user()
		if user:
			name = self.request.get('name')
			email = self.request.get('email')

			participant = Participant(id=email, name=name, email=email)
			participant.put()

			participants_query = Participant.query().order(-Participant.date)
			participants = participants_query.fetch()

			template_values = {
				'participants': participants
	    	}

			utils.fillTemplate(self.response, 'joined.html', template_values)
		else:
			self.redirect(users.create_login_url(self.request.uri))