Show
Ignore:
Timestamp:
05/28/08 13:37:32 (6 months ago)
Author:
JensDiemer
Message:

replace the static admin sub menu with a dynamic one ;)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/plugins_internal/admin_menu/admin_menu_cfg.py

    r1479 r1602  
    1 #!/usr/bin/python 
    21# -*- coding: UTF-8 -*- 
     2 
     3from pprint import pformat 
     4from PyLucid.tools.data_eval import data_eval, DataEvalError 
     5 
     6from django import newforms as forms 
     7from django.newforms.util import ValidationError 
     8from django.utils.translation import gettext_lazy as _ 
    39 
    410#_____________________________________________________________________________ 
     
    915__long_description__ = """""" 
    1016__can_deinstall__ = False 
     17 
     18#_____________________________________________________________________________ 
     19# preferences 
     20 
     21class 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 
     48class 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    ) 
    1166 
    1267#_____________________________________________________________________________