Every Plugin can have his own Preferences. The admin can easy setup the preferences for all plugins with the preferences editor .

Preferences are defined as a django newforms class with initial values .

The newforms class must be inserted in the plugin config file and must be named 'PreferencesForm'.


There are two way to access the preferences:

  • Access the preferences on module level (use in a newform class)
  • Access only in the plugin class

Access in plugin class

This is the easiest way:

from PyLucid.system.BasePlugin import PyLucidBasePlugin
from PyLucid.models import Page, Plugin

class MyPlugin(PyLucidBasePlugin):
    def lucidTagTag(self):
        # Get the preferences from the database:
        preferences = self.get_preferences()
        if preferences == None:
            # preferences not in database -> reinit required

Access in plugin class example:

Access on module level

You should use this access way only if it really needed. You need this e.g. if you use preferences value in a newform class:

from django import newforms as forms
from PyLucid.models import Plugin

# We used preferences values in a newform. We need these values here.
preferences = Plugin.objects.get_preferences(__file__)

class MyPluginForm(forms.Form):
    FooBar = forms.CharField(
        min_length = preferences["min_term_len"],
        max_length = preferences["max_term_len"],

Access on module level example:

low level access

The preferences saved into the plugin model. A low level access looks like this:

from PyLucid.models import Plugin

# Get the system_settings plugin
plugin = Plugin.objects.get(plugin_name = "system_settings")

# Get the preferences as a data dict
preferences = plugin.get_preferences()

# Change one value
preferences["auto_shortcuts"] = False

# Check the new preferences via newforms from the plugin config file
unbound_form = plugin.get_pref_form(debug=True)
form = unbound_form(preferences)
assert form.is_valid(), "Error: %s" % repr(form.errors)

# Save the changes data dict