Changeset 4307

Show
Ignore:
Timestamp:
09/20/08 15:45:02 (2 months ago)
Author:
Blackhex
Message:

ScreenshotsPlugin:

Files:

Legend:

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

    r4192 r4307  
    1010from trac.util import format_datetime, pretty_timedelta, TracError 
    1111from trac.util.html import html 
     12from trac.util.text import to_unicode 
    1213 
    1314from trac.web.main import IRequestHandler 
     
    341342                old_screenshot = api.get_screenshot(cursor, screenshot_id) 
    342343 
    343                 if old_screenshot: 
    344                     # Construct screenshot dictionary from form values. 
    345                     screenshot = {'name' :  req.args.get('name'), 
    346                                   'description' : req.args.get('description'), 
    347                                   'author' : req.authname, 
    348                                   'tags' : req.args.get('tags'), 
    349                                   'components' : req.args.get('components') or [], 
    350                                   'versions' : req.args.get('versions') or []} 
    351  
    352                     # Converst components and versions to list if only one item is 
    353                     # selected. 
    354                     if not isinstance(screenshot['components'], list): 
    355                          screenshot['components'] = [screenshot['components']] 
    356                     if not isinstance(screenshot['versions'], list): 
    357                          screenshot['versions'] = [screenshot['versions']] 
    358  
    359                     # Edit screenshot. 
    360                     api.edit_screenshot(cursor, screenshot_id, screenshot) 
    361  
    362                     # Notify change listeners. 
    363                     for listener in self.change_listeners: 
    364                         listener.screenshot_changed(screenshot, old_screenshot) 
    365  
    366                     # Clear id to prevent display of edit and delete button. 
    367                     req.args['id'] = None 
    368  
    369                 else: 
     344                # Check if requested screenshot exits. 
     345                if not old_screenshot: 
    370346                    raise TracError('Edited screenshot not found.', 
    371347                      'Screenshot not found.') 
    372348 
     349                # Construct screenshot dictionary from form values. 
     350                screenshot = {'name' :  req.args.get('name'), 
     351                              'description' : req.args.get('description'), 
     352                              'author' : req.authname, 
     353                              'tags' : req.args.get('tags'), 
     354                              'components' : req.args.get('components') or [], 
     355                              'versions' : req.args.get('versions') or []} 
     356 
     357                # Converst components and versions to list if only one item is 
     358                # selected. 
     359                if not isinstance(screenshot['components'], list): 
     360                     screenshot['components'] = [screenshot['components']] 
     361                if not isinstance(screenshot['versions'], list): 
     362                     screenshot['versions'] = [screenshot['versions']] 
     363 
     364                # Edit screenshot. 
     365                api.edit_screenshot(cursor, screenshot_id, screenshot) 
     366 
     367                # Notify change listeners. 
     368                for listener in self.change_listeners: 
     369                    listener.screenshot_changed(screenshot, old_screenshot) 
     370 
     371                # Clear id to prevent display of edit and delete button. 
     372                req.args['id'] = None 
     373 
    373374            elif action == 'delete': 
    374375                req.perm.assert_permission('SCREENSHOTS_ADMIN') 
     
    377378                screenshot = api.get_screenshot(cursor, req.args.get('id')) 
    378379 
     380                # Check if requested screenshot exits. 
     381                if not screenshot: 
     382                    raise TracError('Deleted screenshot not found.', 
     383                      'Screenshot not found.') 
     384 
     385                # Delete screenshot. 
     386                api.delete_screenshot(cursor, screenshot['id']) 
     387 
     388                # Delete screenshot files. Don't append any other files there :-). 
    379389                try: 
    380                     # Delete screenshot. 
    381                     api.delete_screenshot(cursor, screenshot['id']) 
    382  
    383                     # Delete screenshot files. Don't append any other files there :-). 
    384390                    path = os.path.join(self.path, to_unicode(screenshot['id'])) 
    385391                    path = os.path.normpath(path) 
  • screenshotsplugin/0.11/tracscreenshots/core.py

    r4278 r4307  
    361361                old_screenshot = api.get_screenshot(context, screenshot_id) 
    362362 
    363                 if old_screenshot: 
    364                     # Construct screenshot dictionary from form values. 
    365                     screenshot = {'name' :  context.req.args.get('name'), 
    366                                   'description' : context.req.args.get( 
    367                                     'description'), 
    368                                   'author' : context.req.authname, 
    369                                   'tags' : context.req.args.get('tags'), 
    370                                   'components' : context.req.args.get( 
    371                                     'components') or [], 
    372                                   'versions' : context.req.args.get('versions') or []} 
    373  
    374                     # Convert components and versions to list if only one item is 
    375                     # selected. 
    376                     if not isinstance(screenshot['components'], list): 
    377                          screenshot['components'] = [screenshot['components']] 
    378                     if not isinstance(screenshot['versions'], list): 
    379                          screenshot['versions'] = [screenshot['versions']] 
    380  
    381                     self.log.debug(screenshot) 
    382  
    383                     # Edit screenshot. 
    384                     api.edit_screenshot(context, screenshot_id, screenshot) 
    385  
    386  
    387                     # Notify change listeners. 
    388                     for listener in self.change_listeners: 
    389                         listener.screenshot_changed(context.req, screenshot, 
    390                           old_screenshot) 
    391  
    392                     # Clear id to prevent display of edit and delete button. 
    393                     context.req.args['id'] = None 
    394  
    395                 else: 
     363                # Check if requested screenshot exits. 
     364                if not old_screenshot: 
    396365                    raise TracError('Edited screenshot not found.', 
    397366                      'Screenshot not found.') 
    398367 
     368                # Construct screenshot dictionary from form values. 
     369                screenshot = {'name' :  context.req.args.get('name'), 
     370                              'description' : context.req.args.get( 
     371                                'description'), 
     372                              'author' : context.req.authname, 
     373                              'tags' : context.req.args.get('tags'), 
     374                              'components' : context.req.args.get( 
     375                                'components') or [], 
     376                              'versions' : context.req.args.get('versions') or []} 
     377 
     378                # Convert components and versions to list if only one item is 
     379                # selected. 
     380                if not isinstance(screenshot['components'], list): 
     381                     screenshot['components'] = [screenshot['components']] 
     382                if not isinstance(screenshot['versions'], list): 
     383                     screenshot['versions'] = [screenshot['versions']] 
     384 
     385                # Edit screenshot. 
     386                api.edit_screenshot(context, screenshot_id, screenshot) 
     387 
     388 
     389                # Notify change listeners. 
     390                for listener in self.change_listeners: 
     391                    listener.screenshot_changed(context.req, screenshot, 
     392                      old_screenshot) 
     393 
     394                # Clear id to prevent display of edit and delete button. 
     395                context.req.args['id'] = None 
     396 
    399397            elif action == 'delete': 
    400398                context.req.perm.assert_permission('SCREENSHOTS_ADMIN') 
     
    406404                screenshot = api.get_screenshot(context, screenshot_id) 
    407405 
     406                # Check if requested screenshot exits. 
     407                if not screenshot: 
     408                    raise TracError('Deleted screenshot not found.', 
     409                      'Screenshot not found.') 
    408410                try: 
    409411                    # Delete screenshot.