Exemple #1
0
def subscribe_hit(request, id):
    """Used by our ajax call handleSubscriptionLink.  It will get a security
    error if we redirect it to a URL outside the channelguide, so we don't do
    that
    """
    ids = [id] + [int(k) for k in request.GET]
    for id in ids:
        channel = get_object_or_404(Channel, pk=id)
        referer = request.META.get('HTTP_REFERER', '')
        ignore_for_recommendations = False
        if referer.startswith(settings.BASE_URL_FULL):
            referer = util.chop_prefix(referer, settings.BASE_URL_FULL)
            if not referer.startswith("/"):
                referer = '/' + referer # make sure it starts with a slash
            try:
                resolved = resolve(referer)
            except Resolver404:
                pass
            else:
                if resolved is not None:
                    func, args, kwargs = resolved
                    if func == channel_view and args[0] != id:
                        ignore_for_recommendations = True
                    elif func == firsttime_index:
                        ignore_for_recommendations = True
        ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
        if ip == '127.0.0.1':
            ip = request.META.get('HTTP_X_FORWARDED_FOR', '0.0.0.0')
        Subscription.objects.add(
            channel, ip,
            ignore_for_recommendations=ignore_for_recommendations)

    return HttpResponse("Hit successfull")
Exemple #2
0
 def website_link(self):
     url_label = self.website_url
     url_label = util.chop_prefix(url_label, 'http://')
     url_label = util.chop_prefix(url_label, 'https://')
     url_label = util.chop_prefix(url_label, 'www.')
     return util.make_link(self.website_url, url_label)
Exemple #3
0
 def website_link(self):
     url_label = self.website_url
     url_label = util.chop_prefix(url_label, 'http://')
     url_label = util.chop_prefix(url_label, 'https://')
     url_label = util.chop_prefix(url_label, 'www.')
     return util.make_link(self.website_url, url_label)