diff options
Diffstat (limited to 'tagging')
-rw-r--r-- | tagging/models.py | 15 | ||||
-rw-r--r-- | tagging/tests/settings.py | 22 | ||||
-rw-r--r-- | tagging/utils.py | 2 |
3 files changed, 20 insertions, 19 deletions
diff --git a/tagging/models.py b/tagging/models.py index 860cf81..e13b077 100644 --- a/tagging/models.py +++ b/tagging/models.py @@ -17,6 +17,8 @@ from tagging import settings from tagging.utils import calculate_cloud, get_tag_list, get_queryset_and_model, parse_tag_input from tagging.utils import LOGARITHMIC +import collections + qn = connection.ops.quote_name ############ @@ -166,9 +168,16 @@ class TagManager(models.Manager): # Django 1.2+ compiler = queryset.query.get_compiler(using='default') extra_joins = ' '.join(compiler.get_from_clause()[0][1:]) - where, params = queryset.query.where.as_sql( - compiler.quote_name_unless_alias, compiler.connection - ) + if isinstance(compiler, collections.Callable): + # Django 1.7+ + where, params = queryset.query.where.as_sql( + compiler, compiler.connection + ) + else: + # Django 1.2-1.6 + where, params = queryset.query.where.as_sql( + compiler.quote_name_unless_alias, compiler.connection + ) else: # Django pre-1.2 extra_joins = ' '.join(queryset.query.get_from_clause()[0][1:]) diff --git a/tagging/tests/settings.py b/tagging/tests/settings.py index 74eb909..1985118 100644 --- a/tagging/tests/settings.py +++ b/tagging/tests/settings.py @@ -3,22 +3,14 @@ DIRNAME = os.path.dirname(__file__) DEFAULT_CHARSET = 'utf-8' -test_engine = os.environ.get("TAGGING_TEST_ENGINE", "sqlite3") - -DATABASE_ENGINE = test_engine -DATABASE_NAME = os.environ.get("TAGGING_DATABASE_NAME", "tagging_test") -DATABASE_USER = os.environ.get("TAGGING_DATABASE_USER", "") -DATABASE_PASSWORD = os.environ.get("TAGGING_DATABASE_PASSWORD", "") -DATABASE_HOST = os.environ.get("TAGGING_DATABASE_HOST", "localhost") - -if test_engine == "sqlite": - DATABASE_NAME = os.path.join(DIRNAME, 'tagging_test.db') - DATABASE_HOST = "" -elif test_engine == "mysql": - DATABASE_PORT = os.environ.get("TAGGING_DATABASE_PORT", 3306) -elif test_engine == "postgresql_psycopg2": - DATABASE_PORT = os.environ.get("TAGGING_DATABASE_PORT", 5432) +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(DIRNAME, 'tagging_test.db'), + } +} +SECRET_KEY = 'liewoo1jie7TahTao3ci7xayee8gieg9ukee' INSTALLED_APPS = ( 'django.contrib.contenttypes', diff --git a/tagging/utils.py b/tagging/utils.py index e89bab0..759e8d8 100644 --- a/tagging/utils.py +++ b/tagging/utils.py @@ -232,7 +232,7 @@ def _calculate_tag_weight(weight, max_weight, distribution): if distribution == LINEAR or max_weight == 1: return weight elif distribution == LOGARITHMIC: - return math.log(weight) * max_weight / math.log(max_weight) + return min((max_weight, math.log(weight) * max_weight / math.log(max_weight))) raise ValueError(_('Invalid distribution algorithm specified: %s.') % distribution) def calculate_cloud(tags, steps=4, distribution=LOGARITHMIC): |