Exemplo n.º 1
0
    def get(self, request):
        template = 'login.html'
        redirect = request.GET.get('next', reverse('home'))
        context_dict = {'redirect_to': redirect}

        if request.user.is_authenticated:
            if hasattr(request.session, 'branch_id'):
                return django_redirect(redirect)
            else:
                return django_redirect(reverse('branch') + '?next=' + redirect)

        return render(request, template, context_dict)
def redirect(request, *args, **kwargs):
    current_stash = get_stash(request)

    if len(current_stash):
        # Extract the target redirect
        target_redirect = current_stash.pop()

        # Update the stash
        set_stash(request, current_stash)

        return django_redirect(target_redirect)
    else:
        return django_redirect(*args, **kwargs)
Exemplo n.º 3
0
def follow_banner_link(request, banner_instance_id):
    """
    Add a click to a banner instance and redirect the user to the Firefox
    download page.
    """
    try:
        banner_instance = FacebookBannerInstance.objects.select_related("banner").get(id=banner_instance_id)
    except FacebookBannerInstance.DoesNotExist:
        return django_redirect(settings.FACEBOOK_DOWNLOAD_URL)

    # Do not add a click if the request is from the Facebook bot.
    if not is_facebook_bot(request):
        add_click.delay(banner_instance_id)

    return django_redirect(banner_instance.banner.link)
Exemplo n.º 4
0
    def response(self, include_messages=False):
        """ Renders the response using JSON, if appropriate.
        """
        if self.request.is_ajax():
            return self.json_response(include_messages)

        else:
            # Try and redirect somewhere useful
            redirect_to = self.redirect_data
            if redirect_to is None:
                if 'HTTP_REFERER' in self.request.META:
                    redirect_to = self.request.META['HTTP_REFERER']
                elif DEFAULT_REDIRECT:
                    redirect_to = DEFAULT_REDIRECT
            if ADJAX_DEBUG:
                debug_template = 'adjax/debug.html'
                context = RequestContext(self.request, {
                    'store': self,
                    'redirect_to': redirect_to
                })
                return django_render_to_response(debug_template,
                                                 context_instance=context)
            if redirect_to:
                return django_redirect(redirect_to)
            return HttpResponse()
Exemplo n.º 5
0
def post_invite(request):
    """
    Redirect user back to the app after they've invited friends to download
    Firefox.
    """
    messages.success(request, _("You have successfully sent a message to one " "of your friends!"))
    return django_redirect(settings.FACEBOOK_APP_URL)
Exemplo n.º 6
0
def post_banner_share(request):
    """
    Redirect user back to the app after they've posted a banner to their feed.
    """
    if "post_id" in request.GET:
        messages.success(request, _("You have successfully posted a banner to " "your wall !"))
    return django_redirect(settings.FACEBOOK_APP_URL)
Exemplo n.º 7
0
def new_category(request):
    form_name = "New Category"
    print("HERE")
    user_profile = UserProfile.objects.get(user__pk=request.user.pk)
    if (not request.user.is_authenticated or user_profile.points < pointreq['new_category']):
        return django_redirect(index)

    if (request.method == 'POST'):
        new_category_form = CategoryForm(request.POST)
        if (new_category_form.is_valid()):
            category = Category(name=new_category_form.cleaned_data['name'], created_by=user_profile)
            category.save()
            template = loader.get_template('linked/success.html')
            # Create context
            context = {'for': 'New Category'}
            # Render the template
            return HttpResponse(template.render(context, request))

    # Load category form
    new_category_form = CategoryForm()
    # Load template
    template = loader.get_template('linked/form.html')
    # Create context
    context = {
        'form': new_category_form,
        'form_name': form_name,
        'auth': request.user.is_authenticated
    }

    return HttpResponse(template.render(context, request))
Exemplo n.º 8
0
    def get(self, request):
        redirect = request.GET.get('next', reverse('home'))
        branches = utils.get_branches(request.user)

        if len(branches) == 1:
            request.session['branch_id'] = branches[0].id
            request.session['branch_name'] = str(branches[0])
            return django_redirect(redirect)
        elif len(branches) < 1:
            msg = 'This account does not belong to any branch. Kindly contact the site administrator.'
            messages.error(request, msg)
            return django_redirect(reverse('logout'))

        context_dict = {'redirect_to': redirect, 'branches': branches}

        return render(request, self.template_name, context_dict)
Exemplo n.º 9
0
def follow_banner_link(request, banner_instance_id):
    """
    Add a click to a banner instance and redirect the user to the Firefox
    download page.
    """
    try:
        banner_instance = (
            FacebookBannerInstance.objects.select_related('banner').get(
                id=banner_instance_id))
    except FacebookBannerInstance.DoesNotExist:
        return django_redirect(settings.FACEBOOK_DOWNLOAD_URL)

    # Do not add a click if the request is from the Facebook bot.
    if not is_facebook_bot(request):
        add_click.delay(banner_instance_id)

    return django_redirect(banner_instance.banner.link)
