Commits

Simon Meers committed f5e4f1f

Better handling of DEFAULT_CONFIG_KEY

  • Participants
  • Parent commits c7ddca7
  • Branches multiconfig

Comments (0)

Files changed (3)

File markitup/fields.py

         # _rendered field itself is frozen as well. See introspection
         # rules below.
         self.add_rendered_field = not kwargs.pop('no_rendered_field', False)
-        self.config_key = kwargs.pop('config_key', 'default')
+        self.config_key = kwargs.pop('config_key', settings.DEFAULT_CONFIG_KEY)
         if not self.config_key in settings.MARKITUP_CONFIG:
             raise RuntimeError(
                 u'Invalid MarkupField.config_key (%s); options are: %s' % (
 
 # register MarkupField to use the custom widget in the Admin
 from django.contrib.admin.options import FORMFIELD_FOR_DBFIELD_DEFAULTS
-FORMFIELD_FOR_DBFIELD_DEFAULTS[MarkupField] = {'widget': widgets.AdminMarkItUpWidget}
+FORMFIELD_FOR_DBFIELD_DEFAULTS[MarkupField] = {
+    'widget': widgets.AdminMarkItUpWidget}
+# TODO: set config in admin widget automatically also
 
 # allow South to handle MarkupField smoothly
 try:

File markitup/settings.py

             MARKITUP_CONFIG[name]['filter']
     inject_callables(MARKITUP_CONFIG[name])
 
-if not DEFAULT_CONFIG_KEY in MARKITUP_CONFIG:
-    # inject copy of first configuration as under default key if not present
-    MARKITUP_CONFIG[DEFAULT_CONFIG_KEY] = MARKITUP_CONFIG[configurations[0][0]]
+if not DEFAULT_CONFIG_KEY in MARKITUP_CONFIG: # if default key not present
+    DEFAULT_CONFIG_KEY = configurations[0][0] # set first as default
 
 def get_filter_function(config_key, preview=False, fail_silently=True):
+    if config_key is None:
+        config_key = DEFAULT_CONFIG_KEY
     try:
         function_key = \
             'preview_filter_function' if preview else 'filter_function'

File markitup/views.py

 from django.template import RequestContext
 from . import settings
 
-def apply_filter(request, config_key='default'):
+def apply_filter(request, config_key=None):
     markup = settings.get_filter_function(config_key, preview=True)(
         request.POST.get('data', ''))
     context = RequestContext(request)