Show
Ignore:
Timestamp:
05/02/08 16:47:16 (23 months ago)
Author:
JensDiemer
Message:

update preferences:

  • move the preferences form from the plugin module into the plugin config modul
  • a plugin must not use try...except to get the preferences
  • update all modules around the plugin install/deinstall etc.
  • detect_page used the system_settings "index_page" value (setup a other default index page works!)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/db/page.py

    r1390 r1551  
    2020#      page-ID  <-> parant-ID relation? 
    2121#      url data for every page? 
     22 
     23from django import newforms as forms 
     24from django.newforms.util import ValidationError 
     25from django.utils.translation import ugettext as _ 
    2226 
    2327from PyLucid.models import User, Page 
     
    129133    return sub_pages 
    130134 
     135#______________________________________________________________________________ 
     136# newforms Page choice 
     137""" 
     138# usage: 
    131139 
     140from PyLucid.db.page import PageChoiceField, get_page_choices 
     141class MyForm(forms.Form): 
     142    ... 
     143    page = PageChoiceField(widget=forms.Select(choices=get_page_choices())) 
     144    ... 
     145""" 
     146 
     147class PageChoiceField(forms.IntegerField): 
     148    def clean(self, page_id): 
     149        """ 
     150        returns the parent page instance. 
     151        Note: 
     152            In PyLucid.models.Page.save() it would be checkt if the selected 
     153            parent page is logical valid. Here we check only, if the page with 
     154            the given ID exists. 
     155        """ 
     156        # let convert the string into a integer: 
     157        page_id = super(PageChoiceField, self).clean(page_id) 
     158 
     159        if page_id == 0: 
     160            # assigned to the tree root. 
     161            return None 
     162 
     163        try: 
     164            #page_id = 999999999 # Not exists test 
     165            page = Page.objects.get(id=page_id) 
     166        except Exception, msg: 
     167            raise ValidationError(_(u"Wrong parent POST data: %s" % msg)) 
     168        else: 
     169            return page_id 
     170 
     171 
     172def get_page_choices(): 
     173    """ 
     174    generate a verbose page name tree for the parent choice field. 
     175    """ 
     176    page_list = flat_tree_list() 
     177    choices = [(0, "---[root]---")] 
     178    for page in page_list: 
     179        choices.append((page["id"], page["level_name"])) 
     180    return choices