Configurazione

urls.py

in urls.py devono essere avviati i vari autodiscover:

dajaxice_autodiscover()
autocomplete_light.autodiscover()
admin.autodiscover()
admin_tools.dashboard.autodiscover()

in aggiunta devono essere aggiunti i pattern per la localizzazione. jmb-start dovrebbe fare questo in automatico.

Monkey Patch

Jumbo relies on some patches to the official django version that can be applied using the function jmb.core.monkey.patch() in settings/__init__.py:

# place these lines after any other code!!!
from jmb.core import monkey
monkey.patch()
jmb.core.monkey.patch(exclude=None)[source]

Apply all patches Jumbo relyes on. Currently management commands, jquery, and timepicker

Parameters:exclude – a list of strings naming the patches that will not be applied. ‘jquery’ patch will only be applied if cms is in INSTALLED_APPS

management commands

Django find_management_module fails at finding modules when namespaces are used.

This version of find_management_module tries a real import when django fails to find the module. The difference is that django only uses:

imp.find_module(...)

that doesn’t implement full module search algorithm. We’re going to place this code in settings/__init__.py, the older way to place it in :file:`urls.py doesn’t work as is not found when calling from command line as urls.py is not called:

from jmb.core import monkey
monkey.patch()

At the moment there’s an open ticket

Django and jQuery

jmb.core.monkey.conf.patch_cms_page_not_to_overwrite_jquery()[source]

MonkeyPatch django-cms not to overwrite jquery.

While django make attention to use djangojQuery and not to overwite standard $(), so different versions can coexist, PageAdmin and PluginEditor overwrite it with django.jQuery. Utilizzata in urls.py cosi:

from jmb.core import monkey

if settings.CMS_ENABLED:
    urlpatterns += patterns('',
        url(r'^', include('cms.urls')),
    )
    monkey.patch_cms_page_not_to_overwrite_jquery()

Errors in forms

When running the development server, print in the console which errors have been raised when saveing an object. This in necessary when not all fields are used in a form and Django just says “Fix errors below”

This will work if you have a variable called RUNNING_DEVSERVER that can be initialized as follows:

import sys
try:
   RUNNING_DEVSERVER = (sys.argv[1] == 'runserver')
except KeyError:
   RUNNING_DEVSERVER = False

timepicker

Datetime and time widgets in Django are pretty poor ones.

Html widgets used by admin are defined in django.contrib.admin.options in a dict named FORMFIELD_FOR_DBFIELD_DEFAULTS.

We overwrite it in jmb.core.admin.options and define a widget that is derived from jQuery.ui‘s default one.

autocomplete_light

A monkey patch vs autocomplete_light (rel 1.4.9) is applied from within our change_form.html so that Dynamic Autocompletion capabilities are added to standard autocomplete_light.

It’s called from extrahead block.

Previous topic

Configurazioni

Next topic

Middlewares

This Page