Changeset 4304

Show
Ignore:
Timestamp:
09/20/08 14:40:02 (2 months ago)
Author:
Blackhex
Message:

ScreenshotsPlugin:

  • [[ScreenshotsList()]] macro added.
  • Added tags, components and versions variable for [[Screenshots()]] macro.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • screenshotsplugin/0.11/tracscreenshots/api.py

    r4195 r4304  
    6868        return self._get_items(context, 'screenshot', ('id', 'name', 
    6969          'description', 'time', 'author', 'tags', 'file', 'width', 'height')) 
     70 
     71    def get_screenshots_complete(self, context): 
     72        screenshots = self.get_screenshots(context) 
     73        for screenshot in screenshots: 
     74            screenshot['components'] = self.get_screenshot_components(context, 
     75              screenshot['id']) 
     76            screenshot['versions'] = self.get_screenshot_versions(context, 
     77              screenshot['id']) 
     78        return screenshots 
    7079 
    7180    def get_filtered_screenshots(self, context, components, versions): 
  • screenshotsplugin/0.11/tracscreenshots/wiki.py

    r3465 r4304  
    1515 
    1616class ScreenshotsWiki(Component): 
     17    """ 
     18        The wiki module implements macro for screenshots referencing. 
     19    """ 
     20    implements(IWikiSyntaxProvider, IWikiMacroProvider) 
    1721 
    1822    screenshot_macro_doc = """Allows embed screenshot image in wiki page. 
     
    4549 * {{{$width}}} - Original width of image. 
    4650 * {{{$height}}} - Original height of image. 
     51 * {{{$tags}}} - Comma separated list of screenshot tags. 
     52 * {{{$components}}} - Comma separated list of screenshot components. 
     53 * {{{$versions}}} - Comma separated list of screenshot versions. 
    4754 
    4855Example: 
     
    5259}}}""" 
    5360 
    54     """ 
    55         The wiki module implements macro for screenshots referencing. 
    56     """ 
    57     implements(IWikiSyntaxProvider, IWikiMacroProvider) 
     61    screenshots_list_macro_doc = """Displays list of all available screenshots 
     62on wiki page. Accepts one argument which is template for list items fromatting. 
     63Possible variables in this template are: 
     64 
     65 * {{{$id}}} - ID of image. 
     66 * {{{$name}}} - Name of image. 
     67 * {{{$author}}} - User name who uploaded image. 
     68 * {{{$time}}} - Time when image was uploaded. 
     69 * {{{$file}}} - File name of image. 
     70 * {{{$description}}} - Detailed description of image. 
     71 * {{{$width}}} - Original width of image. 
     72 * {{{$height}}} - Original height of image. 
     73 * {{{$tags}}} - Comma separated list of screenshot tags. 
     74 * {{{$components}}} - Comma separated list of screenshot components. 
     75 * {{{$versions}}} - Comma separated list of screenshot versions. 
     76 
     77Example: 
     78 
     79{{{ 
     80 [[ScreenshotsList($name - $description ($widthx$height))]] 
     81}}}""" 
    5882 
    5983    # [screenshot] macro id regular expression. 
     
    6791    default_description = Option('screenshots', 'default_description', 
    6892      '$description', 'Template for embended image description.') 
     93    default_list_item = Option('screenshots', 'default_list_item', '$id - $name - $description', 
     94      doc = 'Default format of list item description of [[ScreenshotsList()]]' \ 
     95      ' macro.') 
    6996 
    7097    # IWikiSyntaxProvider 
     
    80107    def get_macros(self): 
    81108        yield 'Screenshot' 
     109        yield 'ScreenshotsList' 
    82110 
    83111    def get_macro_description(self, name): 
    84112        if name == 'Screenshot': 
    85113            return self.screenshot_macro_doc 
     114        elif name == 'ScreenshotsList': 
     115            return self.screenshots_list_macro_doc 
    86116 
    87117    def expand_macro(self, formatter, name, content): 
     118 
     119        # Create request context. 
     120        context = Context.from_request(formatter.req)('screenshots-wiki') 
     121 
     122        # Get database access. 
     123        db = self.env.get_db_cnx() 
     124        context.cursor = db.cursor() 
     125 
     126        # Get API component. 
     127        api = self.env[ScreenshotsApi] 
     128 
    88129        if name == 'Screenshot': 
    89130            # Check permission. 
     
    91132               return html.div('No permissions to see screenshots.', 
    92133               class_ = 'system-message') 
    93  
    94             # Create request context. 
    95             context = Context.from_request(formatter.req)('screenshots-wiki') 
    96  
    97             # Get database access. 
    98             db = self.env.get_db_cnx() 
    99             context.cursor = db.cursor() 
    100  
    101             # Get API component. 
    102             api = self.env[ScreenshotsApi] 
    103134 
    104135            # Get macro arguments. 
     
    170201                  class_ = 'missing') 
    171202 
     203        elif name == 'ScreenshotsList': 
     204            # Check permission. 
     205            if not formatter.req.perm.has_permission('SCREENSHOTS_VIEW'): 
     206               return html.div('No permissions to see screenshots.', 
     207               class_ = 'system-message') 
     208 
     209            # Get desired list item description 
     210            list_item_description = content or self.default_list_item 
     211 
     212            # Get all screenshots. 
     213            screenshots = api.get_screenshots_complete(context) 
     214 
     215            # Create and return HTML list of screenshots. 
     216            list_items = [] 
     217            for screenshot in screenshots: 
     218                list_item = self._format_description(context, 
     219                  list_item_description, screenshot) 
     220                list_items.append(html.li(html.a(list_item, href = 
     221                  formatter.req.href.screenshots(screenshot['id'])))) 
     222            return html.ul(list_items) 
     223 
    172224    # Internal functions 
    173225 
     
    220272        description = description.replace('$height', to_unicode( 
    221273          screenshot['height'])) 
     274        description = description.replace('$tags', to_unicode( 
     275          screenshot['tags'])) 
     276        description = description.replace('$components', 
     277          ', '.join(screenshot['components'])) 
     278        description = description.replace('$versions', 
     279          ', '.join(screenshot['versions'])) 
     280 
    222281        self.log.debug(description) 
    223282        return format_to_oneliner(self.env, context, description)