# HG changeset patch # User Paul Boddie # Date 1298249743 -3600 # Node ID 9e6baeb6ea5d9add1200a63af8176930fb6b93b0 # Parent cf4986b6fb395a27b094c5f2de198a4724f5eb66 Made category propagation optional. Handle unchanged subpages gracefully: this may be necessary when breaking out sections in a reverted page. diff -r cf4986b6fb39 -r 9e6baeb6ea5d actions/SectionBreakout.py --- a/actions/SectionBreakout.py Sun Feb 20 22:02:35 2011 +0100 +++ b/actions/SectionBreakout.py Mon Feb 21 01:55:43 2011 +0100 @@ -36,11 +36,12 @@ heading_details = getHeadingDetails(body, level, level) d = { - "buttons_html" : buttons_html, - "heading_level_label" : escape(_("Heading level")), - "found_headings_label" : escape(_("Headings found in page")), - "preview_label" : escape(_("Preview")), - "level" : escattr(level), + "buttons_html" : buttons_html, + "heading_level_label" : escape(_("Heading level")), + "found_headings_label" : escape(_("Headings found in page")), + "propagate_categories_label" : escape(_("Propagate categories")), + "preview_label" : escape(_("Preview")), + "level" : escattr(level), } html = u''' @@ -60,6 +61,10 @@ + %(propagate_categories_label)s + + + %(buttons_html)s @@ -78,11 +83,12 @@ # A heading level must be provided. level = form.get("level", [None])[0] + propagate = form.get("propagate", [None])[0] if not level: return 0, _("No heading level specified.") - return self.break_out_headings(int(level)) + return self.break_out_headings(int(level), propagate) def render_success(self, msg, msgtype=None): @@ -94,10 +100,11 @@ pass - def break_out_headings(self, level): + def break_out_headings(self, level, propagate): """ - Break out headings at the given 'level' from the current page. + Break out headings at the given 'level' from the current page. If + 'propagate' is a true value, propagate categories to subpages. """ _ = self._ @@ -108,7 +115,9 @@ # Acquire all heading details from the page. page_body = page.get_raw_body() - categories = getCategoryMembership(page_body) + + if propagate: + categories = getCategoryMembership(page_body) regions = [] current_region_start = None @@ -164,16 +173,21 @@ new_page = PageEditor(request, new_page_name) new_page_body = page_body[start:end] - new_page_categories = getCategoryMembership(new_page_body) + + if propagate: + new_page_categories = getCategoryMembership(new_page_body) - # Add categories if the parent page has any. + # Add categories if the parent page has any. - if new_page_categories != categories: - new_page_body += getCategoryDeclaration(categories) + if new_page_categories != categories: + new_page_body += getCategoryDeclaration(categories) # Save the new page. - new_page.saveText(new_page_body, 0) + try: + new_page.saveText(new_page_body, 0) + except PageEditor.Unchanged: + pass # Retain the preceding region for the current page. @@ -196,13 +210,15 @@ edited_page = PageEditor(request, page.page_name) edited_page_body = "".join(retained_regions) - edited_page_categories = getCategoryMembership(edited_page_body) + + if propagate: + edited_page_categories = getCategoryMembership(edited_page_body) - # Add categories if the parent page should have any, but these were - # broken out. + # Add categories if the parent page should have any, but these were + # broken out. - if edited_page_categories != categories: - edited_page_body += getCategoryDeclaration(categories) + if edited_page_categories != categories: + edited_page_body += getCategoryDeclaration(categories) # Save the current page.