Changeset 1555
- Timestamp:
- 05.05.2008 13:00:26 (2 weeks ago)
- Files:
-
- trunk/pylucid/PyLucid/models.py (modified) (1 diff)
- trunk/pylucid/PyLucid/plugins_internal/page_admin/page_admin.py (modified) (13 diffs)
- trunk/pylucid/PyLucid/system/detect_page.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pylucid/PyLucid/models.py
r1551 r1555 279 279 super(Page, self).save() # Call the "real" save() method 280 280 281 def delete(self): 282 # Delete all pages in the cache. 283 delete_page_cache() 284 super(Page, self).delete() 285 281 286 def get_absolute_url(self): 282 287 """ trunk/pylucid/PyLucid/plugins_internal/page_admin/page_admin.py
r1551 r1555 40 40 from PyLucid.db.page_archiv import archive_page 41 41 from PyLucid.system.BasePlugin import PyLucidBasePlugin 42 from PyLucid.system.detect_page import get_default_page _id42 from PyLucid.system.detect_page import get_default_page 43 43 from PyLucid.tools.content_processors import apply_markup, \ 44 44 render_string_template … … 63 63 64 64 parent = PageChoiceField( 65 widget=forms.Select(choices=get_page_choices()),66 # FIXME: How to set invalid_choice here?67 65 help_text="the higher-ranking father page", 68 66 ) … … 89 87 widget=forms.TextInput(attrs={'class':'bigger'}), 90 88 ) 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 91 94 92 95 #______________________________________________________________________________ … … 127 130 return edit_page_id, page_instance 128 131 129 130 def _delete_cache(self, page_instance):131 """132 Delete the old page data in the cache, so anonymous users133 see directly the new page content134 """135 shortcut = page_instance.shortcut136 cache_key = settings.PAGE_CACHE_PREFIX + shortcut137 cache.delete(cache_key)138 139 132 def _refresh_curent_page(self, page_instance): 140 133 """ … … 158 151 if page_instance.id == self.current_page.id: 159 152 # A existing page was edited 160 edit_comment = html_form.cleaned_data ["edit_comment"]153 edit_comment = html_form.cleaned_data.pop("edit_comment") 161 154 # achive the old page data: 162 155 archive_page(self.current_page, edit_comment) 163 156 self.page_msg(_("Old page data archived.")) 164 157 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 165 163 # Transfer the form values into the page instance 166 164 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) 169 166 170 167 try: … … 175 172 self.page_msg("Can't save the page data:", msg) 176 173 return 177 178 # Delete the old page data cache:179 self._delete_cache(page_instance)180 174 181 175 if page_instance.id == self.current_page.id: … … 359 353 ...this page has sub pages. 360 354 """ 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: 364 358 msg = _( 365 "Can't delete the page with ID:% s,"366 " because this is the default page!"367 ) % id359 "Can't delete the page with ID:%(id)s," 360 " because %(reason)s!" 361 ) % {"id":id, "reason":skip_data[id]} 368 362 raise DeletePageError(msg) 369 363 … … 389 383 self.page_msg(_("Page with id: %s delete successful.") % id) 390 384 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_id395 self.current_page = Page.objects.get(id=default_page_id)396 397 385 398 386 def _process_delete_pages(self): … … 421 409 422 410 423 def _get_html(self, sitemap_tree, default_page_id):411 def _get_html(self, sitemap_tree, skip_data): 424 412 """ 425 413 generate from the sitemap_tree a "checkbox-list" for the delete … … 431 419 result.append('<li>') 432 420 433 if entry["id"] ==default_page_id:421 if entry["id"] in skip_data: 434 422 html = ( 435 423 '<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"]] 438 426 elif "subitems" in entry: 439 427 html = ( … … 454 442 if "subitems" in entry: 455 443 result.append( 456 self._get_html(entry["subitems"], default_page_id)444 self._get_html(entry["subitems"], skip_data) 457 445 ) 458 446 … … 461 449 result.append("</ul>\n") 462 450 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 463 469 464 470 … … 475 481 page_tree = get_sitemap_tree(self.request) 476 482 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() 479 485 480 486 # Generate the HTML form code: 481 html = self._get_html(page_tree, default_page_id)487 html = self._get_html(page_tree, skip_data) 482 488 html = mark_safe(html) # turn djngo auto-escaping off 483 489 trunk/pylucid/PyLucid/system/detect_page.py
r1551 r1555 37 37 38 38 39 def get_default_page_id(request): 40 """ 41 returns the default page id 42 """ 39 def get_default_page(request): 43 40 try: 44 41 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"] 58 43 # page_id = "wrong test" 59 44 return Page.objects.get(id__exact=page_id)
