Attachment '60015_newpage_dialog_in_showcategory_page.patch'

Download

   1 diff -r 7401f51c198b MoinMoin/macro/ShowCategory.py
   2 --- a/MoinMoin/macro/ShowCategory.py	Tue Nov 25 11:08:51 2008 +0800
   3 +++ b/MoinMoin/macro/ShowCategory.py	Tue Nov 25 11:13:23 2008 +0800
   4 @@ -8,7 +8,7 @@
   5      @license: GNU GPL, see COPYING for details.
   6  """
   7  
   8 -from MoinMoin import wikiutil2
   9 +from MoinMoin import wikiutil, wikiutil2
  10  from MoinMoin.Page import Page
  11  
  12  _sysmsg = '<p><strong class="%s">%s</strong></p>'
  13 @@ -19,26 +19,55 @@
  14                    recursive=False, items=0, skipitems=0, exclude_template=True):
  15      cc = wikiutil2.CategoryCache(request)
  16      _ = request.getText
  17 +    summary_of_subcategories = []
  18 +    summary_of_subpages = []
  19      
  20      if "all" in categorylist:
  21 +        categorylist = ["all"]
  22          show_cat = True
  23          show_page = False
  24          recursive = False
  25 -        summary_of_subcategories = "<h2>" + _("All categories") + "</h2>\n" + \
  26 -                                   _("There are %(count)d categories in this wiki.")
  27 -        summary_of_subpages      = ""
  28 +        summary_of_subcategories = ["<h2>" + _("All categories") + "</h2>",
  29 +                                    _("There are %(count)d categories in this wiki."),
  30 +                                   ]
  31 +        summary_of_subpages      = []
  32      else:
  33 -        summary_of_subcategories = "<h2>" + _("Subcategories of <b>%(category)s</b>") + "</h2>\n" + \
  34 -                                   _("This category has the following %(count)d subcategories.")
  35 -        summary_of_subpages      = "<h2>" + _("Pages in category <b>%(category)s</b>") + "</h2>\n" + \
  36 -                                   _("There are %(count)d pages are in this category.")
  37 -        
  38 +        summary_of_subcategories = ["<h2>" + _("Subcategories of <b>%(category)s</b>") + "</h2>",
  39 +                                    u"<span id='subcategory-heading'>" + _("This category has the following %(count)d subcategories.") + u"</span>",
  40 +                                    u"<div id='new-subcategory-dialog' class='new-subcategory-dialog'>",
  41 +                                    "%(newsubcategory)s"
  42 +                                    u"</div>",
  43 +                                    "<script type=\"text/javascript\">",
  44 +                                    "if (window.showToggle) {",
  45 +                                    "  showToggle('subcategory-heading', ['new-subcategory-dialog'], '', \"" + _("add") + "\", \"" + _("hide") + "\", true);",
  46 +                                    "}",
  47 +                                    "</script>\n",
  48 +                                   ]
  49 +        summary_of_subpages      = ["<h2>" + _("Pages in category <b>%(category)s</b>") + "</h2>",
  50 +                                    u"<span id='subpage-heading'>" + _("There are %(count)d pages are in this category.") + u"</span>",
  51 +                                    u"<div id='new-subpage-dialog' class='new-subpage-dialog'>",
  52 +                                    "%(newsubpage)s"
  53 +                                    u"</div>",
  54 +                                    "<script type=\"text/javascript\">",
  55 +                                    "if (window.showToggle) {",
  56 +                                    "  showToggle('subpage-heading', ['new-subpage-dialog'], '', \"" + _("add") + "\", \"" + _("hide") + "\", true);",
  57 +                                    "}",
  58 +                                    "</script>\n",
  59 +                                   ]
  60 +    
  61 +    summary_of_subcategories = '\n'.join(summary_of_subcategories)
  62 +    summary_of_subpages = '\n'.join(summary_of_subpages)
  63      result = []
  64  
  65      # show sub category
  66 +    Parser = wikiutil.searchAndImportPlugin(request.cfg, "parser", request.page.pi['format'])
  67      if show_cat:
  68          for category in categorylist:
  69              itemlist = []
  70 +            if category != "all":
  71 +                newsubcategory = wikiutil.renderText(request, Parser, u" <<NewPage(CategoryTemplate, %s, category=%s, validate=category)>>" % (_("Create a sub category"),category))
  72 +            else:
  73 +                newsubcategory = u""
  74              for i in sorted( cc.get_sub_categories(category,recursive=recursive, exclude_template=exclude_template) ):
  75                  name = i
  76                  page = Page(request, name)
  77 @@ -65,7 +94,7 @@
  78                      itemlist=[ (x[-2], x[-1]) for x in itemlist ]
  79      
  80              if show_summary:
  81 -                result += [ summary_of_subcategories % {'category': category, 'count': len(itemlist)} ]
  82 +                result += [ summary_of_subcategories % {'category': category, 'count': len(itemlist), 'newsubcategory': newsubcategory} ]
  83              
  84              if skipitems:
  85                  itemlist=itemlist[skipitems:]
  86 @@ -76,7 +105,11 @@
  87      # show pages belong to this category
  88      if show_page:
  89          for category in categorylist:
  90 +            template_pages = cc.get_templates(category, True)
  91 +            if template_pages:
  92 +                template_pages.insert(0, ('', _('<No addition>')))
  93              itemlist = []
  94 +            newsubpage = wikiutil.renderText(request, Parser, u" <<NewPage(%s, %s, category=%s, validate=nocategory)>>" % (template_pages, _("Create a sub page"),category))
  95              for i in sorted( cc.get_sub_pages(category,recursive=recursive, exclude_template=exclude_template) ):
  96                  name = i
  97                  page = Page(request, name)
  98 @@ -102,7 +135,7 @@
  99                      itemlist=[ (x[-2], x[-1]) for x in itemlist ]
 100              
 101              if show_summary:
 102 -                result += [ summary_of_subpages % {'category': category, 'count': len(itemlist)} ]
 103 +                result += [ summary_of_subpages % {'category': category, 'count': len(itemlist), 'newsubpage': newsubpage} ]
 104  
 105              if skipitems:
 106                  itemlist=itemlist[skipitems:]
 107 diff -r 7401f51c198b MoinMoin/wikiutil2.py
 108 --- a/MoinMoin/wikiutil2.py	Tue Nov 25 11:08:51 2008 +0800
 109 +++ b/MoinMoin/wikiutil2.py	Tue Nov 25 11:13:23 2008 +0800
 110 @@ -254,20 +254,44 @@
 111          return result    
 112  
 113      def get_templates(self, category, recursive=False):
 114 -        result = set()
 115 -        subpages = self.get_sub_pages(category, recursive, exclude_template=False)
 116 -        for item in subpages:
 117 -            if self.request.cfg.cache.page_template_regexact.search(item) is not None:
 118 -                result.add(item)
 119 +        """ Get templates list suitable for category.
 120 +        """
 121 +        result = []
 122 +        category_list = self._get_page_category_list('', category=category)
 123 +        for category in category_list:
 124 +            if category == 'CategoryCategory':
 125 +                continue
 126 +            subpages = self.get_sub_pages(category, recursive, exclude_template=False)
 127 +            for item in subpages:
 128 +                if self.request.cfg.cache.page_template_regexact.search(item) is not None:
 129 +                    if item not in result:
 130 +                        result.append(item)
 131 +            if result:
 132 +                break
 133          return result
 134 -    
 135 -    def get_page_category_trail(self, pagename, level=9):
 136 +
 137 +    def get_page_category_trail(self, pagename, level=9, category=''):
 138 +        """ Get category trail for page.
 139 +        
 140 +        For non-exist page, if we known category it should belong to, set category parameter.
 141 +        """
 142          result = []
 143 -        self._get_page_category_trail( pagename, level, result)
 144 +        catlist = set()
 145 +        if category:
 146 +            catlist = set(category.split(','))
 147 +        if pagename:
 148 +            catlist = catlist | self.pagedict.get(pagename, set())
 149 +        if catlist:
 150 +            self._get_page_category_trail( catlist, level, result)
 151          return result
 152 -        
 153 +
 154      def _get_page_category_trail(self, pagename, level, result, scanned=[]):
 155 -        categories = self.pagedict.get(pagename, set())
 156 +        # the first argument maybe a set of categories
 157 +        if isinstance(pagename, set):
 158 +            categories = pagename
 159 +        # the first argument is page name.
 160 +        else:
 161 +            categories = self.pagedict.get(pagename, set())
 162          if categories:
 163              level -= 1
 164              for category in categories: 
 165 @@ -280,6 +304,18 @@
 166                  else:
 167                      self._get_page_category_trail(category, level, result, branch)
 168  
 169 +    def _get_page_category_list(self, pagename, level=9, category=''):
 170 +        category_list = []
 171 +        category_trail = self.get_page_category_trail(pagename, level=level, category=category)
 172 +        if category_trail:
 173 +            maxdepth = max ([len(trail) for trail in category_trail])
 174 +            for i in range(0,maxdepth):
 175 +                for trail in category_trail:
 176 +                    if len(trail) < i+1:
 177 +                        continue
 178 +                    if trail[i] != 'CategoryCategory' and trail[i] not in category_list:
 179 +                        category_list.append(trail[i])
 180 +        return category_list
 181  
 182  def formatList(request, itemlist, column=3, show_capital=True):
 183      """

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-11-26 08:19:48, 20.2 KB) [[attachment:60010_macro_showcategory.patch]]
  • [get | view] (2008-11-26 08:20:52, 8.8 KB) [[attachment:60015_newpage_dialog_in_showcategory_page.patch]]
  • [get | view] (2008-11-24 01:47:46, 37.5 KB) [[attachment:category_news.png]]
  • [get | view] (2008-11-24 01:41:53, 16.8 KB) [[attachment:new_subcategory.png]]
  • [get | view] (2008-11-24 01:42:13, 18.5 KB) [[attachment:new_subpage.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.