Permalink
Browse files

Use AppConf for app-level configuration

  • Loading branch information...
1 parent e5cceec commit e92127fef4ac7bdb4e1460b2cb532ae898656ee9 @paltman paltman committed Jan 23, 2013
Showing with 25 additions and 21 deletions.
  1. +6 −0 agora/callbacks.py
  2. +13 −10 agora/{utils.py → conf.py}
  3. +3 −6 agora/models.py
  4. +0 −5 agora/settings.py
  5. +3 −0 setup.py
View
6 agora/callbacks.py
@@ -0,0 +1,6 @@
+from django.utils.html import urlize, linebreaks, escape
+from django.utils.safestring import mark_safe
+
+
+def default_text(text):
+ return mark_safe(linebreaks(urlize(escape(text))))
View
23 agora/utils.py → agora/conf.py
@@ -1,17 +1,15 @@
+from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
-from django.utils.html import urlize, linebreaks, escape
-from django.utils.safestring import mark_safe
-try:
- from django.utils.importlib import import_module
-except ImportError:
- from importlib import import_module
+from django.utils import importlib
+
+from appconf import AppConf
def load_path_attr(path):
i = path.rfind(".")
- module, attr = path[:i], path[i+1:]
+ module, attr = path[:i], path[i + 1:]
try:
- mod = import_module(module)
+ mod = importlib.import_module(module)
except ImportError, e:
raise ImproperlyConfigured("Error importing %s: '%s'" % (module, e))
try:
@@ -21,5 +19,10 @@ def load_path_attr(path):
return attr
-def default_text(text):
- return mark_safe(linebreaks(urlize(escape(text))))
+class AgoraAppConf(AppConf):
+
+ PARSER = "agora.callbacks.default_text"
+ EDIT_TIMEOUT = dict(minutes=3)
+
+ def configure_parser(self, value):
+ return load_path_attr(value)
View
9 agora/models.py
@@ -1,5 +1,4 @@
import datetime
-import functools
import json
from django.core.urlresolvers import reverse
@@ -9,9 +8,8 @@
from django.contrib.auth.models import User
+from agora.conf import settings
from agora.managers import ForumThreadManager
-from agora.settings import PARSER, EDIT_TIMEOUT
-from agora.utils import load_path_attr
# this is the glue to the activity events framework, provided as a no-op here
@@ -244,14 +242,13 @@ class Meta:
abstract = True
def save(self, **kwargs):
- render_func = functools.partial(load_path_attr(PARSER[0], **PARSER[1]))
- self.content_html = conditional_escape(render_func(self.content))
+ self.content_html = conditional_escape(settings.AGORA_PARSER(self.content))
super(ForumPost, self).save(**kwargs)
# allow editing for short period after posting
def editable(self, user):
if user == self.author:
- if timezone.now() < self.created + datetime.timedelta(**EDIT_TIMEOUT):
+ if timezone.now() < self.created + datetime.timedelta(**settings.AGORA_EDIT_TIMEOUT):
return True
return False
View
5 agora/settings.py
@@ -1,5 +0,0 @@
-from django.conf import settings
-
-
-PARSER = getattr(settings, "AGORA_PARSER", ["agora.utils.default_text", {}])
-EDIT_TIMEOUT = getattr(settings, "AGORA_EDIT_TIMEOUT", dict(minutes=3))
View
3 setup.py
@@ -14,6 +14,9 @@
"agora",
"agora.templatetags"
],
+ install_requires = [
+ "django-appconf==0.5"
+ ],
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Web Environment",

0 comments on commit e92127f

Please sign in to comment.