def between(cls, answer, lowerlmt, upperlmt): if isinstance(answer, basestring): answer = extract_date(answer, dayfirst=True).date() if isinstance(lowerlmt, basestring): lowerlmt = extract_date(lowerlmt, dayfirst=True).date() if isinstance(upperlmt, basestring): upperlmt = extract_date(upperlmt, dayfirst=True).date() return upperlmt > answer >= lowerlmt
def validate_test_value(cls, value): '''Shall be used to validate that a given value is appropriate for this answer :return: ''' try: extract_date(value, fuzzy=True) except ValueError as ex: raise ValidationError([unicode(ex), ])
def validate_test_value(cls, value): '''Shall be used to validate that a given value is appropriate for this answer :return: ''' try: extract_date(value, fuzzy=True) except ValueError as ex: raise ValidationError([unicode(ex), ])
def between(cls, answer, lowerlmt, upperlmt): if isinstance(answer, basestring): answer = extract_date(answer, dayfirst=True).date() if isinstance(lowerlmt, basestring): lowerlmt = extract_date(lowerlmt, dayfirst=True).date() if isinstance(upperlmt, basestring): upperlmt = extract_date(upperlmt, dayfirst=True).date() return upperlmt > answer >= lowerlmt
def create(cls, interview, question, answer): raw_answer = answer if isinstance(answer, basestring): answer = extract_date(answer, dayfirst=False) # use zfill to normalize the string for comparism return super(DateAnswer, cls).create(interview, question, answer, as_text=raw_answer, as_value=cls.prep_value(answer) )
def create(cls, interview, question, answer): raw_answer = answer if isinstance(answer, basestring): answer = extract_date(answer, dayfirst=False) # use zfill to normalize the string for comparism return super(DateAnswer, cls).create(interview, question, answer, as_text=raw_answer, as_value=cls.prep_value(answer) )
def save_non_response(survey_tree, qset, survey, survey_allocation, access_channel, answer, reference_interview): interviewer = survey_allocation.interviewer extracted_date = extract_date(_get_nodes(CREATION_DATE_PATH, tree=survey_tree)[0].text, dayfirst=False) closure_date = extracted_date.replace(tzinfo=timezone.now().tzinfo) interview = Interview.objects.create(survey=survey, question_set=qset, ea=survey_allocation.allocation_ea, interviewer=interviewer, interview_channel=access_channel, closure_date=closure_date, interview_reference_id=reference_interview) return NonResponseAnswer.objects.create(interview=interview, value=answer, interviewer=interviewer)
def get_answers(node, qset, question_map, completion_date): """get answers for the node set. Would work for nested loops but for loops sitting in same inline question thread """ answers = [] inline_record = {} for e in node.getchildren(): if e.getchildren(): if _get_nodes('./creationDate', tree=e): completion_date = extract_date(_get_nodes('./creationDate', tree=e)[0].text, dayfirst=False) loop_answers = get_answers(e, qset, question_map, completion_date) _update_loop_answers(inline_record, loop_answers) answers.extend(loop_answers) else: inline_record['completion_date'] = completion_date inline_record[e.tag.strip('q')] = e.text question = question_map.get(e.tag.strip('q'), '') if question: _update_answer_dict(question, e.text, answers) if len(answers) == 0: # if there is no child here, you have to record the inline answers.append(inline_record) return answers
def create(cls, interview, question, answer, loop_id=Answer.NO_LOOP): if isinstance(answer, basestring): answer = extract_date(answer, fuzzy=True) question = question return cls.objects.create(question=question, value=answer, interview=interview, loop_id=loop_id)
def to_odk_date(cls, date_val): if isinstance(date_val, basestring): date_val = extract_date(date_val, dayfirst=True) return "date('%s')" % date_val.strftime('%Y-%m-%d')
def less_than(cls, answer, value): if isinstance(value, basestring): value = extract_date(value, dayfirst=True).date() if isinstance(answer, basestring): answer = extract_date(answer, dayfirst=True).date() return answer < value
def prep_value(cls, val): if isinstance(val, basestring): val = extract_date(val, dayfirst=False) # prepare as integer. for saving date_value = int(time.mktime(val.timetuple())) return unicode(date_value).zfill(cls.STRING_FILL_LENGTH)
def to_odk_date(cls, date_val): if isinstance(date_val, basestring): date_val = extract_date(date_val, dayfirst=True) return "date('%s')" % date_val.strftime('%Y-%m-%d')
def less_than(cls, answer, value): if isinstance(value, basestring): value = extract_date(value, dayfirst=True).date() if isinstance(answer, basestring): answer = extract_date(answer, dayfirst=True).date() return answer < value
def prep_value(cls, val): if isinstance(val, basestring): val = extract_date(val, dayfirst=False) # prepare as integer. for saving date_value = int(time.mktime(val.timetuple())) return unicode(date_value).zfill(cls.STRING_FILL_LENGTH)
def create(cls, interview, question, answer): if isinstance(answer, basestring): answer = extract_date(answer, fuzzy=True) question = question return cls.objects.create(question=question, value=answer, interview=interview)
def _get_default_date_created(survey_tree): date_string = _get_nodes(DEFAULT_DATE_CREATED_PATH, tree=survey_tree)[0].text if date_string: return extract_date(date_string, dayfirst=False) else: return datetime.now()