Exemplo n.º 10
0
def post_invite(request):
    """
    Redirect user back to the app after they've invited friends to download
    Firefox.
    """
    if request.GET.get('success', None):
        messages.success(request, _('You have successfully sent a message to one of your '
                                    'friends!'))
    return django_redirect(settings.FACEBOOK_APP_URL)
Exemplo n.º 11
0
    def post(self, request):
        branch_id = request.POST.get('branch_id')
        instance = models.Branch.objects.get(pk=branch_id)

        request.session['branch_id'] = instance.id
        request.session['branch_name'] = str(instance)

        redirect = request.GET.get('next', reverse('home'))
        return django_redirect(redirect)
Exemplo n.º 12
0
def post_invite(request):
    """
    Redirect user back to the app after they've invited friends to download
    Firefox.
    """
    messages.success(
        request,
        _('You have successfully sent a message to one '
          'of your friends!'))
    return django_redirect(settings.FACEBOOK_APP_URL)
Exemplo n.º 13
0
def post_banner_share(request):
    """
    Redirect user back to the app after they've posted a banner to their feed.
    """
    if 'post_id' in request.GET:
        messages.success(
            request,
            _('You have successfully posted a banner to '
              'your wall !'))
    return django_redirect(settings.FACEBOOK_APP_URL)
Exemplo n.º 14
0
    def post(self, request):
        template = 'login.html'
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=password)

        if user is not None:
            if user.is_active:

                branches = utils.get_branches(user)
                if len(branches) > 1:
                    login(request, user)
                    request.session['branch_id'] = branches[0].id
                    request.session['branch_name'] = str(branches[0])
                    redirect = request.GET.get(
                        'next', reverse('home')) or reverse('home')
                    return django_redirect(
                        reverse('branch') + '?next=' + redirect)
                elif len(branches) < 1:
                    msg = 'You are authenticated as {0} but this account does not belong to any branch. Kindly contact the site administrator.'.format(
                        user.username)
                    messages.error(request, msg)
                    return render(request, template)
                else:
                    login(request, user)
                    request.session['branch_id'] = branches[0].id
                    request.session['branch_name'] = str(branches[0])
                    redirect = request.GET.get(
                        'next', reverse('home')) or reverse('home')
                    return django_redirect(redirect)

            else:
                msg = 'User is inactive.'
                messages.error(request, msg)
                return render(request, template_name)
        else:
            msg = 'Invalid username and/or password'
            messages.error(request, msg)
            return render(request, template)
Exemplo n.º 15
0
def safari_workaround(request):
    """
    Safari does not allow third-party requests to set cookies, but we need to
    set session and other cookies when users view the app through the Facebook
    iframe.

    To work around this, we send Safari users to this view, which sends a test
    cookie to the user. Because Safari allows third-party requests to set
    cookies if a cookie was sent with that request, the test cookie will allow
    us to set the session cookie normally.
    """
    response = django_redirect(settings.FACEBOOK_APP_URL)
    response.set_cookie(SAFARI_WORKAROUND_KEY, '1')
    return response
Exemplo n.º 16
0
def safari_workaround(request):
    """
    Safari does not allow third-party requests to set cookies, but we need to
    set session and other cookies when users view the app through the Facebook
    iframe.

    To work around this, we send Safari users to this view, which sends a test
    cookie to the user. Because Safari allows third-party requests to set
    cookies if a cookie was sent with that request, the test cookie will allow
    us to set the session cookie normally.
    """
    response = django_redirect(settings.FACEBOOK_APP_URL)
    response.set_cookie(SAFARI_WORKAROUND_KEY, '1')
    return response
Exemplo n.º 17
0
def redirect(request, forum, slug):
    if not request.acl.forums.can_see(forum):
        return error404(request)
    try:
        forum = Forum.objects.get(pk=forum, type='redirect')
        if not request.acl.forums.can_browse(forum):
            return error403(request, _("You don't have permission to follow this redirect."))
        redirects_tracker = request.session.get('redirects', [])
        if forum.pk not in redirects_tracker:
            redirects_tracker.append(forum.pk)
            request.session['redirects'] = redirects_tracker
            forum.redirects += 1
            forum.save(force_update=True)
        return django_redirect(forum.redirect)
    except Forum.DoesNotExist:
        return error404(request)
Exemplo n.º 18
0
def redirect(request, forum, slug):
    if not request.acl.forums.can_see(forum):
        return error404(request)
    try:
        forum = Forum.objects.get(pk=forum, type='redirect')
        if not request.acl.forums.can_browse(forum):
            return error403(
                request,
                _("You don't have permission to follow this redirect."))
        redirects_tracker = request.session.get('redirects', [])
        if forum.pk not in redirects_tracker:
            redirects_tracker.append(forum.pk)
            request.session['redirects'] = redirects_tracker
            forum.redirects += 1
            forum.save(force_update=True)
        return django_redirect(forum.redirect)
    except Forum.DoesNotExist:
        return error404(request)
