Changeset 4516

Show
Ignore:
Timestamp:
10/16/08 11:20:03 (3 months ago)
Author:
Blackhex
Message:

DownloadsPlugin:

  • Only half of work on TagsPlugin 0.6 port was done :-).
  • Potentially bug #3883 fix.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • downloadsplugin/0.11/tracdownloads/api.py

    r4196 r4516  
    1818    when downloads are created, modified, or deleted.""" 
    1919 
    20     def download_created(download): 
     20    def download_created(req, download): 
    2121        """Called when a download is created. Only argument `download` is 
    2222        a dictionary with download field values.""" 
    2323 
    24     def download_changed(download, old_download): 
     24    def download_changed(req, download, old_download): 
    2525        """Called when a download is modified. 
    2626        `old_download` is a dictionary containing the previous values of the 
    2727        fields and `download` is a dictionary with new values. """ 
    2828 
    29     def download_deleted(download): 
     29    def download_deleted(req, download): 
    3030        """Called when a download is deleted. `download` argument is 
    3131        a dictionary with values of fields of just deleted download.""" 
     
    460460                    # Notify change listeners. 
    461461                    for listener in self.change_listeners: 
    462                         listener.download_changed(new_download, download) 
     462                        listener.download_changed(context.req, new_download, 
     463                          download) 
    463464 
    464465                    # Commit DB before file send. 
     
    576577                # Notify change listeners. 
    577578                for listener in self.change_listeners: 
    578                     listener.download_created(download) 
     579                    listener.download_created(context.req, download) 
    579580 
    580581                # Store uploaded image. 
     
    618619                # Notify change listeners. 
    619620                for listener in self.change_listeners: 
    620                     listener.download_changed(download, old_download) 
     621                    listener.download_changed(context.req, download, 
     622                      old_download) 
    621623 
    622624            elif mode == 'downloads-delete': 
     
    646648                            # Notify change listeners. 
    647649                            for listener in self.change_listeners: 
    648                                 listener.download_deleted(download) 
     650                                listener.download_deleted(context.req, download) 
    649651                        except: 
    650652                            pass 
     
    809811            size = os.fstat(file.file.fileno())[6] 
    810812        else: 
    811             file.file.seek(0, 2) 
    812             size = file.file.tell() 
    813             file.file.seek(0) 
     813            size = file.file.len 
    814814        if size == 0: 
    815815            raise TracError('Can\'t upload empty file.') 
    816816 
    817817        # Strip path from filename. 
    818         filename = os.path.basename(file.filename) 
    819  
    820         return file.file, unicode_unquote(filename), size 
     818        filename = os.path.basename(file.filename).decode('utf-8') 
     819 
     820        return file.file, filename, size 
  • downloadsplugin/0.11/tracdownloads/tags.py

    r4515 r4516  
    66from trac.core import * 
    77from trac.resource import * 
     8from trac.mimeview import Context 
    89 
    910from tractags.api import DefaultTagProvider, TagSystem 
     
    3233    # IDownloadChangeListener methods. 
    3334 
    34     def download_created(self, download): 
     35    def download_created(self, req, download): 
    3536        # Create temporary resource. 
    3637        resource = Resource() 
     
    4647        tag_system.add_tags(req, resource, new_tags) 
    4748 
    48     def download_changed(self, download, old_download): 
     49    def download_changed(self, req, download, old_download): 
    4950        # Update old download with new values. 
    5051        old_download.update(download) 
     
    6364        tag_system.add_tags(req, resource, new_tags) 
    6465 
    65     def download_deleted(self, download): 
     66    def download_deleted(self, req, download): 
    6667        # Create temporary resource. 
    6768        resource = Resource() 
     
    8182        # Prepare tag names. 
    8283        tags = [download['author']] 
    83         if download['components']: 
    84             tags += [component for component in download['components']] 
    85         if download['versions']: 
    86             tags += [version for version in download['versions']] 
     84        if download['component']: 
     85            tags += [download['component']] 
     86        if download['version']: 
     87            tags += [download['version']] 
    8788        if download['architecture']: 
    88             tags += download['architecture'
     89            tags += [download['architecture']
    8990        if download['platform']: 
    90             tags += download['platform'
     91            tags += [download['platform']
    9192        if download['type']: 
    92             tags += download['type'
     93            tags += [download['type']
    9394        if download['tags']: 
    9495            tags += download['tags'].split()