legit


2013/1/23 gcapalbo <notifications@github.com>

> In corehq/apps/ivr/api.py:
>
> > @@ -21,6 +22,28 @@ def convert_media_path_to_hq_url(path, app):
> >          url_base = get_url_base()
> >          return url_base + HQMediaMapItem.format_match_map(path, media_type=media.media_type, media_id=media.multimedia_id)["url"] + "foo.wav"
> >
> > +"""
> > +Return True if answer is a valid response to question, False if not.
> > +(question is the XformsResponse object for the question)
> > +"""
> > +def validate_answer(answer, question):
> > +    if question.event.datatype == "select":
> > +        try:
> > +            assert answer is not None
> > +            answer = int(answer)
> > +            assert answer >= 1 and answer <= len(question.event.choices)
> > +            return True
>
> I typically only use the else with try/except when it's explicitly
> necessary. For cases like this where it doesn't matter I prefer to keep it
> simple.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/dimagi/core-hq/pull/501/files#r2746735>.
>
>