def get(self): numADQuestions = Question.gql('WHERE product = :1', 'ADSync').count() numSPQuestions = Question.gql('WHERE product = :1', 'SharePoint Web Part').count() numSSOQuestions = Question.gql('WHERE product = :1', 'SSO').count() values = { 'numADQuestions': numADQuestions, 'numSPQuestions': numSPQuestions, 'numSSOQuestions': numSSOQuestions } self.response.out.write(template.render('templates/index.html', values))
def home(): questions = Question.gql( "WHERE aproved = 'yes'" ).fetch(limit=100) if (len(questions) != 0 and questions != None): random.shuffle(questions) top_yes = Question.gql( "WHERE aproved = 'yes' AND vote_yes !=0 ORDER BY vote_yes DESC" ).fetch(limit=3) top_no = Question.gql( "WHERE aproved = 'yes' AND vote_no!=0 ORDER BY vote_no DESC" ).fetch(limit=3) else: """ Nothing in the database, let's fill it up with some stock questions. """ stock_questions = ( "have DVDs", "have desktop computers", "have optical media in the same size and shape as CDs and DVDs", "have free bags with a purchase from a store", "have cheap wine in bottles", "have large grocery stores that you make orders from", "have CDs", "have written signatures on credit card receipts", "have paper receipts for purchases", "have large grocery stores that you visit in person", "have IPv4", "have credit cards based upon magnetic strips", "have voice-only phone calls", "have IPv6", "have refridgerator magnets", "have corks actually made out of cork", "have broadcast television", ) for question in stock_questions: q = Question(question=question, vote_yes=0, vote_no=0, total=0, aproved="yes") q.save() questions.append(q) top_yes = questions top_no = questions top_yes = [i for i in top_yes if i.vote_yes != 0] top_yes = [ { 'question': entry.question, 'key': entry.key(), 'total': entry.total, 'style': "style-" + str(int(float(Decimal(str(float(1.0*entry.vote_yes/entry.total)*100)).quantize(TWOPLACES)))), 'percent': float(Decimal(str(float(1.0*entry.vote_yes/entry.total)*100)).quantize(TWOPLACES)) } for entry in top_yes if entry.total != 0] top_yes.sort(lambda x, y: cmp(x['percent'], y['percent']), reverse=True) top_no = [i for i in top_no if i.vote_no != 0] top_no = [ { 'question': entry.question, 'key': entry.key(), 'total': entry.total, 'style': "style-" + str(100- int(float(Decimal(str(float(1.0*entry.vote_no/entry.total)*100)).quantize(TWOPLACES)))), 'percent': 100.00 - float(Decimal(str(float(1.0*entry.vote_no/entry.total)*100)).quantize(TWOPLACES)) } for entry in top_no if entry.total != 0] top_no.sort(lambda x, y: cmp(x['percent'], y['percent'])) return render_template('index.html', questions=questions, top_yes=top_yes, top_no=top_no)
def get_rev_set_raw(rev): qs = [] #first object to be the description of the revision lect_class = LectClass.get(rev.lect_class) rev_desc = { 'lecturer':rev.user.name, 'institution':rev.user.institution, 'title':rev.title, 'class':lect_class.name, 'description':rev.description, 'created':rev.created.strftime("%B %d, %Y") } qs.append(rev_desc) questions = Question.gql('WHERE revision = :1',rev).fetch(100) #how do we fetch all the Qs? for q in questions: answers = Answer.gql('WHERE question=:1',q) ans = [] for a in answers: ans.append(a.answer) question = { 'question':q.question.replace("\n","").replace("\r",""), 'answers':ans } qs.append(question) return qs
def post(self): newUser = Responder(name = self.request.get('name'), email = self.request.get('email'), company = self.request.get('company')) newUser.put() set = ResponseSet(product = 'ADSync', responder = newUser) set.put() adQuestions = Question.gql('WHERE product = :1', 'ADSync') htmlBody = '<h2>Response to ADSync Questionnaire</h2><p><i>Submitted by ' + newUser.name +', ' + newUser.email + '</i></p>' for adQuestion in adQuestions: responseText = self.request.get('response' + str(adQuestion.key().id())) response = Response(text = responseText, question = adQuestion, responseSet = set) response.put() htmlBody += '<h3>' + adQuestion.text + '</h3>' + '<p>' + response.text + '</p>' #send email notification sender = '*****@*****.**' recipients = ['*****@*****.**', '*****@*****.**', '*****@*****.**'] sub = newUser.name + ' from ' + newUser.company + ' responded to the ADSync Questionnaire' plainBody = 'Get response here: http://yammerie.appspot.com/responsesets?id=' + str(set.key().id()) mail.send_mail(sender, recipients, sub, plainBody, html = htmlBody) self.redirect('/adsuccess')
def random_question(qid=None): """Return a random question that isn't the one this was linked from""" questions = Question.gql( "WHERE aproved = 'yes'" ).fetch(limit=100) if (not questions == None): questions = [question for question in questions if question.key() != qid] random.shuffle(questions) question = questions.pop() return redirect("/question/%s/" % question.key())
def get_rev_set(rev): questions = Question.gql('WHERE revision = :1',rev).fetch(100) #how do we fetch all the Qs? qs = [] for q in questions: answers = Answer.gql('WHERE question=:1',q) comments = QuestionComment.gql('WHERE question=:1',q) comments_ = [] for c in comments: c_ = { 'comment':c.comment, 'ckey':c.key().__str__(), 'user':QAUser.get(c.ukey) } comments_.append(c_) question = { 'question':q, 'qkey':q.key().__str__(), 'answers':answers, 'comments':comments_, 'comment_count':comments.count() } qs.append(question) return qs
def get(self): ssoQuestions = Question.gql('WHERE product = :1', 'SSO') values = { 'ssoQuestions': ssoQuestions } self.response.out.write(template.render('templates/sso.html', values))
def get(self): spQuestions = Question.gql('WHERE product = :1', 'SharePoint Web Part') values = { 'spQuestions': spQuestions } self.response.out.write(template.render('templates/sharepoint.html', values))
def get(self): adQuestions = Question.gql('WHERE product = :1', 'ADSync') values = { 'adQuestions': adQuestions } self.response.out.write(template.render('templates/adsync.html', values))