Changeset 1548

Show
Ignore:
Timestamp:
01.05.2008 12:24:21 (2 weeks ago)
Author:
JensDiemer
Message:

put the plugin preferences into the plugin model.
TODO: update detect_page and set system_settings at install.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pylucid/PyLucid/db/preferences.py

    r1544 r1548  
    44    PyLucid preferences API 
    55    ~~~~~~~~~~~~~~~~~~~~~~~ 
     6 
     7    OBSOLETE 
    68 
    79    Last commit info: 
     
    168170 
    169171 
     172def get_pref_dict(plugin_name): 
     173    """ 
     174    returns the data_dict for the given plugin_name. Used the cache. 
     175    If a plugin use preferences in a newforms, it must have access to the 
     176    preferences at module level. 
     177    FIXME: If the admin change the preferences, the values in a plugin module 
     178    level would only updated, if the server instance restarted. 
     179    """ 
     180    if plugin_name in preference_cache: 
     181        return preference_cache[plugin_name] 
     182 
     183    plugin = Plugin.objects.get(plugin_name=plugin_name) 
     184 
     185    p = Preferences() 
     186    p.set_plugin(plugin) 
     187    p.load_from_db() 
     188    return p.data_dict 
     189 
    170190 
    171191#______________________________________________________________________________ 
  • trunk/pylucid/PyLucid/install/install.py

    r1544 r1548  
    3131    DROP_TABLES = ( 
    3232        "PyLucid_pagearchiv", 
     33        "PyLucid_plugin", 
     34        "PyLucid_preference", 
    3335        "PyLucid_preference2", 
    3436    ) 
  • trunk/pylucid/PyLucid/models.py

    r1544 r1548  
    1919 
    2020import os, posixpath, pickle 
     21from pprint import pformat 
    2122 
    2223from django.conf import settings 
     
    2627from django.utils.translation import ugettext as _ 
    2728 
     29from PyLucid.tools.newforms_utils import get_init_dict, setup_help_text 
     30from PyLucid.tools.data_eval import data_eval, DataEvalError 
    2831from PyLucid.tools.shortcuts import getUniqueShortcut 
    2932from PyLucid.tools import crypt 
    3033from PyLucid.system.utils import get_uri_base 
     34from PyLucid.system.plugin_import import get_plugin_module 
     35 
    3136#from PyLucid.db.cache import delete_page_cache 
    3237 
     
    175180        """ 
    176181        try: 
    177             entry = Preference.objects.get(name="index page") 
    178         except Preference.DoesNotExist
     182            preferences = Plugin.objects.get_preferences("system_settings") 
     183        except Plugin.DoesNotExist, e
    179184            # Update old PyLucid installation? 
    180185            return 
    181186 
    182         index_page_id = entry.value 
     187        index_page_id = preferences["index_page"] 
    183188 
    184189        if int(self.id) != int(index_page_id): 
     
    224229        """ 
    225230        try: 
    226             auto_shortcuts = Preference.objects.get(name='auto shortcuts').value 
    227         except Preference.DoesNotExist
     231            preferences = Plugin.objects.get_preferences("system_settings") 
     232        except Plugin.DoesNotExist, e
    228233            # Update old PyLucid installation? 
    229234            auto_shortcuts = True 
    230  
    231         if auto_shortcuts in (1, True, "1"): 
     235        else: 
     236            print ">>>", preferences 
     237            auto_shortcuts = preferences["auto_shortcuts"] 
     238 
     239        if auto_shortcuts: 
    232240            # We should rebuild the shortcut 
    233241            self.shortcut = self.name 
     
    485493 
    486494 
    487 #class Markup(models.Model): 
    488 #    # Obsolete! 
    489 #    pass 
    490  
    491 #class PagesInternal(models.Model): 
    492 #    # Obsolete! 
    493 #    pass 
     495class Preference(models.Model): 
     496    # Obsolete! 
     497    pass 
    494498 
    495499#____________________________________________________________________ 
    496500 
     501preference_cache = {} 
     502 
     503class PluginManager(models.Manager): 
     504    def get_preferences(self, plugin_name): 
     505        """ 
     506        returns the preference data dict, use the cache 
     507        """ 
     508        # Get the name of the plugin, if __file__ used 
     509        plugin_name = os.path.splitext(os.path.basename(plugin_name))[0] 
     510        print "plugin name: '%s'" % plugin_name 
     511 
     512        if plugin_name in preference_cache: 
     513            return preference_cache[plugin_name] 
     514 
     515        plugin = self.get(plugin_name = plugin_name) 
     516        return plugin.get_preferences() 
     517 
     518 
    497519class Plugin(models.Model): 
     520    objects = PluginManager() 
     521 
     522    plugin_name = models.CharField(max_length=90, unique=True) 
     523 
    498524    package_name = models.CharField(max_length=255) 
    499     plugin_name = models.CharField(max_length=90, unique=True) 
    500     version = models.CharField(null=True, blank=True, max_length=45) 
    501525    author = models.CharField(blank=True, max_length=150) 
    502526    url = models.CharField(blank=True, max_length=255) 
    503527    description = models.CharField(blank=True, max_length=255) 
    504     long_description = models.TextField(blank=True) 
     528 
     529    pref_data_string = models.TextField( 
     530        null=True, blank=True, 
     531        help_text="printable representation of the newform data dictionary" 
     532    ) 
    505533    can_deinstall = models.BooleanField(default=True, 
    506534        help_text=( 
     
    512540        help_text="Is this plugin is enabled and useable?" 
    513541    ) 
     542 
     543    def init_pref_form(self, pref_form): 
     544        """ 
     545        Set self.pref_data_string from the given newforms form and his initial 
     546        values. 
     547        """ 
     548        init_dict = get_init_dict(pref_form) 
     549        preference_cache[self.plugin_name] = init_dict 
     550        self.set_pref_data_string(init_dict) 
     551 
     552    def set_pref_data_string(self, data_dict): 
     553        """ 
     554        set the dict via pformat 
     555        """ 
     556        preference_cache[self.plugin_name] = data_dict 
     557        self.pref_data_string = pformat(data_dict) 
     558 
     559    def get_preferences(self): 
     560        """ 
     561        evaluate the pformat string into a dict and return it. 
     562        """ 
     563        data_dict = data_eval(self.pref_data_string) 
     564        preference_cache[self.plugin_name] = data_dict 
     565        return data_dict 
     566 
     567    def get_pref_form(self, debug): 
     568        """ 
     569        Get the 'PreferencesForm' newform class from the plugin modul, insert 
     570        initial information into the help text and return the form. 
     571        """ 
     572        plugin_module = get_plugin_module( 
     573            self.package_name, self.plugin_name, debug 
     574        ) 
     575        form = getattr(plugin_module, "PreferencesForm") 
     576        setup_help_text(form) 
     577        return form 
    514578 
    515579    def save(self): 
     
    535599    class Admin: 
    536600        list_display = ( 
    537             "active", "plugin_name", "description", "version", "can_deinstall" 
     601            "active", "plugin_name", "description", "can_deinstall" 
    538602        ) 
    539603        list_display_links = ("plugin_name",) 
    540604        ordering = ('package_name', 'plugin_name') 
    541         list_filter = ("author",
     605        list_filter = ("author","package_name", "can_deinstall"
    542606 
    543607    def __unicode__(self): 
    544608        txt = u"%s - %s" % (self.package_name, self.plugin_name) 
    545609        return txt.replace(u"_",u" ") 
    546  
    547 #______________________________________________________________________________ 
    548 # Preference 
    549  
    550 class Preference(models.Model): 
    551     """ 
    552     Stores preferences 
    553  
    554     Any pickleable Python object can be stored. 
    555  
    556     Use a small cache, so the pickle.loads() method would only be used on the 
    557     first access. 
    558  
    559     Note: 
    560         - This model has no Admin class. Because it makes no sense to edit 
    561             pickled data strings in the django admin panel ;) 
    562     """ 
    563     plugin = models.ForeignKey("Plugin", help_text="The associated plugin") 
    564     repr_string = models.TextField( 
    565         help_text="printable representation of the newform data dictionary" 
    566     ) 
    567  
    568     lastupdatetime = models.DateTimeField(auto_now=True, editable=False) 
    569     lastupdateby = models.ForeignKey( 
    570         User, null=True, blank=True, editable=False, 
    571     ) 
    572  
    573     #__________________________________________________________________________ 
    574  
    575     def __unicode__(self): 
    576         return u"Preference object for '%s'" % self.plugin 
    577  
    578     class Admin: 
    579         pass 
    580  
    581     class Meta: 
    582         # Use a new table 
    583         db_table = u'PyLucid_preference2' 
    584  
    585  
    586 class PreferenceOld(models.Model): 
    587     """ 
    588     Stores preferences for the PyLucid system and all Plugins. 
    589  
    590     Any pickleable Python object can be stored. 
    591     Use a small cache, so the pickle.loads() method would only be used on the 
    592     first get_value access. The default_value used no cache. 
    593  
    594     Usage: 
    595     --------------------------------------------------------------------------- 
    596     Preference(name = "value name", value = my_python_data_object).save() 
    597  
    598     p = Preference.objects.get(name = "value name") 
    599     print p.value 
    600     --------------------------------------------------------------------------- 
    601  
    602     Note: 
    603         - This model has no Admin class. Because it makes no sense to edit 
    604             pickled data strings in the django admin panel ;) 
    605         - value and default_value are properties 
    606     """ 
    607     __cache = {} # Cache the pickleable Python object 
    608  
    609     #__________________________________________________________________________ 
    610  
    611     def _get_cache_key(self): 
    612         """ returns plugin name + preferences name as a string """ 
    613         return "%s-%s" % (self.plugin, self.name) 
    614  
    615     #__________________________________________________________________________ 
    616     # get and set methods for the value property of the entry 
    617  
    618     def __get_value(self): 
    619         """ 
    620         returns the pickleable Python object back. Use the cache first. 
    621         """ 
    622         cache_key = self._get_cache_key() 
    623  
    624         if cache_key in self.__cache: 
    625             value = self.__cache[cache_key] 
    626         else: 
    627             self._value = str(self._value) 
    628             value = pickle.loads(self._value) 
    629             self.__cache[cache_key] = value 
    630         return value 
    631  
    632     def __set_value(self, value): 
    633         """ 
    634         Save a the pickleable Python object into the database. Remember the 
    635         source object in the cache 
    636         """ 
    637         cache_key = self._get_cache_key() 
    638  
    639         self.__cache[cache_key] = value 
    640         self._value = pickle.dumps(value) 
    641  
    642     #__________________________________________________________________________ 
    643     # get and set methods for the default value property of the entry 
    644  
    645     def __get_default_value(self): 
    646         """ 
    647         returns the default value back 
    648         """ 
    649         self._default_value = str(self._default_value) 
    650         default_value = pickle.loads(self._default_value) 
    651         return default_value 
    652  
    653     def __set_default_value(self, default_value): 
    654         """ 
    655         save a default value 
    656         """ 
    657         self._default_value = pickle.dumps(default_value) 
    658  
    659     #__________________________________________________________________________ 
    660     # The attributes 
    661  
    662     plugin = models.ForeignKey( 
    663         "Plugin", help_text="The associated plugin", 
    664         null=True, blank=True, editable=False 
    665     ) 
    666     name = models.CharField( 
    667         max_length=150, db_index=True, editable=False, 
    668         help_text="Name of the preferences entry", 
    669     ) 
    670     description = models.TextField(editable=False) 
    671  
    672     _value = models.TextField( 
    673         editable=False, help_text="Pickled Python object" 
    674     ) 
    675     value = property(__get_value, __set_value) 
    676  
    677     _default_value = models.TextField( 
    678         editable=False, help_text="Pickled Python object" 
    679     ) 
    680     default_value = property(__get_default_value, __set_default_value) 
    681  
    682     field_type = models.CharField(max_length=150, editable=False, 
    683         help_text="The data type for this entry (For building a html form)." 
    684     ) 
    685  
    686     lastupdatetime = models.DateTimeField(auto_now=True) 
    687     lastupdateby = models.ForeignKey( 
    688         User, null=True, blank=True, editable=False, 
    689     ) 
    690  
    691     #__________________________________________________________________________ 
    692  
    693     def save(self): 
    694         """ 
    695         Save a new or update a preference entry 
    696         """ 
    697         if self.id == None: 
    698             # A new preferences should be saved. 
    699             if self._default_value == "": 
    700                 # No default value given in the __init__ -> Use current value 
    701                 self._default_value = self._value 
    702  
    703         super(Preference, self).save() # Call the "real" save() method 
    704  
    705     def __unicode__(self): 
    706 #        <Preference: Preference object> 
    707         return "%s '%s'" % (self.plugin, self.name) 
    708  
    709     class Meta: 
    710         # Use the old table 
    711         db_table = u'PyLucid_preference' 
    712610 
    713611 
  • trunk/pylucid/PyLucid/plugins_internal/find_and_replace/find_and_replace.py

    r1544 r1548  
    2929 
    3030from django import newforms as forms 
     31from django.utils.safestring import mark_safe 
    3132from django.utils.translation import ugettext as _ 
    32 from django.utils.safestring import mark_safe 
    3333 
     34from PyLucid.system.BasePlugin import PyLucidBasePlugin 
    3435from PyLucid.models import Page, Template, Style 
    35 from PyLucid.system.BasePlugin import PyLucidBasePlugin 
     36#from PyLucid.db.preferences import get_pref_dict 
     37from PyLucid.tools.Diff import diff_lines 
    3638from PyLucid.tools.utils import escape 
    37 from PyLucid.tools.Diff import diff_lines 
    3839 
    39 # How min/max long must a search term be? 
    40 MIN_TERM_LEN = 2 
    41 MAX_TERM_LEN = 150 
    4240 
    4341class PreferencesForm(forms.Form): 
     
    5957) 
    6058 
     59 
     60# We used preferences values in a newform. We need these values here. 
     61try: 
     62    preferences = Plugin.objects.get_preferences(__file__) 
     63except Plugin.DoesNotExist, e: 
     64    # in _install section? 
     65    pass 
     66else: 
     67    min_term_len = preferences["min_term_len"] 
     68    max_term_len = preferences["max_term_len"] 
     69 
     70 
    6171class FindReplaceForm(forms.Form): 
    6272    # TODO: min und max should be saved in the prefereces. 
    6373    find_string = forms.CharField( 
    64         min_length = MIN_TERM_LEN, max_length = MAX_TERM_LEN
     74        min_length = min_term_len, max_length = max_term_len
    6575    ) 
    6676    replace_string = forms.CharField( 
    67         min_length = MIN_TERM_LEN, max_length = MAX_TERM_LEN
     77        min_length = min_term_len, max_length = max_term_len
    6878    ) 
    6979    type = forms.ChoiceField( 
     
    7989 
    8090    def find_and_replace(self): 
    81         self.page_msg("Preferences:", self.preferences) 
    82  
    8391        context = {} 
    8492        if self.request.method == 'POST': 
  • trunk/pylucid/PyLucid/plugins_internal/find_and_replace/find_and_replace_cfg.py

    r1479 r1548  
    2626    }, 
    2727} 
     28 
     29preferences = ( 
     30    { 
     31        "name": "term len limit", 
     32        "description": "How min/max long must a search term be?", 
     33        "value": { 
     34            "min term len": 1, 
     35            "max term len": 255, 
     36        } 
     37    }, 
     38) 
  • trunk/pylucid/PyLucid/plugins_internal/preferences/preferences.py

    r1544 r1548  
    2626from django.utils.translation import ugettext as _ 
    2727 
    28 from PyLucid.db.preferences import get_all_prefs, Preferences 
    2928from PyLucid.system.BasePlugin import PyLucidBasePlugin 
    30 from PyLucid.tools.data_eval import data_eval, DataEvalError 
     29from PyLucid.models import Plugin 
    3130 
    3231 
     
    4443 
    4544        items = [] 
    46         for pref in get_all_prefs(): 
    47             edit_link = self.URLs.methodLink("edit", args=pref.id) 
     45        plugins = Plugin.objects.all() 
     46        for plugin in plugins: 
     47            if plugin.pref_data_string == None: 
     48                continue 
     49 
     50            edit_link = self.URLs.methodLink("edit", args=plugin.id) 
    4851 
    4952            items.append({ 
    50                 "plugin_name": self._vebose_plugin_name(pref), 
    51                 "plugin_description": pref.plugin.description, 
     53                "plugin_name": unicode(plugin), 
     54                "plugin_description": plugin.description, 
    5255                "edit_link": edit_link, 
    5356            }) 
     
    6265        try: 
    6366            url_args = url_args.strip("/") 
    64             pref_id = int(url_args) 
     67            plugin_id = int(url_args) 
    6568        except Exception, e: 
    6669            self.page_msg.red("url error:", e) 
    6770            return 
    6871 
    69         p = Preferences() 
    70         p.init_via_id(pref_id) 
    71         data_dict = p.data_dict 
    72  
    73         p.load_form(self.request) 
    74         unbound_form = p.form 
     72        plugin = Plugin.objects.get(id = plugin_id) 
     73        unbound_form = plugin.get_pref_form(self.request.debug) 
    7574 
    7675        if self.request.method == 'POST': 
     
    7877            if form.is_valid(): 
    7978                new_data_dict = form.cleaned_data 
    80                 p.update_and_save(new_data_dict) 
     79 
     80                plugin.set_pref_data_string(new_data_dict) 
     81                plugin.save() 
    8182                self.page_msg("New preferences saved.") 
    8283                return self.select() # Display the menu 
    8384        else: 
     85            data_dict = plugin.get_preferences() 
    8486            form = unbound_form(data_dict) 
    8587 
    8688        context = { 
    87             "plugin_name": self._vebose_plugin_name(p), 
     89            "plugin_name": unicode(plugin), 
    8890            "form": form, 
    8991            "url_abort": self.URLs.methodLink("select"), 
  • trunk/pylucid/PyLucid/plugins_internal/search/search.py

    r1544 r1548  
    2727 
    2828from django import newforms as forms 
     29from django.utils.safestring import mark_safe 
    2930from django.utils.translation import ugettext as _ 
    30 from django.utils.safestring import mark_safe 
    31  
    32 from PyLucid.models import Page 
     31 
    3332from PyLucid.system.BasePlugin import PyLucidBasePlugin 
    3433from PyLucid.tools.utils import escape 
    35  
    36  
    37 # How min/max long must a search term be? 
    38 MIN_TERM_LEN = 3 
    39 MAX_TERM_LEN = 50 
    40  
    41 # Number of the paged for the result page: 
    42 MAX_RESULTS = 20 
    43  
    44 # The length of the text-hit-cutouts: 
    45 TEXT_CUTOUT_LEN = 50 
    46  
    47 # Max. cutout lines for every search term: 
    48 MAX_CUTOUTS_LINES = 5 
     34from PyLucid.models import Page, Plugin 
    4935 
    5036 
     
    7157    ) 
    7258 
    73  
    74 class SearchForm(forms.Form): 
    75     # TODO: min und max should be saved in the prefereces. 
    76     search_string = forms.CharField( 
    77         min_length = MIN_TERM_LEN, max_length = MAX_TERM_LEN 
    78     ) 
     59# We used preferences values in a newform. We need these values here. 
     60try: 
     61    preferences = Plugin.objects.get_preferences(__file__) 
     62except Plugin.DoesNotExist, e: 
     63    # in _install section? 
     64    pass 
     65else: 
     66    class SearchForm(forms.Form): 
     67        search_string = forms.CharField( 
     68            min_length = preferences["min_term_len"], 
     69            max_length = preferences["max_term_len"], 
     70        ) 
    7971 
    8072 
     
    8577        Insert a empty search form into the page. 
    8678        """ 
    87         self.page_msg("Preferences:", self.preferences) 
    8879        search_form = SearchForm() 
    8980        context = { 
     
    138129        search_strings = [] 
    139130        for term in raw_search_strings: 
    140             if len(term)<MIN_TERM_LEN
     131            if len(term)<preferences["min_term_len"]
    141132                self.page_msg("Ignore '%s' (too small)" % cgi.escape(term)) 
    142133            else: 
     
    178169 
    179170        # Use only the first pages: 
    180         results = results[:MAX_RESULTS
     171        results = results[:preferences["max_results"]
    181172 
    182173        # Build a dict, for the template 
     
    191182        the lines. 
    192183        """ 
     184        text_cutout_len = preferences["text_cutout_len"] 
     185        max_cutout_lines = preferences["max_cutout_lines"] 
     186 
    193187        for result in results: 
    194188            result["cutouts"] = [] 
     
    197191            for term in search_strings: 
    198192                start = 0 
    199                 for _ in xrange(MAX_CUTOUTS_LINES): 
     193                for _ in xrange(max_cutout_lines): 
    200194                    try: 
    201195                        index = content.index(term, start) 
     
    206200                    start = index+1 
    207201 
    208                     if index<TEXT_CUTOUT_LEN
    209                         txt = content[:TEXT_CUTOUT_LEN
     202                    if index<text_cutout_len
     203                        txt = content[:text_cutout_len
    210204                    else: 
    211                         txt = content[index-TEXT_CUTOUT_LEN:index+TEXT_CUTOUT_LEN] 
     205                        start = index-text_cutout_len 
     206                        end = index+text_cutout_len 
     207                        txt = content[start:end] 
    212208 
    213209                    txt = escape(txt) 
  • trunk/pylucid/PyLucid/plugins_internal/system_settings/system_settings.py

    r1544 r1548  
    6060        Insert a empty search form into the page. 
    6161        """ 
    62         self.page_msg("Preferences:", self.preferences) 
     62        self.page_msg("Preferences:", preferences) 
  • trunk/pylucid/PyLucid/system/BasePlugin.py

    r1544 r1548  
    5959 
    6060        self.current_page = self.context["PAGE"] 
    61         self.preferences = self.context.preferences 
    6261 
    6362    def build_menu(self): 
  • trunk/pylucid/PyLucid/system/detect_page.py

    r1507 r1548  
    1717""" 
    1818 
    19 from PyLucid.models import Page, Preference 
     19from PyLucid.models import Page 
    2020from PyLucid.system.exceptions import AccessDenied, LowLevelError 
    2121 
  • trunk/pylucid/PyLucid/system/plugin_import.py

    r1544 r1548  
    2121 
    2222 
    23 def _import(request, from_name, object_name): 
     23def _import(from_name, object_name, debug): 
    2424    """ 
    2525    from 'from_name' import 'object_name' 
     
    2828        return __import__(from_name, {}, {}, [object_name]) 
    2929    except (ImportError, SyntaxError), e: 
    30         if request.user.is_superuser or request.debug: 
     30        if debug: 
    3131            raise 
    3232        raise ImportError, "Can't import %s from %s: %s" % ( 
     
    3434        ) 
    3535 
    36 def get_plugin_module(request, package_name, plugin_name): 
    37     plugin_module = _import(request, 
     36def get_plugin_module(package_name, plugin_name, debug): 
     37    plugin_module = _import( 
    3838        from_name = ".".join([package_name, plugin_name, plugin_name]), 
    39         object_name = plugin_name 
     39        object_name = plugin_name, 
     40        debug = debug, 
    4041    ) 
    4142    return plugin_module 
    4243 
    43 #def get_plugin_class(request, package_name, plugin_name): 
    44 #    """ 
    45 #    import the plugin/plugin and returns the class object 
    46 #    """ 
    47 #    plugin_module = get_plugin_module(request, package_name, plugin_name) 
    48 #    plugin_class = getattr(plugin_module, plugin_name) 
    49 #    return plugin_class 
     44#    debug = request.user.is_superuser or request.debug 
     45 
    5046 
    5147def debug_plugin_config(page_msg, plugin_config): 
     
    6561    """ 
    6662    config_name = "%s_cfg" % plugin_name 
     63    debug = request.user.is_superuser or request.debug 
    6764 
    6865    def get_plugin(object_name): 
     
    7067        if extra_verbose: 
    7168            print "from %s import %s" % (from_name, object_name) 
    72         return _import(request, from_name, object_name
     69        return _import(from_name, object_name, debug
    7370 
    7471    config_plugin = get_plugin(config_name) 
  • trunk/pylucid/PyLucid/system/plugin_manager.py

    r1544 r1548  
    3434from django.http import HttpResponse, Http404 
    3535 
    36 from PyLucid.db.preferences import Preferences, preference_cache, \ 
    37                                                         PreferenceDoesntExist 
     36#from PyLucid.db.preferences import Preferences, preference_cache, PreferenceDoesntExist 
    3837from PyLucid.system.plugin_import import get_plugin_module, get_plugin_config 
    3938from PyLucid.system.exceptions import * 
     
    112111    URLs.current_plugin = plugin_name 
    113112 
    114     plugin_module = get_plugin_module(request, plugin.package_name, plugin_name) 
    115  
    116     if plugin_name in preference_cache: 
    117         context.preferences = preference_cache[plugin_name] 
    118     else: 
    119         if hasattr(plugin_module, "PreferencesForm"): 
    120             # Get the preferences dict data from the database 
    121             try: 
    122                 p = Preferences() 
    123                 p.set_plugin(plugin) 
    124                 p.load_from_db() 
    125                 context.preferences = p.data_dict 
    126             except PreferenceDoesntExist, e: 
    127                 error("Can't get preferences: %s" % e) 
    128                 return 
    129         else: 
    130             # plugin has no preferences 
    131             context.preferences = None 
     113    debug = request.user.is_superuser or request.debug 
     114    plugin_module = get_plugin_module(plugin.package_name, plugin_name, debug) 
    132115 
    133116    plugin_class = getattr(plugin_module, plugin_name) 
     117#    print plugin_class, type(plugin_class) 
    134118    class_instance = plugin_class(context, local_response) 
    135119    unbound_method = getattr(class_instance, method_name) 
     
    216200 
    217201 
    218 def _install_plugin(package_name, plugin_name, plugin_config, active, 
     202def _install_plugin(request, package_name, plugin_name, plugin_config, active, 
    219203                                                                extra_verbose): 
    220204    """ 
     
    223207    if extra_verbose: 
    224208        print "Install %s.%s..." % (package_name, plugin_name), 
     209 
    225210    plugin = Plugin.objects.create( 
    226211        package_name = package_name, 
    227212        plugin_name = plugin_name, 
    228         version = plugin_config.__version__, 
    229213        author = plugin_config.__author__, 
    230214        url = plugin_config.__url__, 
    231215        description = plugin_config.__description__, 
    232         long_description = plugin_config.__long_description__, 
    233216        can_deinstall = getattr(plugin_config, "__can_deinstall__", True), 
    234217        active = active, 
    235218    ) 
     219    debug = request.user.is_superuser or request.debug 
     220    plugin_module = get_plugin_module(package_name, plugin_name, debug) 
     221    pref_form = getattr(plugin_module, "PreferencesForm", None) 
     222    if pref_form: 
     223        # plugin module has a preferences newform class 
     224        plugin.init_pref_form(pref_form) 
     225 
     226 
    236227    plugin.save() 
    237228    if extra_verbose: 
     
    239230    return plugin 
    240231 
    241  
    242 def _insert_preferences(request, plugin, package_name, plugin_name): 
    243     """ 
    244     insertet the initial values from the newforms preferences class into the 
    245     database. 
    246     """ 
    247     plugin_module = get_plugin_module(request, package_name, plugin_name) 
    248  
    249     pref_form = getattr(plugin_module, "PreferencesForm", None) 
    250     if pref_form == None: 
    251         # Has no preferences newform class 
    252         return 
    253  
    254     p = Preferences() 
    255     p.set_plugin(plugin) 
    256     p.create_initial(pref_form) 
    257232 
    258233 
     
    280255 
    281256    plugin = _install_plugin( 
    282         package_name, plugin_name, plugin_config, active, extra_verbose 
     257        request, package_name, plugin_name, 
     258        plugin_config, active, extra_verbose 
    283259    ) 
    284     _insert_preferences(request, plugin, package_name, plugin_name) 
    285260 
    286261 
     
    314289            ) 
    315290        except Exception, e: 
    316             print "Error:", e 
     291            print "Error:" 
     292            import traceback 
     293            traceback.print_exc() 
    317294            continue 
    318295