Simon Meers avatar Simon Meers committed f5e4f1f

Better handling of DEFAULT_CONFIG_KEY

Comments (0)

Files changed (3)

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:

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'

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.