Exemplo n.º 1
0
	def process_request(self,request):

		baned_ips = cache.get(CACHE_KEY_BANED_IP)
		if baned_ips is None:
			baned_ips = BannedIP.objects.all()
			cache.set(CACHE_KEY_BANED_IP,baned_ips,CACHE_TIME)

		if get_ip(request) in baned_ips:
			raise Http404

		super(ClickMiddleware,self).process_request(request)
Exemplo n.º 2
0
    def process_request(self, request):

        baned_ips = cache.get(CACHE_KEY_BANED_IP)
        if baned_ips is None:
            baned_ips = BannedIP.objects.all()
            cache.set(CACHE_KEY_BANED_IP, baned_ips, CACHE_TIME)

        if get_ip(request) in baned_ips:
            raise Http404

        super(ClickMiddleware, self).process_request(request)
Exemplo n.º 3
0
    def countclick(self, request, response):

        boots = unicode(request.META.get('HTTP_USER_AGENT', '')[:255],
                        errors='ignore')
        browser = get_browser(boots)
        os = get_os(boots)
        ip = get_ip(request)
        attrs = {
            'url': request.path,
            'browser': browser.family,
            'browser_version': browser.version_string,
            'user_agent': boots,
            'ip': ip,
            'operating_system': os.family,
            'operating_system_version': os.version_string,
        }

        content_type = response.get('X-Object-Type', False)
        object_id = response.get('X-Object-Id', False)

        if content_type and object_id:

            key_cache = CACHE_KEY_CONTENTTYPE + content_type
            cache_contenttype = cache.get(key_cache)

            if cache_contenttype is None:
                from django.contrib.contenttypes.models import ContentType
                app_label, model = content_type.split('.')
                cache_contenttype = ContentType.objects.get(
                    app_label=app_label, model=model)
                cache.set(key_cache, cache_contenttype, CACHE_TIME_CONTENTTYPE)

            attrs.update({
                'object_id': object_id,
                'content_type': cache_contenttype
            })

        click = Click(**attrs)

        try:
            click.save()
            return click
        except DatabaseError:
            return False
Exemplo n.º 4
0
	def countclick(self,request,response):

		boots = unicode(request.META.get('HTTP_USER_AGENT', '')[:255], errors='ignore')
		browser = get_browser(boots)
		os = get_os(boots)
		ip = get_ip(request)
		attrs = {
			'url':request.path,
			'browser':browser.family,
			'browser_version':browser.version_string,
			'user_agent':boots,
			'ip': ip,
			'operating_system':os.family,
			'operating_system_version':os.version_string,
		}

		content_type=response.get('X-Object-Type',False)
		object_id=response.get('X-Object-Id', False)

		if content_type and object_id:

			key_cache= CACHE_KEY_CONTENTTYPE + content_type
			cache_contenttype = cache.get(key_cache)

			if cache_contenttype is None:
				from django.contrib.contenttypes.models import ContentType
				app_label, model = content_type.split('.')
				cache_contenttype=ContentType.objects.get(app_label=app_label,model=model)
				cache.set(key_cache,cache_contenttype,CACHE_TIME_CONTENTTYPE)

			attrs.update({
				'object_id':object_id,
				'content_type':cache_contenttype
			})

		click=Click(**attrs)
		
		try:
			click.save()
			return click
		except DatabaseError:
			return False