Changeset 4304
- Timestamp:
- 09/20/08 14:40:02 (2 months ago)
- Files:
-
- screenshotsplugin/0.11/tracscreenshots/api.py (modified) (1 diff)
- screenshotsplugin/0.11/tracscreenshots/wiki.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
screenshotsplugin/0.11/tracscreenshots/api.py
r4195 r4304 68 68 return self._get_items(context, 'screenshot', ('id', 'name', 69 69 '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 70 79 71 80 def get_filtered_screenshots(self, context, components, versions): screenshotsplugin/0.11/tracscreenshots/wiki.py
r3465 r4304 15 15 16 16 class ScreenshotsWiki(Component): 17 """ 18 The wiki module implements macro for screenshots referencing. 19 """ 20 implements(IWikiSyntaxProvider, IWikiMacroProvider) 17 21 18 22 screenshot_macro_doc = """Allows embed screenshot image in wiki page. … … 45 49 * {{{$width}}} - Original width of image. 46 50 * {{{$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. 47 54 48 55 Example: … … 52 59 }}}""" 53 60 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 62 on wiki page. Accepts one argument which is template for list items fromatting. 63 Possible 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 77 Example: 78 79 {{{ 80 [[ScreenshotsList($name - $description ($widthx$height))]] 81 }}}""" 58 82 59 83 # [screenshot] macro id regular expression. … … 67 91 default_description = Option('screenshots', 'default_description', 68 92 '$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.') 69 96 70 97 # IWikiSyntaxProvider … … 80 107 def get_macros(self): 81 108 yield 'Screenshot' 109 yield 'ScreenshotsList' 82 110 83 111 def get_macro_description(self, name): 84 112 if name == 'Screenshot': 85 113 return self.screenshot_macro_doc 114 elif name == 'ScreenshotsList': 115 return self.screenshots_list_macro_doc 86 116 87 117 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 88 129 if name == 'Screenshot': 89 130 # Check permission. … … 91 132 return html.div('No permissions to see screenshots.', 92 133 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]103 134 104 135 #Â Get macro arguments. … … 170 201 class_ = 'missing') 171 202 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 172 224 # Internal functions 173 225 … … 220 272 description = description.replace('$height', to_unicode( 221 273 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 222 281 self.log.debug(description) 223 282 return format_to_oneliner(self.env, context, description)
