def proxy_page(self, request, proxy):
     conn = httplib2.Http()
     url = request.path
     headers = dict((header.lstrip('HTTP_'), value) for (header, value) 
        in request.META.items() if header.startswith('HTTP_'))
     headers["x-internal-from-new"] = "yes"
     headers["X-FORWARDED-FOR"] = get_client_ip(request)
     try:
         if request.method == 'POST':
             headers['Content-type'] = 'application/x-www-form-urlencoded'
             url = proxy.proxy + url
             data = request.POST.urlencode()
             response, content = conn.request(url, request.method, data, headers=headers)
         else:
             url_ending = '%s?%s' % (url, request.GET.urlencode())
             url = proxy.proxy + url_ending
             response, content = conn.request(url, request.method, headers=headers)
     except:
         raise Http404
     if int(response['status']) != 200:
         raise Http404
     if response.get("x-page-title"):
         m = re.search('<head>(.*)</head><body>(.*)</body>', content, flags=re.DOTALL)
         data = {"page_content": m.group(2), 
                 "title": response.get("x-page-title"), 'extra_head_content': m.group(1)}
         return render(request, "base.html", data)
     return HttpResponse(content, status=int(response['status']), content_type=response['content-type'])
Exemple #2
0
def who_uses(request, page=1):
    if request.method == "POST":
        form = choose_form(request, UseExampleForm, UseExampleAnonymousForm, request.POST)
        if form.is_valid():
            use_example = form.save(commit=False)
            use_example.ip = get_client_ip(request)
            if request.user.is_authenticated():
                use_example.poster = request.user
            use_example.save()
            messages.add_message(request, messages.SUCCESS, "Your project has been submitted, it will be made public after being reviewed.")
            return redirect(reverse('pastel-svg-who-uses'))
    else:
        form = choose_form(request, UseExampleForm, UseExampleAnonymousForm)
    use_example = UseExample.objects.filter(validated=True).order_by('-posted')  
    paginator = Paginator(use_example, 20)    
    try:
        use_page = paginator.page(page)
    except (EmptyPage, InvalidPage):
        if page != 1 and use_example:
            return redirect(use_example[0].get_absolute_url(paginator.num_pages))
    data = {
        "title": "Who Uses Pastel SVG Icons",
        "form": form,
        "page": use_page,
        "use_example": use_example[0] if use_example else None,
    }
    return render(request, 'pastelsvg/use_example.html' , data)
Exemple #3
0
 def post(self, request, request_id):
     upvote_request = get_object_or_404(self.request_class, is_spam=False, is_public=True, pk=request_id)
     form = choose_form(request, self.comment_form, self.comment_anonymous_form, request.POST)
     if form.is_valid():
         comment = form.save(commit=False)
         comment.ip = get_client_ip(request)
         if request.user.is_authenticated():
             comment.poster = request.user
         comment.is_spam = check_askmet_spam(request, form)
         comment.request = upvote_request
         comment.save()
         if comment.is_spam:
             return redirect(reverse(self.spam_url)) 
         return redirect(reverse(self.request_url, kwargs={'request_id': request_id})) 
     return self.display(request, upvote_request, form)
Exemple #4
0
 def post(self, request):
     form = choose_form(request, self.request_form, self.request_anonymous_form, request.POST)
     if form.is_valid():
         icon_request = form.save(commit=False)
         icon_request.ip = get_client_ip(request)
         if request.user.is_authenticated():
             icon_request.poster = request.user
         icon_request.is_spam = check_askmet_spam(request, form)
         icon_request.save()
         if icon_request.is_spam:
             return redirect(reverse(self.spam_url)) 
         return redirect(reverse(self.request_url))
     return render(request, self.template , {
         "title": self.title,
         "form": form,
     })