Changeset 1544
- Timestamp:
- 04/30/08 13:35:20 (14 months ago)
- Location:
- trunk
- Files:
-
- 8 added
- 14 modified
-
dev_scripts/local_tests/prefereces_test.py (added)
-
pylucid/media/PyLucid/internal_page/admin_menu/sub_menu.html (modified) (1 diff)
-
pylucid/media/PyLucid/internal_page/preferences/edit_form.html (modified) (1 diff)
-
pylucid/media/PyLucid/internal_page/preferences/select.html (modified) (1 diff)
-
pylucid/media/PyLucid/internal_page/preferences/select.js (added)
-
pylucid/PyLucid/db/preferences.py (added)
-
pylucid/PyLucid/install/install.py (modified) (1 diff)
-
pylucid/PyLucid/models.py (modified) (3 diffs)
-
pylucid/PyLucid/plugins_internal/find_and_replace/find_and_replace.py (modified) (2 diffs)
-
pylucid/PyLucid/plugins_internal/plugin_admin/plugin_admin.py (modified) (1 diff)
-
pylucid/PyLucid/plugins_internal/preferences/preferences.py (modified) (6 diffs, 2 props)
-
pylucid/PyLucid/plugins_internal/preferences/preferences_cfg.py (modified) (1 prop)
-
pylucid/PyLucid/plugins_internal/preferences/__init__.py (modified) (1 prop)
-
pylucid/PyLucid/plugins_internal/search/search.py (modified) (2 diffs)
-
pylucid/PyLucid/plugins_internal/system_settings (added)
-
pylucid/PyLucid/plugins_internal/system_settings/system_settings.py (added)
-
pylucid/PyLucid/plugins_internal/system_settings/system_settings_cfg.py (added)
-
pylucid/PyLucid/plugins_internal/system_settings/__init__.py (added)
-
pylucid/PyLucid/system/BasePlugin.py (modified) (2 diffs)
-
pylucid/PyLucid/system/page_msg.py (modified) (1 diff)
-
pylucid/PyLucid/system/plugin_import.py (added)
-
pylucid/PyLucid/system/plugin_manager.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/media/PyLucid/internal_page/admin_menu/sub_menu.html
r1539 r1544 55 55 </li> 56 56 <li> 57 <a href="{{ commandURLprefix }}/preferences/select/">{% trans ' Low level preferneces editor' %}</a>57 <a href="{{ commandURLprefix }}/preferences/select/">{% trans 'Preferences editor' %}</a> 58 58 </li> 59 59 <!-- -
trunk/pylucid/media/PyLucid/internal_page/preferences/edit_form.html
r1540 r1544 1 <fieldset><legend>{{ plugin_name }} - {{ pref_name }}</legend> 2 <p>{{ description }}</p> 1 <fieldset><legend>{{ plugin_name }}</legend> 3 2 <form method="post" action="."> 4 {{ form.as_p }} 3 <ul id="input_fields"> 4 {% for field in form %} 5 <li title="{{ field.help_text }}" class="{{ field.html_name }}"> 6 <label for="{{ field.auto_id }}">{{ field.label }} :</label> 7 {{ field }} 8 <span class="field_help_text">{{ field.help_text }}</span> 9 {% if field.errors %}<li class="field_errors">{{ field.errors }}</li>{% endif %} 10 </li> 11 {% endfor %} 12 </ul> 5 13 <input type="submit" name="save" value="{% trans 'save' %}" /> 6 <input type="submit" name="validate" value="{% trans 'validate' %}" />7 14 <input onclick="self.location.href='{{ url_abort }}'" name="abort" value="{% trans 'abort' %}" type="reset" /> 8 15 </form> 9 <p><strong>Note:</strong><br />10 {% blocktrans %}11 Validate checks only, if the input is a valid Python expression string.<br />12 It not examined if the data are logically correct.13 {% endblocktrans %}14 </p>15 16 </fieldset> -
trunk/pylucid/media/PyLucid/internal_page/preferences/select.html
r1540 r1544 1 {% for plugin, data in preferences.items %} 2 <fieldset><legend>{{ plugin }}</legend> 1 <fieldset><legend>select for edit</legend> 3 2 <ul> 4 {% for pref in data %} 5 <li><a href="{{ pref.link }}">{{ pref.name }}</a><br /> 6 {{ pref.description }}</li> 7 {% endfor %} 3 {% for item in preferences %} 4 <li><a href="{{ item.edit_link }}">{{ item.plugin_name }}</a> - {{ item.plugin_description }}</li> 5 {% endfor %} 8 6 </ul> 7 <small> 8 ({% trans 'Low level edit in the' %} <a href="{{ admin_link }}" onclick="OpenInWindow(this); return false">{% trans 'django admin panel' %}</a>.) 9 </small> 9 10 </fieldset> 10 {% endfor %} -
trunk/pylucid/PyLucid/install/install.py
r1466 r1544 31 31 DROP_TABLES = ( 32 32 "PyLucid_pagearchiv", 33 "PyLucid_preference2", 33 34 ) 34 35 -
trunk/pylucid/PyLucid/models.py
r1538 r1544 542 542 543 543 def __unicode__(self): 544 return self.plugin_name.replace("_"," ") 545 544 txt = u"%s - %s" % (self.package_name, self.plugin_name) 545 return txt.replace(u"_",u" ") 546 547 #______________________________________________________________________________ 548 # Preference 546 549 547 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): 548 587 """ 549 588 Stores preferences for the PyLucid system and all Plugins. … … 648 687 lastupdateby = models.ForeignKey( 649 688 User, null=True, blank=True, editable=False, 650 related_name="preferences_lastupdateby",651 689 ) 652 690 … … 669 707 return "%s '%s'" % (self.plugin, self.name) 670 708 709 class Meta: 710 # Use the old table 711 db_table = u'PyLucid_preference' 712 713 714 #______________________________________________________________________________ 671 715 672 716 -
trunk/pylucid/PyLucid/plugins_internal/find_and_replace/find_and_replace.py
r1476 r1544 41 41 MAX_TERM_LEN = 150 42 42 43 class PreferencesForm(forms.Form): 44 min_term_len = forms.IntegerField( 45 help_text="Min length of a search term", 46 initial=2, min_value=1 47 ) 48 max_term_len = forms.IntegerField( 49 help_text="Max length of a search term", 50 initial=150, min_value=1, max_value=500 51 ) 52 43 53 44 54 # for FindReplaceForm ChoiceField … … 69 79 70 80 def find_and_replace(self): 81 self.page_msg("Preferences:", self.preferences) 82 71 83 context = {} 72 84 if self.request.method == 'POST': -
trunk/pylucid/PyLucid/plugins_internal/plugin_admin/plugin_admin.py
r1532 r1544 25 25 import os 26 26 27 from django.utils.translation import ugettext as _ 27 28 from django import newforms as forms 28 from django.utils.translation import ugettext as _29 29 from django.conf import settings 30 30 31 from PyLucid.system.plugin_manager import get_plugin_list, install_plugin 32 from PyLucid.system.plugin_import import get_plugin_config 33 from PyLucid.system.BasePlugin import PyLucidBasePlugin 31 34 from PyLucid.models import Plugin 32 from PyLucid.system.plugin_manager import get_plugin_list, get_plugin_config, \33 install_plugin34 from PyLucid.system.BasePlugin import PyLucidBasePlugin35 35 36 36 -
trunk/pylucid/PyLucid/plugins_internal/preferences/preferences.py
- Property svn:eol-style set to LF
- Property svn:keywords set to Rev Author
r1540 r1544 12 12 $LastChangedDate$ 13 13 $Rev$ 14 $Author : JensDiemer$14 $Author$ 15 15 16 16 :copyleft: 2008 by the PyLucid team. … … 26 26 from django.utils.translation import ugettext as _ 27 27 28 from PyLucid. models import Preference28 from PyLucid.db.preferences import get_all_prefs, Preferences 29 29 from PyLucid.system.BasePlugin import PyLucidBasePlugin 30 30 from PyLucid.tools.data_eval import data_eval, DataEvalError 31 32 INTERNAL_NAME = "[system]"33 34 35 class DataEvalField(forms.CharField):36 def clean(self, raw_value):37 raw_value = super(DataEvalField, self).clean(raw_value)38 try:39 value = data_eval(raw_value)40 except DataEvalError, e:41 raise ValidationError(_(u"data eval error: %s") % e)42 else:43 return value44 45 class PformatWidget(forms.Textarea):46 def __init__(self, attrs=None):47 self.attrs={'rows': '10'}48 49 def render(self, name, value, attrs=None):50 if not isinstance(value, basestring):51 value = pformat(value)52 return super(PformatWidget, self).render(name, value, attrs=None)53 54 class EditForm(forms.Form):55 """56 Form for editing a preferences57 """58 raw_value = DataEvalField(widget=PformatWidget())59 31 60 32 … … 63 35 64 36 def _vebose_plugin_name(self, pref): 65 if pref.plugin == None: 66 return INTERNAL_NAME 67 else: 68 return pref.plugin.plugin_name.replace("_", " ") 37 return pref.plugin.plugin_name.replace("_", " ") 69 38 70 39 def select(self): … … 72 41 Display the sub menu 73 42 """ 74 self.context["PAGE"].title = _(" Low levelpreferences editor")43 self.context["PAGE"].title = _("preferences editor") 75 44 76 preferences = {}77 for pref in Preference.objects.all():78 plugin_name = self._vebose_plugin_name(pref)45 items = [] 46 for pref in get_all_prefs(): 47 edit_link = self.URLs.methodLink("edit", args=pref.id) 79 48 80 pref.link = self.URLs.methodLink("edit", args=(pref.id, pref.name)) 81 82 if plugin_name not in preferences: 83 preferences[plugin_name] = [pref] 84 else: 85 preferences[plugin_name].append(pref) 49 items.append({ 50 "plugin_name": self._vebose_plugin_name(pref), 51 "plugin_description": pref.plugin.description, 52 "edit_link": edit_link, 53 }) 86 54 87 55 context = { 88 "preferences": preferences, 56 "preferences": items, 57 "admin_link": self.URLs.adminLink("PyLucid/preference"), 89 58 } 90 59 self._render_template("select", context)#, debug=True) 91 60 92 def edit(self, url_args =None):61 def edit(self, url_args): 93 62 try: 94 url_args = url_args.strip("/") .split("/",1)[0]63 url_args = url_args.strip("/") 95 64 pref_id = int(url_args) 96 65 except Exception, e: … … 98 67 return 99 68 100 p = Preference.objects.get(id = pref_id) 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 101 75 102 76 if self.request.method == 'POST': 103 form = EditForm(self.request.POST)77 form = unbound_form(self.request.POST) 104 78 if form.is_valid(): 105 value = form.cleaned_data["raw_value"] 106 if "validate" in self.request.POST: 107 # rebuild the form for pformat with the eval data 108 form = EditForm({"raw_value": value}) 109 self.page_msg("validate only...") 110 else: 111 # save the form 112 p.value = value 113 p.save() 114 self.page_msg.green("new value saved!") 115 return self.select() # Display the menu 79 new_data_dict = form.cleaned_data 80 p.update_and_save(new_data_dict) 81 self.page_msg("New preferences saved.") 82 return self.select() # Display the menu 116 83 else: 117 form = EditForm({"raw_value": p.value})84 form = unbound_form(data_dict) 118 85 119 86 context = { 120 87 "plugin_name": self._vebose_plugin_name(p), 121 "pref_name": p.name,122 "description": p.description,123 88 "form": form, 124 89 "url_abort": self.URLs.methodLink("select"), 125 90 } 126 91 self._render_template("edit_form", context)#, debug=True) 127 # self._render_string_template(EDIT_TEMPLATE, context)#, debug=True)128 92 129 93 … … 133 97 134 98 135 136 137 138 139 140 141 142 -
trunk/pylucid/PyLucid/plugins_internal/preferences/preferences_cfg.py
- Property svn:eol-style set to LF
-
trunk/pylucid/PyLucid/plugins_internal/preferences/__init__.py
- Property svn:eol-style set to LF
-
trunk/pylucid/PyLucid/plugins_internal/search/search.py
r1418 r1544 49 49 50 50 51 class PreferencesForm(forms.Form): 52 min_term_len = forms.IntegerField( 53 help_text="Min length of a search term", 54 initial=3, min_value=1 55 ) 56 max_term_len = forms.IntegerField( 57 help_text="Max length of a search term", 58 initial=50, min_value=1, max_value=200 59 ) 60 max_results = forms.IntegerField( 61 help_text="Number of the paged for the result page", 62 initial=20, min_value=1, max_value=200 63 ) 64 text_cutout_len = forms.IntegerField( 65 help_text="The length of the text-hit-cutouts", 66 initial=50, min_value=1, max_value=200 67 ) 68 text_cutout_lines = forms.IntegerField( 69 help_text="Max. cutout lines for every search term", 70 initial=5, min_value=1, max_value=20 71 ) 72 51 73 52 74 class SearchForm(forms.Form): … … 63 85 Insert a empty search form into the page. 64 86 """ 87 self.page_msg("Preferences:", self.preferences) 65 88 search_form = SearchForm() 66 89 context = { -
trunk/pylucid/PyLucid/system/BasePlugin.py
r1536 r1544 40 40 from PyLucid.tools.utils import escape 41 41 from PyLucid.system.internal_page import InternalPage, InternalPageNotFound 42 from PyLucid.system.plugin_ managerimport get_plugin_config, debug_plugin_config42 from PyLucid.system.plugin_import import get_plugin_config, debug_plugin_config 43 43 from PyLucid.models import Plugin 44 44 … … 59 59 60 60 self.current_page = self.context["PAGE"] 61 self.preferences = self.context.preferences 61 62 62 63 def build_menu(self): -
trunk/pylucid/PyLucid/system/page_msg.py
r1313 r1544 54 54 55 55 request = context["request"] 56 self.debug_mode = request.debug56 self.debug_mode = getattr(request, "debug", False) 57 57 58 58 self._charset = settings.DEFAULT_CHARSET -
trunk/pylucid/PyLucid/system/plugin_manager.py
r1540 r1544 34 34 from django.http import HttpResponse, Http404 35 35 36 from PyLucid.db.preferences import Preferences, preference_cache, \ 37 PreferenceDoesntExist 38 from PyLucid.system.plugin_import import get_plugin_module, get_plugin_config 36 39 from PyLucid.system.exceptions import * 37 from PyLucid.models import Plugin, Preference 38 39 40 def _import(request, from_name, object_name): 41 """ 42 from 'from_name' import 'object_name' 43 """ 44 try: 45 return __import__(from_name, {}, {}, [object_name]) 46 except (ImportError, SyntaxError), e: 47 if request.user.is_superuser or request.debug: 48 raise 49 raise ImportError, "Can't import %s from %s: %s" % ( 50 object_name, from_name, e 51 ) 52 53 def get_plugin_class(request, package_name, plugin_name): 54 """ 55 import the plugin/plugin and returns the class object 56 """ 57 plugin = _import(request, 58 from_name = ".".join([package_name, plugin_name, plugin_name]), 59 object_name = plugin_name 60 ) 61 plugin_class = getattr(plugin, plugin_name) 62 return plugin_class 63 64 def debug_plugin_config(page_msg, plugin_config): 65 for item in dir(plugin_config): 66 if item.startswith("_"): 67 continue 68 page_msg("'%s':" % item) 69 page_msg(getattr(plugin_config, item)) 70 71 def get_plugin_config(request, package_name, plugin_name, 72 dissolve_version_string=False, extra_verbose=False): 73 """ 74 imports the plugin and the config plugin and returns a merge config-object 75 76 dissolve_version_string == True -> get the version string (__version__) 77 from the plugin and put it into the config object 78 """ 79 config_name = "%s_cfg" % plugin_name 80 81 def get_plugin(object_name): 82 from_name = ".".join([package_name, plugin_name, object_name]) 83 if extra_verbose: 84 print "from %s import %s" % (from_name, object_name) 85 return _import(request, from_name, object_name) 86 87 config_plugin = get_plugin(config_name) 88 89 if dissolve_version_string: 90 plugin_plugin = get_plugin(plugin_name) 91 92 plugin_version = getattr(plugin_plugin, "__version__", None) 93 if plugin_version: 94 # Cleanup a SVN Revision Number 95 plugin_version = plugin_version.strip("$ ") 96 config_plugin.__version__ = plugin_version 97 98 return config_plugin 40 from PyLucid.models import Plugin 41 42 43 99 44 100 45 def _run(context, local_response, plugin_name, method_name, url_args, … … 167 112 URLs.current_plugin = plugin_name 168 113 169 plugin_class=get_plugin_class(request, plugin.package_name, plugin_name) 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 132 133 plugin_class = getattr(plugin_module, plugin_name) 170 134 class_instance = plugin_class(context, local_response) 171 135 unbound_method = getattr(class_instance, method_name) … … 275 239 return plugin 276 240 277 def _insert_preferences(plugin, plugin_config): 278 preferences = getattr(plugin_config, "preferences", None) 279 if preferences == None: 280 # The plugin has no preferences 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 281 252 return 282 253 283 for pref in preferences: 284 print plugin, type(plugin), pref 285 Preference( 286 plugin = plugin, 287 name = pref["name"], 288 description = pref["description"], 289 value = pref["value"], 290 ).save() 254 p = Preferences() 255 p.set_plugin(plugin) 256 p.create_initial(pref_form) 257 291 258 292 259 def install_plugin(request, package_name, plugin_name, active, … … 315 282 package_name, plugin_name, plugin_config, active, extra_verbose 316 283 ) 317 _insert_preferences( plugin, plugin_config)284 _insert_preferences(request, plugin, package_name, plugin_name) 318 285 319 286
