def home(request): if request.user.is_authenticated(): return redirect('base.dashboard') else: return render(request, 'base/home.html', { 'affiliate_count': User.objects.count(), 'link_count': Link.objects.count(), 'click_count': Link.objects.total_link_clicks(), })
def post(self, request, *args, **kwargs): # Only allow editing of the user if you are logged in as the # current user. profile = self.get_object() if request.user != profile.user: # TODO: Add some sort've error message here. return redirect(profile) else: return super(UserProfileView, self).post(request, *args, **kwargs)
def home(request): if request.user.is_authenticated(): return redirect('base.dashboard') else: return render( request, 'base/home.html', { 'affiliate_count': User.objects.count(), 'link_count': Link.objects.count(), 'click_count': Link.objects.total_link_clicks(), })
def home(request): if request.user.is_authenticated(): return redirect('base.dashboard') else: aggregate_clicks = Link.objects.aggregate(a=Sum('aggregate_link_clicks'))['a'] or 0 datapoint_clicks = DataPoint.objects.aggregate(d=Sum('link_clicks'))['d'] or 0 return render(request, 'base/home.html', { 'affiliate_count': User.objects.count(), 'link_count': Link.objects.count(), 'click_count': aggregate_clicks + datapoint_clicks })
def load_app(request): """ Create or authenticate the Facebook user and direct them to the correct area of the app upon their entry. """ signed_request = request.POST.get('signed_request', None) if signed_request is None: # App wasn't loaded within a canvas, redirect to the home page. return redirect('base.home') decoded_request = decode_signed_request(signed_request, settings.FACEBOOK_APP_SECRET) if decoded_request is None: return redirect('base.home') # If user is using Safari, we need to apply the cookie workaround. useragent = request.META.get('HTTP_USER_AGENT', '') using_safari = 'Safari' in useragent and not 'Chrome' in useragent workaround_applied = SAFARI_WORKAROUND_KEY in request.COOKIES if using_safari and not workaround_applied: return fb_redirect(request, absolutify(reverse('facebook.safari_workaround')), top_window=True) user, created = (FacebookUser.objects. get_or_create_user_from_decoded_request(decoded_request)) if user is None: # User has yet to authorize the app, redirect to the pre-auth promo. return fb_redirect(request, absolutify(reverse('facebook.pre_auth_promo'))) # Attach country data to the user object. This can only be retrieved from # the decoded request, so we add it here and login saves it. user.country = decoded_request['user'].get('country', user.country) # User has been authed, let's log them in. login(request, user) return fb_redirect(request, absolutify(reverse('facebook.banner_list')))
def home(request): if request.user.is_authenticated(): return redirect('base.dashboard') else: aggregate_clicks = Link.objects.aggregate( a=Sum('aggregate_link_clicks'))['a'] or 0 datapoint_clicks = DataPoint.objects.aggregate( d=Sum('link_clicks'))['d'] or 0 return render( request, 'base/home.html', { 'affiliate_count': User.objects.count(), 'link_count': Link.objects.count(), 'click_count': aggregate_clicks + datapoint_clicks })
def inner(request, *args, **kwargs): if is_logged_in(request): return func(request, *args, **kwargs) else: return redirect('base.home')
def login_required(request): messages.warning(request, _('You must be logged in to view that page.')) return redirect('base.home')
def test_permanent(self): with self.activate('en-US'): response = redirect('mock_view', permanent=True) eq_(response.status_code, 301) eq_(response['Location'], '/en-US/mock_view')
def test_basic(self): with self.activate('en-US'): response = redirect('mock_view') eq_(response.status_code, 302) eq_(response['Location'], '/en-US/mock_view')