Changeset 1555

Show
Ignore:
Timestamp:
05.05.2008 13:00:26 (2 weeks ago)
Author:
JensDiemer
Message:

Some bugfixes:

  • fixed cache problems with PageChoiceField?. Move it into init
  • current page can't be deleted.
  • remove obsolete _delete_cache() method (Page.save() method cleans the cache)
  • clean the page cache, if a page has been deleted
Files:

Legend:

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

    r1551 r1555  
    279279        super(Page, self).save() # Call the "real" save() method 
    280280 
     281    def delete(self): 
     282        # Delete all pages in the cache. 
     283        delete_page_cache() 
     284        super(Page, self).delete() 
     285 
    281286    def get_absolute_url(self): 
    282287        """ 
  • trunk/pylucid/PyLucid/plugins_internal/page_admin/page_admin.py

    r1551 r1555  
    4040from PyLucid.db.page_archiv import archive_page 
    4141from PyLucid.system.BasePlugin import PyLucidBasePlugin 
    42 from PyLucid.system.detect_page import get_default_page_id 
     42from PyLucid.system.detect_page import get_default_page 
    4343from PyLucid.tools.content_processors import apply_markup, \ 
    4444                                                        render_string_template 
     
    6363 
    6464    parent = PageChoiceField( 
    65         widget=forms.Select(choices=get_page_choices()), 
    66         # FIXME: How to set invalid_choice here? 
    6765        help_text="the higher-ranking father page", 
    6866    ) 
     
    8987        widget=forms.TextInput(attrs={'class':'bigger'}), 
    9088    ) 
     89    def __init__(self, *args, **kwargs): 
     90        super(EditPageForm, self).__init__(*args, **kwargs) 
     91        # FIXME: How to set invalid_choice here? 
     92        self.fields["parent"].widget=forms.Select(choices=get_page_choices()) 
     93 
    9194 
    9295#______________________________________________________________________________ 
     
    127130        return edit_page_id, page_instance 
    128131 
    129  
    130     def _delete_cache(self, page_instance): 
    131         """ 
    132         Delete the old page data in the cache, so anonymous users 
    133         see directly the new page content 
    134         """ 
    135         shortcut = page_instance.shortcut 
    136         cache_key = settings.PAGE_CACHE_PREFIX + shortcut 
    137         cache.delete(cache_key) 
    138  
    139132    def _refresh_curent_page(self, page_instance): 
    140133        """ 
     
    158151        if page_instance.id == self.current_page.id: 
    159152            # A existing page was edited 
    160             edit_comment = html_form.cleaned_data["edit_comment"] 
     153            edit_comment = html_form.cleaned_data.pop("edit_comment") 
    161154            # achive the old page data: 
    162155            archive_page(self.current_page, edit_comment) 
    163156            self.page_msg(_("Old page data archived.")) 
    164157 
     158        # Assign parent page 
     159        parent_page_id = html_form.cleaned_data.pop("parent") 
     160        parent = Page.objects.get(id=parent_page_id) 
     161        page_instance.parent = parent 
     162 
    165163        # Transfer the form values into the page instance 
    166164        for key, value in html_form.cleaned_data.iteritems(): 
    167             if key != "edit_comment": # The comment is only for the page archiv 
    168                 setattr(page_instance, key, value) 
     165            setattr(page_instance, key, value) 
    169166 
    170167        try: 
     
    175172            self.page_msg("Can't save the page data:", msg) 
    176173            return 
    177  
    178         # Delete the old page data cache: 
    179         self._delete_cache(page_instance) 
    180174 
    181175        if page_instance.id == self.current_page.id: 
     
    359353        ...this page has sub pages. 
    360354        """ 
    361         # The default page can't delete: 
    362         default_page_id = get_default_page_id() 
    363         if id == default_page_id
     355        skip_data = self.get_delete_skip_data() 
     356        # The skip_data contains the default- and the current page. 
     357        if id in skip_data
    364358            msg = _( 
    365                     "Can't delete the page with ID:%s," 
    366                     " because this is the default page!" 
    367             ) % id 
     359                    "Can't delete the page with ID:%(id)s," 
     360                    " because %(reason)s!" 
     361            ) % {"id":id, "reason":skip_data[id]} 
    368362            raise DeletePageError(msg) 
    369363 
     
    389383            self.page_msg(_("Page with id: %s delete successful.") % id) 
    390384 
    391         if id == self.current_page.id: 
    392             # The current page was deleted, so we must go to a other page. 
    393             # The easyest way, if to go to the default page ;) 
    394             self.current_page.id = default_page_id 
    395             self.current_page = Page.objects.get(id=default_page_id) 
    396  
    397385 
    398386    def _process_delete_pages(self): 
     
    421409 
    422410 
    423     def _get_html(self, sitemap_tree, default_page_id): 
     411    def _get_html(self, sitemap_tree, skip_data): 
    424412        """ 
    425413        generate from the sitemap_tree a "checkbox-list" for the delete 
     
    431419            result.append('<li>') 
    432420 
    433             if entry["id"]==default_page_id
     421            if entry["id"] in skip_data
    434422                html = ( 
    435423                    '<span title="Can not delete this pages,' 
    436                     ' because it the default page.">%(name)s</span>' 
    437                 ) 
     424                    ' because: %s">%%(name)s</span>' 
     425                ) % skip_data[entry["id"]] 
    438426            elif "subitems" in entry: 
    439427                html = ( 
     
    454442            if "subitems" in entry: 
    455443                result.append( 
    456                     self._get_html(entry["subitems"], default_page_id
     444                    self._get_html(entry["subitems"], skip_data
    457445                ) 
    458446 
     
    461449        result.append("</ul>\n") 
    462450        return "".join(result) 
     451 
     452 
     453    def get_delete_skip_data(self): 
     454        """ 
     455        returns a dict with default- and the current page id and why they can't 
     456        delete. 
     457        """ 
     458        skip_data = {} 
     459        skip_data[self.current_page.id] = _( 
     460            "It's the current page." 
     461            " Please goto a other page and start deleting again" 
     462        ) 
     463 
     464        # The default page can't delete, so we need the ID of these page: 
     465        default_page = get_default_page(self.request) 
     466        skip_data["default_page.id"] = _("It's the default page.") 
     467 
     468        return skip_data 
    463469 
    464470 
     
    475481        page_tree = get_sitemap_tree(self.request) 
    476482 
    477         # The default page can't delete, so we need the ID of these page: 
    478         default_page_id = get_default_page_id() 
     483        # The skip_data contains the default- and the current page. 
     484        skip_data = self.get_delete_skip_data() 
    479485 
    480486        # Generate the HTML form code: 
    481         html = self._get_html(page_tree, default_page_id
     487        html = self._get_html(page_tree, skip_data
    482488        html = mark_safe(html) # turn djngo auto-escaping off 
    483489 
  • trunk/pylucid/PyLucid/system/detect_page.py

    r1551 r1555  
    3737 
    3838 
    39 def get_default_page_id(request): 
    40     """ 
    41     returns the default page id 
    42     """ 
     39def get_default_page(request): 
    4340    try: 
    4441        preferences = Plugin.objects.get_preferences("system_settings") 
    45         default_page_id = preferences["index_page"] 
    46         return default_page_id 
    47     except Exception, e: 
    48         # TODO: make a page message for the admin 
    49         # Get the first page 
    50 #        page_msg = request.CONTEXT["page_msg"] 
    51 #        page_msg("Can't get the index page, use the first page.") 
    52         return get_a_page().id 
    53  
    54  
    55 def get_default_page(request): 
    56     page_id = get_default_page_id(request) 
    57     try: 
     42        page_id = preferences["index_page"] 
    5843#        page_id = "wrong test" 
    5944        return Page.objects.get(id__exact=page_id)