diff --git a/requirements.txt b/requirements.txt index 280cab0..29b966f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ etiquetando==0.1 html2text django-taggit python-memcached +django-hitcounter gunicorn gevent diff --git a/src/colab/custom_settings.py b/src/colab/custom_settings.py index b2eb8c5..7f017b3 100644 --- a/src/colab/custom_settings.py +++ b/src/colab/custom_settings.py @@ -107,6 +107,7 @@ INSTALLED_APPS = INSTALLED_APPS + ( 'django_browserid', 'conversejs', 'haystack', + 'hitcounter', # Own apps 'super_archives', @@ -116,7 +117,6 @@ INSTALLED_APPS = INSTALLED_APPS + ( 'accounts', 'proxy', 'search', - 'hitcount', # Feedzilla and deps 'feedzilla', diff --git a/src/hitcount/__init__.py b/src/hitcount/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/src/hitcount/__init__.py +++ /dev/null diff --git a/src/hitcount/admin.py b/src/hitcount/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/src/hitcount/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/src/hitcount/migrations/0001_initial.py b/src/hitcount/migrations/0001_initial.py deleted file mode 100644 index 1236631..0000000 --- a/src/hitcount/migrations/0001_initial.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Adding model 'Hit' - db.create_table(u'hitcount_hit', ( - (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('created', self.gf('django.db.models.fields.DateField')(auto_now_add=True, db_index=True, blank=True)), - ('updated', self.gf('django.db.models.fields.DateField')(auto_now=True, db_index=True, blank=True)), - ('hits', self.gf('django.db.models.fields.PositiveIntegerField')(default=0)), - ('content_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contenttypes.ContentType'])), - ('object_pk', self.gf('django.db.models.fields.CharField')(max_length=256)), - )) - db.send_create_signal(u'hitcount', ['Hit']) - - # Adding unique constraint on 'Hit', fields ['content_type', 'object_pk'] - db.create_unique(u'hitcount_hit', ['content_type_id', 'object_pk']) - - - def backwards(self, orm): - # Removing unique constraint on 'Hit', fields ['content_type', 'object_pk'] - db.delete_unique(u'hitcount_hit', ['content_type_id', 'object_pk']) - - # Deleting model 'Hit' - db.delete_table(u'hitcount_hit') - - - models = { - u'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - }, - u'hitcount.hit': { - 'Meta': {'unique_together': "(('content_type', 'object_pk'),)", 'object_name': 'Hit'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), - 'created': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), - 'hits': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'object_pk': ('django.db.models.fields.CharField', [], {'max_length': '256'}), - 'updated': ('django.db.models.fields.DateField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}) - } - } - - complete_apps = ['hitcount'] \ No newline at end of file diff --git a/src/hitcount/migrations/__init__.py b/src/hitcount/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/src/hitcount/migrations/__init__.py +++ /dev/null diff --git a/src/hitcount/models.py b/src/hitcount/models.py deleted file mode 100644 index afeeae4..0000000 --- a/src/hitcount/models.py +++ /dev/null @@ -1,55 +0,0 @@ - -from django.db import models -from django.core.cache import cache -from django.contrib.contenttypes import generic -from django.contrib.contenttypes.models import ContentType - - -class Hit(models.Model): - created = models.DateField(auto_now_add=True, db_index=True) - updated = models.DateField(auto_now=True, db_index=True) - hits = models.PositiveIntegerField(default=0) - content_type = models.ForeignKey(ContentType) - object_pk = models.CharField(max_length=256) - - class Meta: - unique_together = ('content_type', 'object_pk') - - -class HitCountModelMixin(object): - - @property - def hits(self): - content_type = ContentType.objects.get_for_model(self.__class__, - for_concrete_model=False) - try: - hit = Hit.objects.get(content_type=content_type, - object_pk=self.pk) - except Hit.DoesNotExist: - return 0 - - return hit.hits - - def hit(self, request=None): - content_type = ContentType.objects.get_for_model(self.__class__) - - # Here we cache the user's IP to ensure that the same - # IP won't hit the same page again for while - if request: - ip_addr = request.META.get('REMOTE_ADDR') - cache_key = u'page_hits-{}-{}-{}'.format(ip_addr, - content_type, self.pk) - duplicate = cache.get(cache_key) - if duplicate: - return - cache.set(cache_key, True) - - # Everything ok, so just increment the page count - hit_pk = Hit.objects.get_or_create(content_type=content_type, - object_pk=self.pk)[0].pk - - # Using this way instead of hits += 1 forces django to - # call the UPDATE directly in the database avoiding - # cuncurrency problems - Hit.objects.filter(pk=hit_pk).update(hits=models.F("hits") + 1) - diff --git a/src/hitcount/tests.py b/src/hitcount/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/src/hitcount/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/src/hitcount/views.py b/src/hitcount/views.py deleted file mode 100644 index afba530..0000000 --- a/src/hitcount/views.py +++ /dev/null @@ -1,16 +0,0 @@ -from django.shortcuts import render - -class HitCountViewMixin(object): - def get_object(self, *args, **kwargs): - try: - super(HitCountViewMixin, self).get_object(*args, **kwargs) - except AttributeError: - raise NotImplementedError - - def dispatch(self, request, *args, **kwargs): - response = super(HitCountViewMixin, self).dispatch(request, - *args, **kwargs) - if 200 <= response.status_code < 300: - obj = self.get_object() - if obj: obj.hit(request) - return response diff --git a/src/proxy/models.py b/src/proxy/models.py index fd1470f..f8fff17 100644 --- a/src/proxy/models.py +++ b/src/proxy/models.py @@ -7,10 +7,10 @@ from django.conf import settings from django.db import models from accounts.models import User -from hitcount.models import HitCountModelMixin +from hitcounter.models import HitCounterModelMixin -class Attachment(models.Model, HitCountModelMixin): +class Attachment(models.Model, HitCounterModelMixin): url = models.TextField(primary_key=True) attach_id = models.TextField() used_by = models.TextField() @@ -44,7 +44,7 @@ class Attachment(models.Model, HitCountModelMixin): return None -class Revision(models.Model, HitCountModelMixin): +class Revision(models.Model, HitCounterModelMixin): key = models.TextField(blank=True, primary_key=True) rev = models.TextField(blank=True) author = models.TextField(blank=True) @@ -65,7 +65,7 @@ class Revision(models.Model, HitCountModelMixin): except User.DoesNotExist: return None -class Ticket(models.Model, HitCountModelMixin): +class Ticket(models.Model, HitCounterModelMixin): id = models.IntegerField(primary_key=True) summary = models.TextField(blank=True) description = models.TextField(blank=True) @@ -96,7 +96,7 @@ class Ticket(models.Model, HitCountModelMixin): return None -class Wiki(models.Model, HitCountModelMixin): +class Wiki(models.Model, HitCounterModelMixin): name = models.TextField(primary_key=True) wiki_text = models.TextField(blank=True) author = models.TextField(blank=True) diff --git a/src/proxy/views.py b/src/proxy/views.py index 0f8a8c0..372c604 100644 --- a/src/proxy/views.py +++ b/src/proxy/views.py @@ -5,13 +5,13 @@ from django.conf import settings from revproxy.views import ProxyView from .models import Wiki, Ticket, Revision -from hitcount.views import HitCountViewMixin +from hitcounter.views import HitCounterViewMixin CWD = os.path.abspath(os.path.dirname(__file__)) DIAZO_RULES_DIR = os.path.join(CWD, 'diazo') -class TracProxyView(HitCountViewMixin, ProxyView): +class TracProxyView(HitCounterViewMixin, ProxyView): base_url = settings.COLAB_TRAC_URL add_remote_user = settings.REVPROXY_ADD_REMOTE_USER diazo_theme_template = 'proxy/trac.html' diff --git a/src/super_archives/models.py b/src/super_archives/models.py index 053e1fd..cde5835 100644 --- a/src/super_archives/models.py +++ b/src/super_archives/models.py @@ -14,7 +14,7 @@ from django.utils.translation import ugettext_lazy as _ from html2text import html2text from haystack.query import SearchQuerySet from taggit.managers import TaggableManager -from hitcount.models import HitCountModelMixin +from hitcounter.models import HitCounterModelMixin from .utils import blocks from .utils.etiquetador import etiquetador @@ -108,7 +108,7 @@ class Keyword(models.Model): return self.keyword -class Thread(models.Model, HitCountModelMixin): +class Thread(models.Model, HitCounterModelMixin): subject_token = models.CharField(max_length=512) mailinglist = models.ForeignKey(MailingList, -- libgit2 0.21.2