Changeset 4311

Show
Ignore:
Timestamp:
09/20/08 16:37:41 (2 months ago)
Author:
Blackhex
Message:

ScreenshotsPlugin:

Files:

Legend:

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

    r3313 r4311  
    6767        return self._get_items(cursor, 'screenshot', ('id', 'name', 
    6868          'description', 'time', 'author', 'tags', 'file', 'width', 'height')) 
     69 
     70    def get_screenshots_complete(self, cursor): 
     71        screenshots = self.get_screenshots(cursor) 
     72        for screenshot in screenshots: 
     73            screenshot['components'] = self.get_screenshot_components(cursor, 
     74              screenshot['id']) 
     75            screenshot['versions'] = self.get_screenshot_versions(cursor, 
     76              screenshot['id']) 
     77        return screenshots 
    6978 
    7079    def get_filtered_screenshots(self, cursor, components, versions): 
  • screenshotsplugin/0.10/tracscreenshots/wiki.py

    r3465 r4311  
    5353}}}""" 
    5454 
     55    screenshots_list_macro_doc = """Displays list of all available screenshots 
     56on wiki page. Accepts one argument which is template for list items fromatting. 
     57Possible variables in this template are: 
     58 
     59 * {{{$id}}} - ID of image. 
     60 * {{{$name}}} - Name of image. 
     61 * {{{$author}}} - User name who uploaded image. 
     62 * {{{$time}}} - Time when image was uploaded. 
     63 * {{{$file}}} - File name of image. 
     64 * {{{$description}}} - Detailed description of image. 
     65 * {{{$width}}} - Original width of image. 
     66 * {{{$height}}} - Original height of image. 
     67 * {{{$tags}}} - Comma separated list of screenshot tags. 
     68 * {{{$components}}} - Comma separated list of screenshot components. 
     69 * {{{$versions}}} - Comma separated list of screenshot versions. 
     70 
     71Example: 
     72 
     73{{{ 
     74 [[ScreenshotsList($name - $description ($widthx$height))]] 
     75}}}""" 
     76 
    5577    """ 
    5678        The wiki module implements macro for screenshots referencing. 
     
    6890    default_description = Option('screenshots', 'default_description', 
    6991      '$description', 'Template for embended image description.') 
     92    default_list_item = Option('screenshots', 'default_list_item', '$id - $name - $description', 
     93      doc = 'Default format of list item description of [[ScreenshotsList()]]' \ 
     94      ' macro.') 
    7095 
    7196    # IWikiSyntaxProvider 
     
    81106    def get_macros(self): 
    82107        yield 'Screenshot' 
     108        yield 'ScreenshotsList' 
    83109 
    84110    def get_macro_description(self, name): 
    85111        if name == 'Screenshot': 
    86112            return self.screenshot_macro_doc 
     113        elif name == 'ScreenshotsList': 
     114            return self.screenshots_list_macro_doc 
     115 
    87116 
    88117    def render_macro(self, req, name, content): 
     118 
     119        # Get database access. 
     120        db = self.env.get_db_cnx() 
     121        cursor = db.cursor() 
     122 
     123        # Get API component. 
     124        api = self.env[ScreenshotsApi] 
     125 
    89126        if name == 'Screenshot': 
    90127            # Check permission. 
     
    92129               return html.div('No permissions to see screenshots.', 
    93130               class_ = 'system-message') 
    94  
    95             # Get database access. 
    96             db = self.env.get_db_cnx() 
    97             cursor = db.cursor() 
    98  
    99             # Get API component. 
    100             api = self.env[ScreenshotsApi] 
    101131 
    102132            # Get macro arguments. 
     
    167197                  title = content, class_ = 'missing') 
    168198 
     199        elif name == 'ScreenshotsList': 
     200            # Check permission. 
     201            if not req.perm.has_permission('SCREENSHOTS_VIEW'): 
     202               return html.div('No permissions to see screenshots.', 
     203               class_ = 'system-message') 
     204 
     205            # Get desired list item description 
     206            list_item_description = content or self.default_list_item 
     207 
     208            # Get all screenshots. 
     209            screenshots = api.get_screenshots_complete(cursor) 
     210 
     211            # Create and return HTML list of screenshots. 
     212            list_items = [] 
     213            for screenshot in screenshots: 
     214                list_item = self._format_description(list_item_description, 
     215                  screenshot) 
     216                list_items.append(html.li(html.a(list_item, href = 
     217                  req.href.screenshots(screenshot['id'])))) 
     218            return html.ul(list_items) 
     219 
    169220    # Internal functions 
    170221 
     
    217268        description = description.replace('$height', to_unicode( 
    218269          screenshot['height'])) 
     270        description = description.replace('$tags', to_unicode( 
     271          screenshot['tags'])) 
     272        description = description.replace('$components', 
     273          ', '.join(screenshot['components'])) 
     274        description = description.replace('$versions', 
     275          ', '.join(screenshot['versions'])) 
    219276        return wiki_to_oneliner(description, self.env) 
    220277