Пример #1
0
def all_responses():
    log("Getting all responses")
    fs = SurveyResponse.all().fetch(100)
    while fs:
        for f in fs:
            yield f
        fs = SurveyResponse.all().filter('__key__ >', fs[-1].key()).fetch(100)
Пример #2
0
 def save(self):
     survey_response = SurveyResponse(
         parent=self.candidacy,
         agreement=int(self.cleaned_data['agreement']),
         refined_issue=self.refined_issue.key(),
         more_explanation=self.cleaned_data['more_explanation'],
         candidacy=self.candidacy.key(),
         national=self.national)
     survey_response.put()
Пример #3
0
 def save(self):
     survey_response = SurveyResponse(
         parent = self.candidacy,
         agreement = int(self.cleaned_data['agreement']),
         refined_issue = self.refined_issue.key(),
         more_explanation = self.cleaned_data['more_explanation'],
         candidacy = self.candidacy.key()
     )
     survey_response.put()
Пример #4
0
 def post(self):
     survey_response = SurveyResponse()
     try:  # HTTP_X_APPENGINE_CITY is added when deployed
         survey_response.city = os.environ[
             'HTTP_X_APPENGINE_CITY']  # Categorize by location
     except:
         pass
     survey_response.user_agent = os.environ[
         'HTTP_USER_AGENT']  # Categorize by browser type
     survey_response.opinion = self.request.get('opinion')
     survey_response.improvements = self.request.get('improvements')
     survey_response.rating = self.request.get('rating')
     logging.info(survey_response)
     survey_response.put()
     self.render_template('survey-thank_you.html')
Пример #5
0
 def post(self):
     survey_response = SurveyResponse()
     try: # HTTP_X_APPENGINE_CITY is added when deployed
         survey_response.city = os.environ['HTTP_X_APPENGINE_CITY'] # Categorize by location
     except:
         pass
     survey_response.user_agent = os.environ['HTTP_USER_AGENT'] # Categorize by browser type
     survey_response.opinion = self.request.get('opinion')
     survey_response.improvements = self.request.get('improvements')
     survey_response.rating = self.request.get('rating')
     logging.info(survey_response)
     survey_response.put()
     self.render_template('survey-thank_you.html')
Пример #6
0
def getSurveys():
    s1 = SurveyResponse.all().filter('formID','1').fetch(100)
    s2 = SurveyResponse.all().filter('formID','2').fetch(100)
    r1 = []
    r2 = []
    for s in s1:
        resDic = {}
        for ss in s.answers:
            splitter = re.search(r'(.*) --- (.*)',ss)
            if splitter is None:
                continue
            if splitter.group(1) == 'device_id':
                resDic['0'] = splitter.group(2)
                continue
            result = re.search(r'element_([0-9]*) --- (.*)',ss)
            if result is not None:
                resDic[result.group(1)] = result.group(2)
            
        r1.append(resDic)
        
    for s in s2:
        resDic = {}
        for ss in s.answers:
            splitter = re.search(r'(.*) --- (.*)',ss)
            if splitter is None:
                continue
            if splitter.group(1) == 'device_id':
                resDic['0'] = splitter.group(2)
                continue
            result = re.search(r'element_([0-9]*) --- (.*)',ss)
            if result is not None:
                resDic[result.group(1)] = result.group(2)
            
        r2.append(resDic)
        
    r = {'1':r1,'2':r2}
    return str(r)
Пример #7
0
 def upsert(self, user, answers):
     survey = user.survey
     for column, answer in answers.items():
         # handle singular list responses--this conflicts with the sepcial
         # case handling for MTL Trajet 2018. This is reverted by the special case
         # function and should be handled better.
         if isinstance(answer, list) and len(answer) == 1:
             answer = answer[0]
         text_answer = self._map_hardcoded_ints(survey, column, answer)
         answers[column] = text_answer
     if user.survey_response.one_or_none():
         response = user.survey_response
         response.answers = answers
     else:
         response = SurveyResponse(
             survey_id=survey.id,
             mobile_id=user.id,
             response=answers)
         db.session.add(response)
     db.session.commit()
     return response