Changeset 4311
- Timestamp:
- 09/20/08 16:37:41 (2 months ago)
- Files:
-
- screenshotsplugin/0.10/tracscreenshots/api.py (modified) (1 diff)
- screenshotsplugin/0.10/tracscreenshots/wiki.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
screenshotsplugin/0.10/tracscreenshots/api.py
r3313 r4311 67 67 return self._get_items(cursor, 'screenshot', ('id', 'name', 68 68 '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 69 78 70 79 def get_filtered_screenshots(self, cursor, components, versions): screenshotsplugin/0.10/tracscreenshots/wiki.py
r3465 r4311 53 53 }}}""" 54 54 55 screenshots_list_macro_doc = """Displays list of all available screenshots 56 on wiki page. Accepts one argument which is template for list items fromatting. 57 Possible 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 71 Example: 72 73 {{{ 74 [[ScreenshotsList($name - $description ($widthx$height))]] 75 }}}""" 76 55 77 """ 56 78 The wiki module implements macro for screenshots referencing. … … 68 90 default_description = Option('screenshots', 'default_description', 69 91 '$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.') 70 95 71 96 # IWikiSyntaxProvider … … 81 106 def get_macros(self): 82 107 yield 'Screenshot' 108 yield 'ScreenshotsList' 83 109 84 110 def get_macro_description(self, name): 85 111 if name == 'Screenshot': 86 112 return self.screenshot_macro_doc 113 elif name == 'ScreenshotsList': 114 return self.screenshots_list_macro_doc 115 87 116 88 117 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 89 126 if name == 'Screenshot': 90 127 # Check permission. … … 92 129 return html.div('No permissions to see screenshots.', 93 130 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]101 131 102 132 #Â Get macro arguments. … … 167 197 title = content, class_ = 'missing') 168 198 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 169 220 # Internal functions 170 221 … … 217 268 description = description.replace('$height', to_unicode( 218 269 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'])) 219 276 return wiki_to_oneliner(description, self.env) 220 277
