Skip to content

Commit

Permalink
Adds settings.TERMS_DEBUG.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Sep 12, 2012
1 parent c12c9be commit a3277af
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
13 changes: 10 additions & 3 deletions README.rst
Expand Up @@ -147,6 +147,13 @@ Settings
Common settings
---------------

TERMS_DEBUG
...........

:Default: ``DEBUG``
:Definition: If set to ``True``, allows django-terms to raise minor exceptions
(see `Exceptions`_).

TERMS_ADDITIONAL_IGNORED_APPS
.............................
:Default: ``()``
Expand Down Expand Up @@ -187,7 +194,7 @@ TERMS_REPLACE_FIRST_ONLY
........................

:Default: ``True``
:Definition: If set to True, adds a link only on the first occurrence
:Definition: If set to ``True``, adds a link only on the first occurrence
of each term
:Used by: `Middleware`_, `Template filter`_

Expand Down Expand Up @@ -291,7 +298,7 @@ Resolver404
...........

:Raised by: `Middleware`_ only.
:Raised in: ``DEBUG`` mode. Otherwise the page is ignored by django-terms.
:Raised in: `TERMS_DEBUG`_ mode. Otherwise the page is ignored by django-terms.
:Reason: This happens when django-terms is unable to resolve the current
``request.path`` to determine whether the application
of the current page is in `TERMS_IGNORED_APPS`_.
Expand All @@ -302,7 +309,7 @@ HTMLValidationWarning
.....................

:Raised by: `Middleware`_ and `Template filter`_.
:Raised in: ``DEBUG`` mode. Otherwise we try to make terms replacements
:Raised in: `TERMS_DEBUG`_ mode. Otherwise we try to make terms replacements
work anyway.
:Reason: This happens when django-terms finds a problem in the architecture
of the current HTML page.
Expand Down
7 changes: 3 additions & 4 deletions terms/html.py
Expand Up @@ -3,8 +3,7 @@
from HTMLParser import HTMLParser
from .models import Term
from .settings import TERMS_IGNORED_TAGS, TERMS_IGNORED_CLASSES, \
TERMS_IGNORED_IDS, TERMS_REPLACE_FIRST_ONLY
from django.conf import settings
TERMS_IGNORED_IDS, TERMS_REPLACE_FIRST_ONLY, TERMS_DEBUG
from .exceptions import HTMLValidationWarning


Expand Down Expand Up @@ -102,7 +101,7 @@ def handle_endtag(self, tag):
# Adds the tag to HTML only if it has a start tag.
NeutralHTMLReconstructor.handle_endtag(self, tag)
except IndexError:
if settings.DEBUG:
if TERMS_DEBUG:
lines = self.rawdata.split('\n')
line = self.getpos()[0]
lines = '\n'.join(lines[line - 2:line])
Expand All @@ -111,7 +110,7 @@ def handle_endtag(self, tag):
% (tag, lines))
return None
if tag != opened_tag:
if settings.DEBUG:
if TERMS_DEBUG:
lines = self.rawdata.split('\n')
start_line, end_line = pos[0], self.getpos()[0]
lines = '\n'.join(lines[start_line - 1:end_line])
Expand Down
5 changes: 2 additions & 3 deletions terms/middleware.py
Expand Up @@ -2,8 +2,7 @@

from .html import TermsHTMLReconstructor
from django.core.urlresolvers import resolve, Resolver404
from .settings import TERMS_IGNORED_APPS
from django.conf import settings
from .settings import TERMS_IGNORED_APPS, TERMS_DEBUG


class TermsMiddleware:
Expand All @@ -16,7 +15,7 @@ def process_response(self, request, response):
app_name = resolve(url).app_name
app_ignored = app_name in TERMS_IGNORED_APPS
except Resolver404:
if settings.DEBUG:
if TERMS_DEBUG:
raise Resolver404("could not find whether the application of "
"'%s' is in TERMS_IGNORED_APPS" % url)
app_ignored = True
Expand Down
2 changes: 2 additions & 0 deletions terms/settings.py
Expand Up @@ -3,6 +3,8 @@
from django.conf import settings


TERMS_DEBUG = getattr(settings, 'TERMS_DEBUG', settings.DEBUG)

TERMS_IGNORED_APPS = getattr(settings, 'TERMS_IGNORED_APPS',
[
'admin',
Expand Down

0 comments on commit a3277af

Please sign in to comment.