Changeset 3114
- Timestamp:
- 01/20/08 18:40:11 (1 year ago)
- Files:
-
- downloadsplugin/0.11/tracdownloads/api.py (modified) (8 diffs)
- downloadsplugin/0.11/tracdownloads/core.py (modified) (1 diff)
- downloadsplugin/0.11/tracdownloads/tags.py (modified) (2 diffs)
- downloadsplugin/0.11/tracdownloads/timeline.py (modified) (2 diffs)
- downloadsplugin/0.11/tracdownloads/wiki.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
downloadsplugin/0.11/tracdownloads/api.py
r3113 r3114 5 5 6 6 from trac.core import * 7 from trac.config import Option 7 from trac.config import Option, BoolOption 8 8 from trac.web.chrome import add_stylesheet, add_script 9 9 from trac.wiki.formatter import format_to_html, format_to_oneliner … … 50 50 ' '.join(all_fields), 'List of downloads table fields that should' 51 51 ' be visible to users on Downloads section.') 52 unique_filename = BoolOption('downloads', 'unique_filename', False, 53 'If enabled checks if uploaded file has unique name.') 52 54 53 55 # Get list functions. … … 121 123 "WHERE time BETWEEN %s AND %s" 122 124 self.log.debug(sql % (start, stop)) 123 context.cursor.execute(sql, ( start, stop))125 context.cursor.execute(sql, (to_timestamp(start), to_timestamp(stop))) 124 126 downloads = [] 125 127 for row in context.cursor: … … 210 212 return row 211 213 214 def get_download_by_file(self, context, file): 215 columns = ('id', 'file', 'description', 'size', 'time', 'count', 216 'author', 'tags', 'component', 'version', 'architecture', 'platform', 217 'type') 218 sql = "SELECT id, file, description, size, time, count, author, tags," \ 219 " component, version, architecture, platform, type FROM download" \ 220 " WHERE file = %s" 221 self.log.debug(sql % (file,)) 222 context.cursor.execute(sql, (file,)) 223 for row in context.cursor: 224 row = dict(zip(columns, row)) 225 row['count'] = row['count'] or 0 226 return row 227 212 228 def get_architecture(self, context, id): 213 229 columns = ('id', 'name', 'description') … … 277 293 278 294 def edit_download(self, context, id, download): 279 self._edit_item(contex , 'download', id, download)295 self._edit_item(context, 'download', id, download) 280 296 281 297 def edit_architecture(self, context, id, architecture): … … 422 438 # Get form values. 423 439 download_id = context.req.args.get('id') or 0 440 download_file = context.req.args.get('file') 424 441 425 442 # Get download. 426 download = self.get_download(context, download_id) 443 if download_id: 444 download = self.get_download(context, download_id) 445 else: 446 download = self.get_download_by_file(context, download_file) 427 447 428 448 if download: … … 518 538 'platform' : context.req.args.get('platform'), 519 539 'type' : context.req.args.get('type')} 540 541 # Check for file name uniqueness. 542 if self.unique_filename: 543 if self.get_download_by_file(context, filename): 544 raise TracError('File with same name is already' \ 545 ' uploaded and unique file names are enabled.') 520 546 521 547 # Add new download. … … 770 796 if not hasattr(file, 'filename') or not file.filename: 771 797 raise TracError('No file uploaded.') 798 799 # Get file size. 772 800 if hasattr(file.file, 'fileno'): 773 801 size = os.fstat(file.file.fileno())[6] downloadsplugin/0.11/tracdownloads/core.py
r2999 r3114 60 60 req.args['id'] = match.group(1) 61 61 return True 62 match = re.match(r'''^/downloads/([^/]+)$''', req.path_info) 63 if match: 64 req.args['action'] = 'get-file' 65 req.args['file'] = match.group(1) 66 return True 62 67 return False 63 68 downloadsplugin/0.11/tracdownloads/tags.py
r2999 r3114 4 4 5 5 from trac.core import * 6 from trac.mimeview import * 6 7 from trac.util.html import html 7 8 … … 105 106 106 107 def _resolve_ids(self, download): 107 108 # Get database access.108 # Create context. 109 context = Context('downloads-core') 109 110 db = self.env.get_db_cnx() 110 c ursor = db.cursor()111 context.cursor = db.cursor() 111 112 112 113 # Resolve architecture platform and type names. 113 114 api = self.env[DownloadsApi] 114 architecture = api.get_architecture(c ursor, download['architecture'])115 platform = api.get_platform(c ursor, download['platform'])116 type = api.get_type(c ursor, download['type'])115 architecture = api.get_architecture(context, download['architecture']) 116 platform = api.get_platform(context, download['platform']) 117 type = api.get_type(context, download['type']) 117 118 self.log.debug(architecture) 118 119 download['architecture'] = architecture['name'] downloadsplugin/0.11/tracdownloads/timeline.py
r2999 r3114 3 3 import time 4 4 5 from genshi.builder import tag 6 5 7 from trac.core import * 8 from trac.mimeview import * 6 9 from trac.wiki import wiki_to_html, wiki_to_oneliner 7 from trac.util import Markup10 from trac.util.text import pretty_size 8 11 9 from trac. Timeline import ITimelineEventProvider12 from trac.timeline import ITimelineEventProvider 10 13 11 14 from tracdownloads.api import * … … 20 23 # ITimelineEventProvider 21 24 25 def get_timeline_filters(self, req): 26 if 'DOWNLOADS_VIEW' in req.perm: 27 yield ('downloads', 'Downloads changes') 28 22 29 def get_timeline_events(self, req, start, stop, filters): 23 30 self.log.debug("start: %s, stop: %s, filters: %s" % (start, stop, 24 31 filters)) 25 if 'downloads' in filters: 26 # Create database context 32 if ('downloads' in filters) and ('DOWNLOADS_VIEW' in req.perm): 33 # Create context. 34 context = Context.from_request(req)('downloads-timeline') 27 35 db = self.env.get_db_cnx() 28 c ursor = db.cursor()36 context.cursor = db.cursor() 29 37 30 38 #Â Get API component. 31 39 api = self.env[DownloadsApi] 32 40 33 format = req.args.get('format') 34 self.log.debug("format: %s" % (format)) 41 self.log.debug(api.get_new_downloads(context, start, stop)) 35 42 36 43 # Get message events 37 for download in api.get_new_downloads(req, cursor, start, stop): 38 kind = 'newticket' 44 for download in api.get_new_downloads(context, start, stop): 45 yield ('newticket', download['time'], download['author'], 46 (download['id'], download['file'], download['description'], 47 download['size'])) 39 48 40 title = Markup("New download <em>%s</em> created by %s" % 41 (download['file'], download['author'])) 42 time = download['time'] 43 author = download['author'] 49 def render_timeline_event(self, context, field, event): 50 # Decompose event data. 51 id, name, description, size = event[3] 44 52 45 if format == 'rss': 46 href = req.abs_href.downloads(download['id']) 47 message = wiki_to_html(download['description'], self.env, 48 req) 49 else: 50 href = req.href.downloads(download['id']) 51 message = wiki_to_oneliner(download['description'], self.env) 52 53 yield kind, href, title, time, author, message 54 55 def get_timeline_filters(self, req): 56 if req.perm.has_permission('DOWNLOADS_VIEW'): 57 yield ('downloads', 'Downloads changes') 53 # Return apropriate content. 54 if field == 'url': 55 return context.req.href.downloads(id) 56 elif field == 'title': 57 return tag('New download ', tag.em(name), ' created') 58 elif field == 'description': 59 return tag('(%s) %s' % (pretty_size(size), description)) downloadsplugin/0.11/tracdownloads/wiki.py
r2999 r3114 2 2 3 3 from trac.core import * 4 from trac.mimeview import Context 4 5 from trac.util.html import html 5 6 … … 26 27 if ns == 'download': 27 28 if formatter.req.perm.has_permission('DOWNLOADS_VIEW'): 28 # Get cursor. 29 # Create context. 30 context = Context.from_request(formatter.req)('downloads-wiki') 29 31 db = self.env.get_db_cnx() 30 c ursor = db.cursor()32 context.cursor = db.cursor() 31 33 32 34 # Get API component. … … 34 36 35 37 # Get download. 36 download = api.get_download(cursor, params) 38 if re.match(r'\d+', params): 39 download = api.get_download(context, params) 40 else: 41 download = api.get_download_by_file(context, params) 37 42 38 43 if download: 39 44 # Return link to existing file. 40 45 return html.a(label, href = formatter.href.downloads(params), 41 title = download['file']) 46 title = '%s (%s)' % (download['file'], 47 pretty_size(download['size']))) 42 48 else: 43 49 # Return link to non-existing file.
