def test_complete(self): """ Test with complete set of data. """ request = mock.MagicMock() request.build_absolute_uri.return_value = ( 'http://test/' '?utm_campaign=campaign_name' '&utm_medium=campain_medium' '&utm_source=campain_source') request.path = '/test/' ga_data = genericised_pageview(request, title='My title') self.assertDictEqual( ga_data, { 'page': '/test/', 'location': 'http://test/', 'title': 'My title', 'campaignName': 'campaign_name', 'campaignMedium': 'campain_medium', 'campaignSource': 'campain_source', }, )
def password_change_with_code(request, template_name=None, cancel_url=None, post_change_redirect=None, extra_context=None): cancel_url = resolve_url(cancel_url or '/') if post_change_redirect is None: post_change_redirect = reverse('password_change_done') else: post_change_redirect = resolve_url(post_change_redirect) if request.method == 'POST': form = PasswordChangeWithCodeForm(request=request, data=request.POST) if form.is_valid(): return HttpResponseRedirect(post_change_redirect) else: reset_code = request.GET.get(RESET_CODE_PARAM) form = PasswordChangeWithCodeForm(reset_code=reset_code, request=request) context = { 'form': form, 'cancel_url': cancel_url, 'breadcrumbs': make_breadcrumbs(request, _('Change password')), 'google_analytics_pageview': genericised_pageview(request, _('Set a new password')), } context.update(extra_context or {}) return TemplateResponse(request, template_name, context)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) form = context['form'] search_field = form['search'] new_credit_list = list(form.credit_choices) old_credit_list = [] for index, credit in enumerate(new_credit_list): if credit['resolution'] == 'credited': new_credit_list, old_credit_list = new_credit_list[:index], new_credit_list[index:] break object_count = form.pagination['count'] current_page = form.pagination['page'] page_count = form.pagination['page_count'] if form.is_valid() and form.cleaned_data.get('search'): self.title = _('Search for “%(query)s”') % {'query': form.cleaned_data['search']} context.update({ 'search_field': search_field, 'new_credit_list': new_credit_list, 'old_credit_list': old_credit_list, 'credits_returned': form.is_valid() and (new_credit_list or old_credit_list), 'form_has_errors': not form.is_valid(), 'object_count': object_count, 'current_page': current_page, 'page_count': page_count, 'credit_owner_name': self.request.user.get_full_name(), 'google_analytics_pageview': genericised_pageview( self.request, SearchView.title ) }) return context
def login_view(request): return auth_views.login(request, template_name='mtp_auth/login.html', extra_context={ 'start_page_url': settings.START_PAGE_URL, 'google_analytics_pageview': genericised_pageview(request, _('Sign in')), })
def get_context_data(self, **kwargs): context_data = super().get_context_data(**kwargs) return { **context_data, 'breadcrumbs': self._get_breadcrumbs(**kwargs), 'google_analytics_pageview': genericised_pageview(self.request, self.get_generic_title()), 'search_form_submitted_input_name': SEARCH_FORM_SUBMITTED_INPUT_NAME, }
def test_minimal(self): """ Test with minimal set of data. """ request = mock.MagicMock() request.build_absolute_uri.return_value = '//test/' request.path = '/test/' ga_data = genericised_pageview(request) self.assertDictEqual( ga_data, { 'page': '/test/', 'location': 'https://test/', 'title': None, 'campaignName': None, 'campaignMedium': None, 'campaignSource': None, }, )
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['google_analytics_pageview'] = genericised_pageview( self.request, self.title) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['google_analytics_pageview'] = genericised_pageview( self.request, self.title ) return context
def analytics(request): return { 'analytics_policy': AnalyticsPolicy(request), 'default_google_analytics_pageview': genericised_pageview(request), }