Changeset 1602
- Timestamp:
- 05/28/08 13:37:32 (5 months ago)
- Location:
- trunk/pylucid
- Files:
-
- 11 modified
-
media/PyLucid/internal_page/admin_menu/sub_menu.html (modified) (1 diff)
-
PyLucid/plugins_internal/admin_menu/admin_menu.py (modified) (3 diffs)
-
PyLucid/plugins_internal/admin_menu/admin_menu_cfg.py (modified) (2 diffs)
-
PyLucid/plugins_internal/EMailSystem/EMailSystem_cfg.py (modified) (2 diffs)
-
PyLucid/plugins_internal/filemanager/filemanager_cfg.py (modified) (2 diffs)
-
PyLucid/plugins_internal/find_and_replace/find_and_replace_cfg.py (modified) (3 diffs)
-
PyLucid/plugins_internal/page_admin/page_admin_cfg.py (modified) (2 diffs)
-
PyLucid/plugins_internal/plugin_admin/plugin_admin_cfg.py (modified) (2 diffs)
-
PyLucid/plugins_internal/preference_editor/preference_editor_cfg.py (modified) (2 diffs)
-
PyLucid/plugins_internal/show_internals/show_internals_cfg.py (modified) (2 diffs)
-
PyLucid/system/plugin_manager.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/media/PyLucid/internal_page/admin_menu/sub_menu.html
r1549 r1602 1 <fieldset><legend>{% trans 'page admin' %}</legend> 2 <ul> 3 <li> 4 <a href="{{ commandURLprefix }}/page_admin/select_edit_page/">{% trans 'select page to edit' %}</a> <small>({% trans 'all pages available!' %})</small> 5 </li> 6 <li> 7 <a href="{{ commandURLprefix }}/page_admin/delete_pages/">{% trans 'delete pages' %}</a> <small>({% trans 'select pages to delete these.' %})</small> 8 </li> 9 <li> 10 <a href="{{ commandURLprefix }}/page_admin/sequencing/">{% trans 'sequencing the pages' %}</a> <small>({% trans 'change the page order.' %})</small> 11 </li> 12 {% if is_admin %} 13 <li> 14 <a href="{{ commandURLprefix }}/find_and_replace/find_and_replace/">{% trans 'find/replace' %}</a> <small>({% trans 'Find/replace page content.' %})</small> 15 </li> 16 {% endif %} 17 </ul> 18 </fieldset> 19 20 {% if is_admin %} 21 22 <fieldset><legend>{% trans 'edit look' %}</legend> 23 <ul> 24 <li> 25 <a href="{{ adminURLprefix }}/PyLucid/style/" onclick="OpenInWindow(this); return false">{% trans 'edit stylesheets' %}</a> 26 | 27 <a href="{{ adminURLprefix }}/PyLucid/style/{{ PAGE.style.id }}/" onclick="OpenInWindow(this); return false">{% trans 'edit current stylesheet' %}</a> 28 </li> 29 <li> 30 <a href="{{ adminURLprefix }}/PyLucid/template/" onclick="OpenInWindow(this); return false">{% trans 'edit templates' %}</a> 31 | 32 <a href="{{ adminURLprefix }}/PyLucid/template/{{ PAGE.template.id }}/" onclick="OpenInWindow(this); return false">{% trans 'edit current template' %}</a> 33 </li> 34 </ul> 35 </fieldset> 36 37 <fieldset><legend>{% trans 'user management' %}</legend> 38 <ul> 39 <li> 40 <a href="{{ adminURLprefix }}/auth/user/" onclick="OpenInWindow(this); return false">{% trans 'edit users' %}</a> 41 </li> 42 <li> 43 <a href="{{ adminURLprefix }}/auth/group/" onclick="OpenInWindow(this); return false">{% trans 'edit user groups' %}</a> 44 </li> 45 <li> 46 <a href="{{ commandURLprefix }}/EMailSystem/user_list/">{% trans 'EMail system' %}</a> 47 </li> 48 </ul> 49 </fieldset> 50 51 <fieldset><legend>{% trans 'miscellaneous' %}</legend> 52 <ul> 53 <li> 54 <a href="{{ commandURLprefix }}/plugin_admin/menu/">{% trans 'Plugin administration' %}</a> 55 </li> 56 <li> 57 <a href="{{ commandURLprefix }}/preference_editor/select/">{% trans 'Preferences editor' %}</a> 58 </li> 59 <li> 60 <a href="{{ commandURLprefix }}/filemanager/filelist/">{% trans 'Filemanager' %}</a> 61 </li> 62 <li> 63 <a href="{{ commandURLprefix }}/show_internals/menu/">{% trans 'Show internals' %}</a> 64 </li> 65 </ul> 66 </fieldset> 67 68 {% endif %} 1 {% for section in dynamic_menu %} 2 <fieldset><legend>{{ section.name }}</legend> 3 <ul> 4 {% for entry in section %} 5 <li><a href="{{ entry.link }}" {% if entry.open_in_window %}onclick="OpenInWindow(this); return false"{% endif %}>{{ entry.title }}</a> - <small>{{ entry.help_text }}</small></li> 6 {% endfor %} 7 </ul> 8 </fieldset> 9 {% endfor %} -
trunk/pylucid/PyLucid/plugins_internal/admin_menu/admin_menu.py
r1532 r1602 19 19 20 20 from django.utils.translation import ugettext as _ 21 from django.utils.safestring import mark_safe 21 22 22 23 from PyLucid.system.BasePlugin import PyLucidBasePlugin 24 from PyLucid.models import Plugin 25 from PyLucid.system.plugin_manager import get_plugin_list, install_plugin 26 from PyLucid.system.plugin_import import get_plugin_config, get_plugin_version 27 28 29 class MenuSection(object): 30 """ 31 Container for all entries in a admin sub menu section 32 """ 33 def __init__(self, page_msg, section_name, section_weight): 34 self.page_msg = page_msg 35 self.name = section_name 36 self.weight = section_weight 37 self.data = [] 38 39 def add_method(self, menu_data): 40 self.data.append(menu_data) 41 42 def __iter__(self): 43 """ 44 for django template engine 45 """ 46 data = sorted(self.data, key=lambda x: x.get('weight',0)) 47 for entry in data: 48 yield entry 49 50 def __repr__(self): 51 return repr(self.data) 52 53 54 class Menu(object): 55 """ 56 Container for the complete admin sub menu data 57 """ 58 def __init__(self, page_msg, section_weights): 59 self.page_msg = page_msg 60 self.section_weights = section_weights 61 self.data = {} 62 63 def add_entry(self, section_name, menu_data): 64 if section_name not in self.data: 65 # Create new section 66 weights = self.section_weights 67 section_weight = weights.get(section_name, 0) 68 self.data[section_name] = MenuSection( 69 self.page_msg, section_name, section_weight 70 ) 71 72 section = self.data[section_name] 73 section.add_method(menu_data) 74 75 def __iter__(self): 76 """ 77 for django template engine 78 """ 79 sections = self.data.keys() 80 weights = self.section_weights 81 82 # sort in two steps: 83 sections = [(weights.get(s, 0), s) for s in sections] 84 sections = [x[1] for x in sorted(sections)] 85 86 # FIXME: sorting in one step, but it doesn't work, why? 87 # sections = sorted(sections, key=lambda x: weights.get(x, 0)) 88 89 for section in sections: 90 yield self.data[section] 91 92 def debug(self): 93 """ 94 Display all data 95 """ 96 self.page_msg("Menu debug:") 97 self.page_msg(self.section_weights) 98 self.page_msg(self.data) 99 23 100 24 101 … … 42 119 def sub_menu(self): 43 120 """ 44 render the sub menu 45 """ 121 render the admin sub menu 122 """ 123 # Collect all plugin methods with a admin_sub_menu data dict 124 menu = self._generate_menu() 125 #menu.debug() 126 127 # Get some static links to the django admin panel 128 self._add_static_entries(menu) 129 #menu.debug() 130 131 #---------------------------------------------------------------------- 46 132 # Change the global page title: 47 133 self.context["PAGE"].title = _("Administration sub menu") … … 50 136 51 137 context = { 52 "PAGE" : self.context["PAGE"], 53 "commandURLprefix": self.URLs.get_command_base(), 54 "adminURLprefix" : self.URLs["adminBase"], 55 "is_admin" : is_admin, 138 "dynamic_menu" : menu, 56 139 } 57 140 self._render_template("sub_menu", context)#, debug=True) 58 141 59 60 142 def _add_static_entries(self, menu): 143 """ 144 Adds some static sub menu entries to the django admin panel 145 TODO: Make this dynamic changeable 146 """ 147 if not self.request.user.is_staff: 148 # All entries here are in the django admin panel 149 # Skip all links, if the current user can't use it 150 return 151 152 page_obj = self.context["PAGE"] 153 154 def add_entry(section, link, title, help_text="", weight=0): 155 menu.add_entry( 156 section, 157 menu_data = { 158 #"section" : section, 159 "link" : link, 160 "title" : title, 161 "help_text" : help_text, 162 "open_in_window": True, 163 "weight" : weight, 164 }, 165 ) 166 167 section = _("edit look") 168 169 # STYLE 170 add_entry(section, 171 self.URLs.adminLink("PyLucid/style/%s" % page_obj.style.id), 172 _("edit '%s' stylesheet") % page_obj.style, 173 _("The current used stylesheet."), 174 -5, 175 ) 176 add_entry(section, 177 self.URLs.adminLink("PyLucid/style"), 178 _("edit all stylesheets"), 179 "You get a list of all existing stylesheets.", 180 -4, 181 ) 182 183 # TEMPLATE 184 add_entry(section, 185 self.URLs.adminLink("PyLucid/template"), 186 _("edit all templates"), 187 "You get a list of all existing templates.", 188 8, 189 ) 190 add_entry(section, 191 self.URLs.adminLink("PyLucid/template/%s" % page_obj.template.id), 192 _("edit '%s' template") % page_obj.template, 193 _("The current used template."), 194 5, 195 ) 196 197 section = _("user management") 198 199 add_entry(section, 200 self.URLs.adminLink("auth/user"), 201 _("edit users"), 202 "Edit all existing users.", 203 5, 204 ) 205 add_entry(section, 206 self.URLs.adminLink("auth/group"), 207 _("edit user groups"), 208 "Edit all existing users.", 209 5, 210 ) 211 212 213 def _generate_menu(self): 214 """ 215 Generate the dynamic admin sub menu 216 """ 217 # Get the preferences from the database: 218 preferences = self.get_preferences() 219 if preferences == None: 220 # preferences not in database -> reinit required 221 if self.request.debug == True: 222 msg = ( 223 '<a href="http://www.pylucid.org/_goto/121/changes/">' 224 'reinit "admin_menu" plugin required!</a>' 225 ) 226 self.page_msg.red(mark_safe(msg)) 227 section_weights = [] 228 else: 229 # Sort the sections with the weight information from the preferences 230 section_weights = preferences["section_weights"] 231 232 # All installed + active plugins 233 plugins = Plugin.objects.all().filter(active = True).order_by( 234 'package_name', 'plugin_name' 235 ) 236 237 menu = Menu(self.page_msg, section_weights) 238 239 # Get the plugin config and build the menu data 240 for plugin in plugins: 241 config = get_plugin_config( 242 package_name = plugin.package_name, 243 plugin_name = plugin.plugin_name, 244 debug = False, 245 ) 246 247 for method, data in config.plugin_manager_data.iteritems(): 248 if "admin_sub_menu" not in data: 249 # This method should not listed into the admin sub menu 250 continue 251 252 menu_data = data["admin_sub_menu"] 253 section = unicode(menu_data["section"]) # translate gettext_lazy 254 255 # Add the _command link to the menu data 256 link = self.URLs.commandLink( 257 plugin_name = plugin.plugin_name, 258 method_name = method, 259 ) 260 menu_data["link"] = link 261 262 menu.add_entry(section, menu_data) 263 264 return menu -
trunk/pylucid/PyLucid/plugins_internal/admin_menu/admin_menu_cfg.py
r1479 r1602 1 #!/usr/bin/python2 1 # -*- coding: UTF-8 -*- 2 3 from pprint import pformat 4 from PyLucid.tools.data_eval import data_eval, DataEvalError 5 6 from django import newforms as forms 7 from django.newforms.util import ValidationError 8 from django.utils.translation import gettext_lazy as _ 3 9 4 10 #_____________________________________________________________________________ … … 9 15 __long_description__ = """""" 10 16 __can_deinstall__ = False 17 18 #_____________________________________________________________________________ 19 # preferences 20 21 class WeightField(forms.CharField): 22 def clean(self, value): 23 """ 24 TODO: Check the data. 25 """ 26 # Validates max_length and min_length 27 value = super(WeightField, self).clean(value) 28 29 try: 30 data = data_eval(value) 31 except DataEvalError, err: 32 raise ValidationError("Can't evaluate data: %s" % err) 33 34 for section_name, weight in data.iteritems(): 35 if not isinstance(section_name, basestring): 36 raise ValidationError("Wrong section name '%r'" % section_name) 37 if not isinstance(weight, int): 38 raise ValidationError("Wrong weight for '%s'" % section_name) 39 if weight<-10 or weight>10: 40 msg = ( 41 "weight for '%s' out of range (min: -10, max: 10)" 42 ) % section_name 43 raise ValidationError(msg) 44 45 return data 46 47 48 class PreferencesForm(forms.Form): 49 # TODO: Find a better way to create a better sized form 50 section_weights = WeightField( 51 min_length = 2, 52 help_text=_( 53 "Weigth for every admin sub menu section entry. (ascending order) " 54 ), 55 widget=forms.Textarea(attrs={'rows': '10'}), 56 initial= ( 57 '{' 58 ' "page admin": -5,' 59 ' "edit look": 0,' 60 ' "user management": 3,' 61 ' "miscellaneous": 6,' 62 ' "setup": 8,' 63 '}' 64 ) 65 ) 11 66 12 67 #_____________________________________________________________________________ -
trunk/pylucid/PyLucid/plugins_internal/EMailSystem/EMailSystem_cfg.py
r1479 r1602 1 #!/usr/bin/python2 1 # -*- coding: UTF-8 -*- 2 3 from django.utils.translation import gettext_lazy as _ 3 4 4 5 #_____________________________________________________________________________ … … 19 20 "must_login" : True, 20 21 "must_admin" : False, 22 "admin_sub_menu": { 23 "section" : _("user management"), 24 "title" : _("EMail system"), 25 "help_text" : _("Send other PyLucid members a email."), 26 "open_in_window": False, 27 "weight" : 0, 28 }, 21 29 }, 22 30 } -
trunk/pylucid/PyLucid/plugins_internal/filemanager/filemanager_cfg.py
r1479 r1602 1 #!/usr/bin/python2 1 # -*- coding: UTF-8 -*- 2 3 from django.utils.translation import gettext_lazy as _ 3 4 4 5 #_____________________________________________________________________________ … … 28 29 plugin_manager_data = { 29 30 "lucidTag" : global_rights, 30 "filelist" : global_rights, 31 "filelist" : { 32 "must_login" : True, 33 "must_admin" : True, 34 "admin_sub_menu": { 35 "section" : _("miscellaneous"), 36 "title" : _("Filemanager"), 37 "help_text" : _( 38 "Administrate static files." 39 ), 40 "open_in_window": False, 41 "weight" : 0, 42 }, 43 }, 31 44 "select_basepath": global_rights, 32 45 "edit": global_rights, -
trunk/pylucid/PyLucid/plugins_internal/find_and_replace/find_and_replace_cfg.py
r1551 r1602 1 #!/usr/bin/python2 1 # -*- coding: UTF-8 -*- 2 3 from django import newforms as forms 4 from django.utils.translation import gettext_lazy as _ 3 5 4 6 #_____________________________________________________________________________ … … 20 22 # preferences 21 23 22 from django import newforms as forms23 from django.utils.translation import ugettext as _24 25 24 class PreferencesForm(forms.Form): 26 25 min_term_len = forms.IntegerField( … … 40 39 "must_login" : True, 41 40 "must_admin" : True, 41 "admin_sub_menu": { 42 "section" : _("page admin"), 43 "title" : _("find/replace"), 44 "help_text" : _( 45 "Find and replace strings in page/stylesheets/template content." 46 ), 47 "open_in_window": False, 48 "weight" : 5, 49 }, 42 50 }, 43 51 } 44 45 preferences = (46 {47 "name": "term len limit",48 "description": "How min/max long must a search term be?",49 "value": {50 "min term len": 1,51 "max term len": 255,52 }53 },54 ) -
trunk/pylucid/PyLucid/plugins_internal/page_admin/page_admin_cfg.py
r1596 r1602 1 #!/usr/bin/python2 1 # -*- coding: UTF-8 -*- 2 3 from django.utils.translation import gettext_lazy as _ 3 4 4 5 #_____________________________________________________________________________ … … 17 18 # plugin administration data 18 19 19 global_rights = {20 "must_login" : True,21 "must_admin" : False,22 }23 20 plugin_manager_data = { 24 "edit_page" : global_rights, 25 "new_page" : global_rights, 26 "delete_page" : global_rights, 21 "edit_page" : { 22 "must_login" : True, 23 "must_admin" : False, 24 }, 25 "new_page" : { 26 "must_login" : True, 27 "must_admin" : False, 28 }, 29 "delete_page" : { 30 "must_login" : True, 31 "must_admin" : False, 32 }, 27 33 "markup_help" : { 28 34 "must_login" : False, 29 35 "must_admin" : False, 30 36 }, 31 "select_edit_page" : global_rights, 37 "select_edit_page" : { 38 "must_login" : True, 39 "must_admin" : False, 40 "admin_sub_menu": { 41 "section" : _("page admin"), 42 "title" : _("select page to edit"), 43 "help_text" : _("all pages available!"), 44 "open_in_window": False, 45 "weight" : -8, 46 }, 47 }, 32 48 "delete_pages" : { 33 49 "must_login" : True, 34 50 "must_admin" : True, 51 "admin_sub_menu": { 52 "section" : _("page admin"), 53 "title" : _("delete pages"), 54 "help_text" : _("select pages to delete these."), 55 "open_in_window": False, 56 "weight" : -5, 57 }, 35 58 }, 36 "sequencing" : global_rights, 59 "sequencing" : { 60 "must_login" : True, 61 "must_admin" : False, 62 "admin_sub_menu": { 63 "section" : _("page admin"), 64 "title" : _("sequencing the pages"), 65 "help_text" : _("change the page order."), 66 "open_in_window": False, 67 "weight" : -3, 68 }, 69 }, 37 70 "tag_list": { 38 71 "must_login" : False, -
trunk/pylucid/PyLucid/plugins_internal/plugin_admin/plugin_admin_cfg.py
r1479 r1602 1 #!/usr/bin/python2 1 # -*- coding: UTF-8 -*- 2 3 from django.utils.translation import gettext_lazy as _ 3 4 4 5 #_____________________________________________________________________________ … … 16 17 # plugin administration data 17 18 18 global_rights = { 19 "must_login": True, 20 "must_admin": True, 19 plugin_manager_data = { 20 "menu": { 21 "must_login": True, 22 "must_admin": True, 23 "admin_sub_menu": { 24 "section" : _("setup"), 25 "title" : _("Plugin administration"), 26 "help_text" : _( 27 "Manage all PyLucid plugins." 28 ), 29 "open_in_window": False, 30 "weight" : -8, 31 }, 32 }, 33 "plugin_setup": { 34 "must_login": True, 35 "must_admin": True, 36 }, 21 37 } 22 plugin_manager_data = {23 "menu": global_rights,24 "plugin_setup": global_rights,25 } -
trunk/pylucid/PyLucid/plugins_internal/preference_editor/preference_editor_cfg.py
r1549 r1602 1 #!/usr/bin/python2 1 # -*- coding: UTF-8 -*- 2 3 from django.utils.translation import gettext_lazy as _ 3 4 4 5 #_____________________________________________________________________________ … … 15 16 # plugin administration data 16 17 17 18 global_rights = { 19 "must_login" : True, 20 "must_admin" : True, 18 plugin_manager_data = { 19 "select" : { 20 "must_login" : True, 21 "must_admin" : True, 22 "admin_sub_menu": { 23 "section" : _("setup"), 24 "title" : _("Preferences editor"), 25 "help_text" : _( 26 "Setup all plugin preferences." 27 ), 28 "open_in_window": False, 29 "weight" : -5, 30 }, 31 }, 32 "edit": { 33 "must_login" : True, 34 "must_admin" : True, 35 }, 21 36 } 22 23 plugin_manager_data = {24 "select" : global_rights,25 "edit": global_rights,26 } -
trunk/pylucid/PyLucid/plugins_internal/show_internals/show_internals_cfg.py
r1574 r1602 1 #!/usr/bin/python2 1 # -*- coding: UTF-8 -*- 2 3 from django.utils.translation import gettext_lazy as _ 3 4 4 5 #_____________________________________________________________________________ … … 22 23 "lucidTag" : global_rights, 23 24 "link" : global_rights, 24 "menu" : global_rights, 25 "menu" : { 26 "must_login" : True, 27
