def save_opinion_from_form(request, type, ua, form): """Given a (valid) form and feedback type, save it to the DB.""" locale = detect_language(request) # Remove URL if checkbox disabled or no URL submitted. Broken Website # report does not have the option to disable URL submission. if type != input.OPINION_BROKEN.id and not ( form.cleaned_data.get("add_url", False) and form.cleaned_data.get("url") ): form.cleaned_data["url"] = "" if type not in input.OPINION_TYPES: raise ValueError("Unknown type %s" % type) opinion = Opinion( _type=type, url=form.cleaned_data.get("url", ""), description=form.cleaned_data["description"], user_agent=ua, locale=locale, manufacturer=form.cleaned_data["manufacturer"], device=form.cleaned_data["device"], ) opinion.save() return opinion
def save_opinion_from_form(request, type, ua, form): """Given a (valid) form and feedback type, save it to the DB.""" locale = detect_language(request) # Remove URL if checkbox disabled or no URL submitted. Broken Website # report does not have the option to disable URL submission. if (type != input.OPINION_BROKEN.id and not (form.cleaned_data.get('add_url', False) and form.cleaned_data.get('url'))): form.cleaned_data['url'] = '' if type not in input.OPINION_TYPES: raise ValueError('Unknown type %s' % type) if type != input.OPINION_RATING.id: return Opinion( type=type, url=form.cleaned_data.get('url', ''), description=form.cleaned_data['description'], user_agent=ua, locale=locale, manufacturer=form.cleaned_data['manufacturer'], device=form.cleaned_data['device']).save() else: opinion = Opinion( type=type, user_agent=ua, locale=locale) opinion.save() for question in input.RATING_USAGE: value = form.cleaned_data.get(question.short) if not value: continue Rating(opinion=opinion, type=question.id, value=value).save() return opinion
def test_detect_language(): """Check Accept-Language matching for feedback submission.""" patterns = ( ('en-us,en;q=0.7,de;q=0.8', 'en-US'), ('fr-FR,de-DE;q=0.5', 'fr'), ('zh, en-us;q=0.8, en;q=0.6', 'en-US'), ('German', ''), # invalid ) for pattern in patterns: req = http.HttpRequest() req.META['HTTP_ACCEPT_LANGUAGE'] = pattern[0] eq_(detect_language(req), pattern[1])
def save_opinion_from_form(request, type, ua, form): """Given a (valid) form and feedback type, save it to the DB.""" locale = detect_language(request) if type not in input.OPINION_TYPES: raise ValueError('Unknown type %s' % type) opinion = Opinion(_type=type, url=form.cleaned_data.get('url') or '', description=form.cleaned_data['description'], user_agent=ua, locale=locale, manufacturer=form.cleaned_data['manufacturer'], device=form.cleaned_data['device']) opinion.save() return opinion
def save_opinion_from_form(request, type, ua, form): """Given a (valid) form and feedback type, save it to the DB.""" locale = detect_language(request) if type not in input.OPINION_TYPES: raise ValueError('Unknown type %s' % type) opinion = Opinion( _type=type, url=form.cleaned_data.get('url') or '', description=form.cleaned_data['description'], user_agent=ua, locale=locale, manufacturer=form.cleaned_data['manufacturer'], device=form.cleaned_data['device']) opinion.save() return opinion
def save_opinion_from_form(request, type, ua, form): """Given a (valid) form and feedback type, save it to the DB.""" locale = detect_language(request) # Remove URL if checkbox disabled or no URL submitted. Broken Website # report does not have the option to disable URL submission. if (type != input.OPINION_BROKEN.id and not (form.cleaned_data.get('add_url', False) and form.cleaned_data.get('url'))): form.cleaned_data['url'] = '' if type not in input.OPINION_TYPES: raise ValueError('Unknown type %s' % type) return Opinion( type=type, url=form.cleaned_data.get('url', ''), description=form.cleaned_data['description'], user_agent=ua, locale=locale, manufacturer=form.cleaned_data['manufacturer'], device=form.cleaned_data['device']).save()