Exemplo n.º 19
0
def detail(request, link_id):
    # try:
    #     link = Link.objects.get(pk=link_id)
    # except Link.DoesNotExist:
    #     raise Http404("Link does not exist!")

    link = get_object_or_404(Link, pk=link_id)
    if request.method == 'POST':  # Form Data Process If Any
        # Get the form data
        new_review_form = ReviewForm(request.POST)
        # If form is valid
        if new_review_form.is_valid():
            userpk = request.user.pk
            # Get fields
            rate = new_review_form.cleaned_data['rate']
            review = new_review_form.cleaned_data['review']
            by = UserProfile.objects.get(pk=userpk)
            new_review = Review(link=link, by=by, review=review, rate=rate)
            new_review.save()
            # Add user point
            # UserProfile.objects.filter(pk=userPK).update(points=F('points')+ 20)
            by.addPoints(rewards['review'])
            return django_redirect(index)

    # return HttpResponse("YOu are looking at link %s" % link.name)
    # Load template
    template = loader.get_template('linked/link.html')
    # Create context
    context = {
        'link': link,
        'auth': request.user.is_authenticated,
        'form' : ReviewForm

    }

    reviews = Review.objects.filter(link=link.pk)
    avg = reviews.aggregate(Avg('rate'))

    context['reviews'] = reviews
    context['avg'] = avg['rate__avg']
    context['review_count'] = reviews.count()
    # return HttpResponse("type: %s" % len(links))
    # Render the template
    return HttpResponse(template.render(context, request))
Exemplo n.º 20
0
Arquivo: base.py Projeto: APSL/Adjax
 def response(self, include_messages=False):
     """ Renders the response using JSON, if appropriate.
     """
     if self.request.is_ajax():
         return self.json_response(include_messages)
 
     else:
         # Try and redirect somewhere useful
         redirect_to = self.redirect_data
         if redirect_to is None:
             if 'HTTP_REFERER' in self.request.META:
                 redirect_to = self.request.META['HTTP_REFERER']
             elif DEFAULT_REDIRECT:
                 redirect_to = DEFAULT_REDIRECT
         if ADJAX_DEBUG:
             debug_template = 'adjax/debug.html'
             context = RequestContext(self.request, 
                         {'store': self, 'redirect_to': redirect_to})
             return django_render_to_response(debug_template, context_instance=context)
         if redirect_to:
             return django_redirect(redirect_to)
         return HttpResponse()
Exemplo n.º 21
0
 def redirect(self, url_name):
     """
     Hook for customizing the redirect function when used as application
     content
     """
     return django_redirect(url_name)
Exemplo n.º 22
0
def redirect(to, *args, **kwargs):
    response = django_redirect(to, *args, **kwargs)
    session = kwargs.pop('session', None)
    if session:
        session.close()
    return response
Exemplo n.º 23
0
def redirect_to_login(request):
   from django.shortcuts import redirect as django_redirect
   return django_redirect('/app/accounts/signin')
Exemplo n.º 24
0
def redirect(url, *args, params=None, **kwargs):
    query_params = ""
    if params:
        query_params += '?' + parse.urlencode(params)
    return django_redirect(url + query_params, *args, **kwargs)
Exemplo n.º 25
0
def redirect(request, hash_shortened_url):
    shortened_url = ShortenedURL.objects.get(shortened_url=hash_shortened_url)

    original_url = shortened_url.url

    return django_redirect(original_url)
Exemplo n.º 26
0
 def get(self, request):
     logout(request)
     return django_redirect(reverse('login'))
Exemplo n.º 27
0
 def redirect(self, url_name):
     """
     Hook for customizing the redirect function when used as application
     content
     """
     return django_redirect(url_name)
Exemplo n.º 28
0
def activate_link(request, activation_code):
    link = FacebookAccountLink.objects.activate_link(activation_code)
    if link:
        return django_redirect(settings.FACEBOOK_APP_URL)
    else:
        raise http.Http404
Exemplo n.º 29
0
def activate_link(request, activation_code):
    link = FacebookAccountLink.objects.activate_link(activation_code)
    if link:
        return django_redirect(settings.FACEBOOK_APP_URL)
    else:
        raise http.Http404
Exemplo n.º 30
0
def redirect(request, url=None):
    return django_redirect(url or request.GET.get("next") or request.POST.get("next") or request.META['HTTP_REFERER'])
Exemplo n.º 31
0
 def render_to_response(self, context, **response_kwargs):
     cart = get_or_create_cart(self.request)
     items = cart.get_items()
     if not cart or not items:
         return django_redirect('/')
     return super().render_to_response(context, **response_kwargs)
Exemplo n.º 32
0
 def redirect_to_absolute_url(self, absolute_url: str) -> None:
     """this function redirects to an absolute url"""
     return django_redirect(absolute_url)
Exemplo n.º 33
0
def redirect(to, *args, **kwargs):
    response = django_redirect(to, *args, **kwargs)
    session = kwargs.pop('session', None)
    if session:
        session.close()
    return response
Exemplo n.º 34
0
def redirect_to_name(name):
    return django_redirect(reverse(name))
Exemplo n.º 35
0
def redirect_to_name(name):
    return django_redirect(reverse(name))
Exemplo n.º 36
0
def logout(request):
    # Log user out and destroy session
    auth_logout(request)
    # redirect to index
    return django_redirect(index)