def test_render_no_locale(self, django_render, get_lang_path): # Our render method doesn't blow up if the request has no .locale # (can happen on 500 error path, for example) get_lang_path.return_value = None request = Mock(spec=object) # Note: no .locale on request # Should not cause an exception render(request, None)
def windows_billboards(req): major_version = req.GET.get('majorVersion') minor_version = req.GET.get('minorVersion') if major_version and minor_version: major_version = float(major_version) minor_version = float(minor_version) if major_version == 5 and minor_version == 1: return l10n_utils.render(req, 'firefox/unsupported-winxp.html') return l10n_utils.render(req, 'firefox/unsupported-win2k.html')
def channel(request): data = {} if 'mobile_first' in request.GET: data['mobile_first'] = True return l10n_utils.render(request, "mozorg/channel.html", data)
def contribute_page(request): form = ContributeForm(request.POST or None) success = handle_contribute_form(request, form) return l10n_utils.render(request, 'mozorg/contribute-page.html', { 'form': form, 'success': success })
def marketplace(request): submitted = False error = False email = '' if request.method == 'POST': email = request.POST['email'] format_ = 'T' if request.POST.get('format') == 'text' else 'H' newsletter = 'app-dev' if not email_re.match(email): error = 'email' if not request.POST.get('privacy', None): error = 'privacy' if not error: basket.subscribe(email, newsletter, format=format_) submitted = True return l10n_utils.render(request, "marketplace/marketplace.html", {'submitted': submitted, 'error': error, 'email': email})
def contribute_page(request): form = ContributeForm(request.POST or None) success = handle_contribute_form(request, form) return l10n_utils.render(request, 'mozorg/contribute-page.html', {'form': form, 'success': success})
def all_downloads(request): version = firefox_details.latest_version('release') query = request.GET.get('q') return l10n_utils.render(request, 'firefox/all.html', { 'full_builds': firefox_details.get_filtered_full_builds(version, query), 'test_builds': firefox_details.get_filtered_test_builds(version, query), 'query': query, })
def partnerships(request): form = WebToLeadForm() template_vars = {} template_vars.update(csrf(request)) template_vars['form'] = form return l10n_utils.render(request, 'mozorg/partnerships.html', template_vars)
def contribute(request, template, return_to_form): has_contribute_form = (request.method == 'POST' and 'contribute-form' in request.POST) has_newsletter_form = (request.method == 'POST' and 'newsletter-form' in request.POST) locale = getattr(request, 'locale', 'en-US') contribute_success = False newsletter_success = False # This is ugly, but we need to handle two forms. I would love if # these forms could post to separate pages and get redirected # back, but we're forced to keep the error/success workflow on the # same page. Please change this. if has_contribute_form: form = ContributeForm(request.POST) contribute_success = email_contribute.handle_form(request, form) if contribute_success: # If form was submitted successfully, return a new, empty # one. form = ContributeForm() else: form = ContributeForm() if has_newsletter_form: newsletter_form = NewsletterForm(locale, request.POST, prefix='newsletter') if newsletter_form.is_valid(): data = newsletter_form.cleaned_data try: basket.subscribe(data['email'], 'about-mozilla', format=data['fmt'], country=data['country']) newsletter_success = True except basket.BasketException: msg = newsletter_form.error_class( ['We apologize, but an error occurred in our system.' 'Please try again later.'] ) newsletter_form.errors['__all__'] = msg else: newsletter_form = NewsletterForm(locale, prefix='newsletter') return l10n_utils.render(request, template, {'form': form, 'contribute_success': contribute_success, 'newsletter_form': newsletter_form, 'newsletter_success': newsletter_success, 'return_to_form': return_to_form, 'hide_form': hide_contrib_form(request.locale), 'has_moz15': locale in settings.LOCALES_WITH_MOZ15})
def contribute(request, template, return_to_form): has_contribute_form = (request.method == 'POST' and 'contribute-form' in request.POST) has_newsletter_form = (request.method == 'POST' and 'newsletter-form' in request.POST) locale = getattr(request, 'locale', 'en-US') contribute_success = False newsletter_success = False # This is ugly, but we need to handle two forms. I would love if # these forms could post to separate pages and get redirected # back, but we're forced to keep the error/success workflow on the # same page. Please change this. if has_contribute_form: form = ContributeForm(request.POST) contribute_success = email_contribute.handle_form(request, form) if contribute_success: # If form was submitted successfully, return a new, empty # one. form = ContributeForm() else: form = ContributeForm() if has_newsletter_form: newsletter_form = NewsletterForm(locale, request.POST, prefix='newsletter') if newsletter_form.is_valid(): data = newsletter_form.cleaned_data try: basket.subscribe(data['email'], 'about-mozilla', format=data['fmt'], country=data['country']) newsletter_success = True except basket.BasketException: msg = newsletter_form.error_class([ 'We apologize, but an error occurred in our system.' 'Please try again later.' ]) newsletter_form.errors['__all__'] = msg else: newsletter_form = NewsletterForm(locale, prefix='newsletter') return l10n_utils.render( request, template, { 'form': form, 'contribute_success': contribute_success, 'newsletter_form': newsletter_form, 'newsletter_success': newsletter_success, 'return_to_form': return_to_form })
def firefox_partners(request): # If the current locale isn't in our list, return the en-US value locale_os_url = LOCALE_OS_URLS.get(request.locale, LOCALE_OS_URLS['en-US']) return l10n_utils.render(request, 'firefox/partners/index.html', { 'locale_os_url': locale_os_url, 'js_common': JS_COMMON, 'js_mobile': JS_MOBILE, 'js_desktop': JS_DESKTOP, })
def grant_info(request, slug): grant_data = filter(lambda k: k.url == slug, GRANTS) if not grant_data: raise Http404 return l10n_utils.render(request, "grants/info.html", { 'grant': grant_data[0], 'grant_labels': grant_labels })
def _test(self, path, template, locale, accept_lang, status, destination=None): request = RequestFactory().get(path) request.META['HTTP_ACCEPT_LANGUAGE'] = accept_lang request.locale = locale response = render(request, template) if status == 302: self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], destination) self.assertEqual(response['Vary'], 'Accept-Language') else: self.assertEqual(response.status_code, 200)
def firefoxos(request): form = PrivacyContactForm() form_submitted = False if request.method == 'POST': form = PrivacyContactForm(request.POST) form_submitted = submit_form(request, form) return l10n_utils.render(request, 'privacy/ffos_privacy.html', { 'form': form, 'form_submitted': form_submitted })
def marketplace(request): success = False form = NewsletterForm(request.POST or None) if request.method == 'POST': if form.is_valid(): data = form.cleaned_data basket.subscribe(data['email'], 'app-dev', format=data['fmt']) success = True return l10n_utils.render(request, "marketplace/marketplace.html", {'form': form, 'success': success})
def partners(request): success = False form = NewsletterForm(request.POST or None) if request.method == 'POST': if form.is_valid(): data = form.cleaned_data basket.subscribe(data['email'], 'app-dev', format=data['fmt']) success = True return l10n_utils.render(request, "marketplace/partners.html", { 'form': form, 'success': success })
def installer_help(request): installer_lang = request.GET.get('installer_lang', None) installer_channel = request.GET.get('channel', None) context = { 'installer_lang': None, 'installer_channel': None, } if installer_lang and installer_lang in firefox_details.languages: context['installer_lang'] = installer_lang if installer_channel and installer_channel in INSTALLER_CHANNElS: context['installer_channel'] = installer_channel return l10n_utils.render(request, 'firefox/installer-help.html', context)
def contribute_university_ambassadors(request): form = ContributeUniversityAmbassadorForm(request.POST or None) if form.is_valid(): try: form.save() except basket.BasketException: msg = form.error_class( [_('We apologize, but an error occurred in our system. ' 'Please try again later.')]) form.errors['__all__'] = msg else: return redirect('mozorg.contribute_university_ambassadors_thanks') return l10n_utils.render( request, 'mozorg/contribute_university_ambassadors.html', {'form': form} )
def sms_send(request): form = SMSSendForm(request.POST or None) if request.method == 'POST' and form.is_valid(): try: basket.send_sms(form.cleaned_data['number'], 'SMS_Android', form.cleaned_data['optin']) except basket.BasketException: msg = form.error_class([ _('An error occurred in our system. ' 'Please try again later.') ]) form.errors['__all__'] = msg else: return HttpResponseRedirect(reverse('firefox.mobile.sms-thankyou')) return l10n_utils.render(request, 'firefox/mobile/sms-send.html', {'sms_form': form})
def firefox_partners(request): # If the current locale isn't in our list, return the en-US value locale_os_url = LOCALE_OS_URLS.get(request.locale, LOCALE_OS_URLS['en-US']) form = WebToLeadForm() template_vars = { 'locale_os_url': locale_os_url, 'js_common': JS_COMMON, 'js_mobile': JS_MOBILE, 'js_desktop': JS_DESKTOP, 'form': form, } template_vars.update(csrf(request)) return l10n_utils.render(request, 'firefox/partners/index.html', template_vars)
def plugincheck(request, template='mozorg/plugincheck.html'): """ Determine whether the current UA is the latest Firefox, passes the result to the template and renders the specified template. """ user_agent = request.META.get('HTTP_USER_AGENT', '') user_version = "0" ua_regexp = r"Firefox/(%s)" % version_re match = re.search(ua_regexp, user_agent) if match: user_version = match.group(1) data = { 'is_latest': is_current_or_newer(user_version) } return l10n_utils.render(request, template, data)
def sms_send(request): form = SMSSendForm(request.POST or None) if request.method == 'POST' and form.is_valid(): try: basket.send_sms(form.cleaned_data['number'], 'SMS_Android', form.cleaned_data['optin']) except basket.BasketException: msg = form.error_class( [_('An error occurred in our system. ' 'Please try again later.')] ) form.errors['__all__'] = msg else: return HttpResponseRedirect( reverse('firefox.mobile.sms-thankyou')) return l10n_utils.render(request, 'firefox/mobile/sms-send.html', {'sms_form': form})
def grants(request): type_filter = bleach.clean(request.GET.get('type', '')) if type_filter and type_filter not in grant_labels: raise Http404 if type_filter: grants = filter(lambda k: k.type == type_filter, GRANTS) else: grants = GRANTS grants.sort(key=attrgetter('grantee')) return l10n_utils.render(request, "grants/index.html", { 'filter': type_filter, 'grants': grants, 'grant_labels': grant_labels })
def privacy(request): form = PrivacyContactForm() form_submitted = False if request.method == 'POST': form = PrivacyContactForm(request.POST) if form.is_valid(): subject = 'Message sent from Privacy Hub' sender = form.cleaned_data['sender'] to = ['*****@*****.**'] msg = jingo.render_to_string(request, 'privacy/emails/info.txt', form.cleaned_data) headers = {'Reply-To': sender} email = EmailMessage(subject, msg, sender, to, headers=headers) email.send() form_submitted = True return l10n_utils.render(request, 'privacy/index.html', { 'form': form, 'form_submitted': form_submitted })
def whatsnew_redirect(request, fake_version): """ Redirect visitors based on their user-agent. - Up-to-date Firefox users see the whatsnew page. - Other Firefox users go to the update page. - Non Firefox users go to the new page. """ user_agent = request.META.get('HTTP_USER_AGENT', '') if not 'Firefox' in user_agent: url = reverse('firefox.new') return HttpResponsePermanentRedirect( url) # TODO : Where to redirect bug 757206 user_version = "0" ua_regexp = r"Firefox/(%s)" % version_re match = re.search(ua_regexp, user_agent) if match: user_version = match.group(1) current_version = product_details.firefox_versions[ 'LATEST_FIREFOX_VERSION'] if Version(user_version) < Version(current_version): url = reverse('firefox.update') return HttpResponsePermanentRedirect(url) locales_with_video = { 'en-US': 'american', 'en-GB': 'british', 'de': 'german_final', 'it': 'italian_final', 'ja': 'japanese_final', 'es-AR': 'spanish_final', 'es-CL': 'spanish_final', 'es-ES': 'spanish_final', 'es-MX': 'spanish_final', } return l10n_utils.render(request, 'firefox/whatsnew.html', {'locales_with_video': locales_with_video})
def latest_fx_redirect(request, fake_version, template_name): """ Redirect visitors based on their user-agent. - Up-to-date Firefox users see the whatsnew page. - Other Firefox users go to the update page. - Non Firefox users go to the new page. """ user_agent = request.META.get('HTTP_USER_AGENT', '') if not 'Firefox' in user_agent: url = reverse('firefox.new') # TODO : Where to redirect bug 757206 return HttpResponsePermanentRedirect(url) user_version = "0" ua_regexp = r"Firefox/(%s)" % version_re match = re.search(ua_regexp, user_agent) if match: user_version = match.group(1) if not is_current_or_newer(user_version): url = reverse('firefox.update') return HttpResponsePermanentRedirect(url) locales_with_video = { 'en-US': 'american', 'en-GB': 'british', 'de': 'german_final', 'it': 'italian_final', 'ja': 'japanese_final', 'es-AR': 'spanish_final', 'es-CL': 'spanish_final', 'es-ES': 'spanish_final', 'es-MX': 'spanish_final', } return l10n_utils.render(request, template_name, {'locales_with_video': locales_with_video})
def whatsnew_redirect(request, fake_version): """ Redirect visitors based on their user-agent. - Up-to-date Firefox users see the whatsnew page. - Other Firefox users go to the update page. - Non Firefox users go to the new page. """ user_agent = request.META.get('HTTP_USER_AGENT', '') if not 'Firefox' in user_agent: url = reverse('firefox.new') return HttpResponsePermanentRedirect(url) # TODO : Where to redirect bug 757206 user_version = "0" ua_regexp = r"Firefox/(%s)" % version_re match = re.search(ua_regexp, user_agent) if match: user_version = match.group(1) current_version = product_details.firefox_versions['LATEST_FIREFOX_VERSION'] if Version(user_version) < Version(current_version): url = reverse('firefox.update') return HttpResponsePermanentRedirect(url) locales_with_video = { 'en-US': 'american', 'en-GB': 'british', 'de': 'german_final', 'it': 'italian_final', 'ja': 'japanese_final', 'es-AR': 'spanish_final', 'es-CL': 'spanish_final', 'es-ES': 'spanish_final', 'es-MX': 'spanish_final', } return l10n_utils.render(request, 'firefox/whatsnew.html', {'locales_with_video': locales_with_video})
def firstrun_new(request, view, version): # only Firefox users should see the firstrun pages user_agent = request.META.get('HTTP_USER_AGENT', '') if not 'Firefox' in user_agent: url = reverse('firefox.new') return HttpResponsePermanentRedirect(url) # only users on the latest version should see the # new pages (for GA experiment data purity) user_version = "0" ua_regexp = r"Firefox/(%s)" % version_re match = re.search(ua_regexp, user_agent) if match: user_version = match.group(1) if not is_current_or_newer(user_version): url = reverse('firefox.update') return HttpResponsePermanentRedirect(url) # b only has 1-4 version if (view == 'b' and (int(version) < 1 or int(version) > 4)): version = '1' if (view == 'a'): copy = 'a' if (version in '123') else 'b' else: copy = 'a' if (version in '12') else 'b' template_vars = { 'version': version, 'copy': copy, } template = view + '.html' return l10n_utils.render(request, 'firefox/firstrun/' + template, template_vars)
def privacypolicy(request): return l10n_utils.render(request, "persona/privacy-policy.html")
def persona(request): return l10n_utils.render(request, "persona/persona.html")
def developerfaq(request): return l10n_utils.render(request, "persona/developer-faq.html")
def termsofservice(request): return l10n_utils.render(request, "persona/terms-of-service.html")
def platforms(request): file = settings.MEDIA_ROOT + '/devices.csv' return l10n_utils.render(request, 'firefox/mobile/platforms.html', {'devices': load_devices(request, file)})
def hacks_newsletter(request): return l10n_utils.render(request, 'mozorg/newsletter/hacks.mozilla.org.html')
def example(request): return l10n_utils.render(request, 'l10n_example/example.html')
def devices(request): return l10n_utils.render( request, "landing/devices.html", { 'latest_version': product_details.firefox_versions['LATEST_FIREFOX_VERSION'] })
def about(request): return l10n_utils.render(request, "persona/about.html")
format=data['fmt'], country=data['country']) newsletter_success = True except basket.BasketException, e: msg = newsletter_form.error_class([ 'We apologize, but an error occurred in our system.' 'Please try again later.' ]) newsletter_form.errors['__all__'] = msg else: newsletter_form = NewsletterCountryForm(locale, prefix='newsletter') return l10n_utils.render( request, template, { 'form': form, 'success': success, 'newsletter_form': newsletter_form, 'newsletter_success': newsletter_success, 'return_to_form': return_to_form }) def contribute_send(data): ccs = { 'QA': '*****@*****.**', 'Thunderbird': '*****@*****.**', 'Research': '*****@*****.**', 'Design': '*****@*****.**', 'Security': '*****@*****.**', 'Docs': '*****@*****.**', 'Drumbeat': '*****@*****.**', 'Browser Choice': '*****@*****.**',
def js_redirect(redirect_url, request): return l10n_utils.render(request, 'facebookapps/js-redirect.html', {'redirect_url': redirect_url})
def dnt(request): response = l10n_utils.render(request, 'firefox/dnt.html') response['Vary'] = 'DNT' return response
def people(request): return l10n_utils.render(request, "research/people.html")
def page_view(request, tmpl, **kwargs): ctx = kwargs ctx.update(handle_newsletter(request)) return l10n_utils.render(request, tmpl, ctx)
def research(request): return l10n_utils.render(request, "research/research.html")
def _view(request): return l10n_utils.render(request, tmpl, kwargs)
def demo(request): return l10n_utils.render(request, "collusion/demo.html")
def server_error_view(request, template_name='500.html'): """500 error handler that runs context processors.""" return l10n_utils.render(request, template_name)
def collusion(request): return l10n_utils.render(request, "collusion/collusion.html")