Changeset 3271

Show
Ignore:
Timestamp:
02/24/08 20:18:30 (9 months ago)
Author:
Blackhex
Message:
  • Main navigation bar button can be disabled and meta navigation bar link can be added now.
  • Bug #2621 fix.
  • Additional tags field is now hidden when tags are not available.
Files:

Legend:

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

    r3161 r3271  
    11# -*- coding: utf8 -*- 
    22 
    3 import sets, re, os, os.path, time, mimetypes, unicodedata, Image 
     3import sets, re, os, os.path, shutil, time, mimetypes, unicodedata, Image 
    44 
    55from trac.core import * 
     
    4040 
    4141    # Configuration options. 
    42     title = Option('screenshots', 'title', 'Screenshots', 
     42    mainnav_title = Option('screenshots', 'mainnav_title', 'Screenshots', 
    4343      'Main navigation bar button title.') 
     44    metanav_title = Option('screenshots', 'metanav_title', '', 
     45      'Meta navigation bar link title.') 
    4446    path = Option('screenshots', 'path', '/var/lib/trac/screenshots', 
    4547      'Path where to store uploaded screenshots.') 
     
    7880    def get_navigation_items(self, req): 
    7981        if req.perm.has_permission('SCREENSHOTS_VIEW'): 
    80             yield 'mainnav', 'screenshots', html.a(self.title, 
    81               href = req.href.screenshots()) 
     82            if self.mainnav_title: 
     83                yield 'mainnav', 'screenshots', html.a(self.mainnav_title, 
     84                  href = req.href.screenshots()) 
     85            if self.metanav_title: 
     86                yield 'metanav', 'screenshots', html.a(self.metanav_title, 
     87                  href = req.href.screenshots()) 
    8288 
    8389    # IRequestHandler methods. 
     
    107113        req.hdf['screenshots'] = data 
    108114        req.hdf['screenshots.href'] = req.href.screenshots() 
    109         req.hdf['screenshots.title'] = self.title 
     115        req.hdf['screenshots.title'] = self.mainnav_title or self.metanav_title 
     116        req.hdf['screenshots.has_tags'] = self.env.is_component_enabled( 
     117          'tracscreenshots.tags.ScreenshotsTags') 
     118        #req.hdf['screenshots.has_tags'] = self.config.get('components', 
     119        #  'tracscreenshots.tags.screenshotstags') == 'enabled' 
    110120        return template, content_type 
    111121 
     
    241251                api.add_screenshot(cursor, screenshot) 
    242252 
    243  
    244253                # Get inserted screenshot to with new id. 
    245254                screenshot = api.get_screenshot_by_time(cursor, 
     
    269278 
    270279                # Prepare file paths 
    271                 filename = os.path.join(self.path, unicode(screenshot['id']), 
    272                   '%s-%ix%i.%s' % (result.group(1), screenshot['width'], 
    273                   screenshot['height'], result.group(2))) 
    274                 filename = unicodedata.normalize('NFC', filename) 
    275                 filename = filename.replace('\\', '/').replace(':', '/') 
    276                 path = os.path.dirname(filename) 
    277                 self.log.debug('filename: %s' % (filename,)) 
    278                 self.log.debug('filename: %s' % (path,)) 
     280                path = os.path.join(self.path, unicode(screenshot['id'])) 
     281                filepath = os.path.join(path, '%s-%ix%i.%s' % (result.group(1), 
     282                  screenshot['width'], screenshot['height'], result.group(2))) 
     283                path = os.path.normpath(path) 
     284                filepath = os.path.normpath(filepath) 
     285                self.log.debug('path: %s' % (path,)) 
     286                self.log.debug('filepath: %s' % (filepath,)) 
    279287 
    280288                # Store uploaded image. 
    281289                try: 
    282290                    os.mkdir(path) 
    283                     image.save(filename) 
    284                 except:  
     291                    out_file = open(filepath, 'wb+') 
     292                    file.seek(0) 
     293                    shutil.copyfileobj(file, out_file) 
     294                    out_file.close() 
     295                except Exception, error: 
    285296                    api.delete_screenshot(cursor, screenshot['id']) 
     297                    try: 
     298                       self.log.debug(error) 
     299                    except: 
     300                       pass 
    286301                    try: 
    287302                        os.remove(filename) 
     
    294309                    raise TracError('Error storing file. Is directory' \ 
    295310                      ' specified in path config option in [screenshots]' \ 
    296                       ' section of trac.ini existing?') 
     311                      ' section of trac.ini existing? Original message was: %s' \ 
     312                      % (error,)) 
    297313 
    298314                # Notify change listeners. 
  • screenshotsplugin/0.10/tracscreenshots/tags.py

    r2659 r3271  
    55from tracscreenshots.api import * 
    66from trac.core import * 
     7 
    78from tractags.api import ITaggingSystemProvider, DefaultTaggingSystem, \ 
    89  TagEngine 
  • screenshotsplugin/0.10/tracscreenshots/templates/screenshot-add.cs

    r2644 r3271  
    4040        </div> 
    4141      <?cs /if ?> 
    42       <div class="field"> 
    43         <label for="tags">Additional tags:</label><br/> 
    44         <?cs if:args.action == 'add' ?> 
    45           <input type="text" id="tags" name="tags" value=""/><br/> 
    46         <?cs else ?> 
    47           <input type="text" id="tags" name="tags" value="<?cs var:screenshots.screenshot.tags ?>"/><br/> 
    48         <?cs /if ?> 
    49       </div> 
     42      <?cs if:screenshots.has_tags ?> 
     43        <div class="field"> 
     44          <label for="tags">Additional tags:</label><br/> 
     45          <?cs if:args.action == 'add' ?> 
     46            <input type="text" id="tags" name="tags" value=""/><br/> 
     47          <?cs else ?> 
     48            <input type="text" id="tags" name="tags" value="<?cs var:screenshots.screenshot.tags ?>"/><br/> 
     49          <?cs /if ?> 
     50        </div> 
     51      <?cs /if ?> 
    5052      <div class="field"> 
    5153        <label for="components">Components:</label><br/> 
  • screenshotsplugin/0.11/tracscreenshots/core.py

    r3141 r3271  
    11# -*- coding: utf8 -*- 
    22 
    3 import sets, re, os, os.path, mimetypes, unicodedata, Image 
     3import sets, re, os, os.path, shutil, mimetypes, unicodedata, Image 
    44from datetime import * 
    55 
     
    4141 
    4242    # Configuration options. 
    43     title = Option('screenshots', 'title', 'Screenshots', 
     43    mainnav_title = Option('screenshots', 'mainnav_title', 'Screenshots', 
    4444      'Main navigation bar button title.') 
     45    metanav_title = Option('screenshots', 'metanav_title', '', 
     46      'Meta navigation bar link title.') 
    4547    path = Option('screenshots', 'path', '/var/lib/trac/screenshots', 
    4648      'Path where to store uploaded screenshots.') 
     
    7981    def get_navigation_items(self, req): 
    8082        if req.perm.has_permission('SCREENSHOTS_VIEW'): 
    81             yield 'mainnav', 'screenshots', html.a(self.title, 
    82               href = req.href.screenshots()) 
     83            if self.mainnav_title: 
     84                yield 'mainnav', 'screenshots', html.a(self.mainnav_title, 
     85                  href = req.href.screenshots()) 
     86            if self.metanav_title: 
     87                yield 'metanav', 'screenshots', html.a(self.metanav_title, 
     88                  href = req.href.screenshots()) 
    8389 
    8490    # IRequestHandler methods. 
     
    107113 
    108114        # Prepare data structure. 
    109         self.data['title'] = self.title 
     115        self.data['title'] = self.mainnav_title or self.metanav_title 
     116        self.data['has_tags'] = self.env.is_component_enabled( 
     117          'tracscreenshots.tags.ScreenshotsTags') 
    110118 
    111119        # Get action from request and perform them. 
     
    117125        add_stylesheet(req, 'screenshots/css/screenshots.css') 
    118126        add_script(req, 'screenshots/js/screenshots.js') 
    119  
    120         # Prepare HDF structure. 
    121         req.hdf['screenshots'] = self.data 
    122127 
    123128        # Return template and its data. 
     
    263268                api.add_screenshot(context, screenshot) 
    264269 
    265  
    266270                # Get inserted screenshot to with new id. 
    267271                screenshot = api.get_screenshot_by_time(context, 
     
    291295 
    292296                # Prepare file paths 
    293                 filename = os.path.join(self.path, to_unicode(screenshot['id']), 
    294                   '%s-%ix%i.%s' % (result.group(1), screenshot['width'], 
    295                   screenshot['height'], result.group(2))) 
    296                 filename = unicodedata.normalize('NFC', filename) 
    297                 filename = filename.replace('\\', '/').replace(':', '/') 
    298                 path = os.path.dirname(filename) 
    299                 self.log.debug('filename: %s' % (filename,)) 
    300                 self.log.debug('filename: %s' % (path,)) 
     297                path = os.path.join(self.path, unicode(screenshot['id'])) 
     298                filepath = os.path.join(path, '%s-%ix%i.%s' % (result.group(1), 
     299                  screenshot['width'], screenshot['height'], result.group(2))) 
     300                path = os.path.normpath(path) 
     301                filepath = os.path.normpath(filepath) 
     302                self.log.debug('path: %s' % (path,)) 
     303                self.log.debug('filename: %s' % (filepath,)) 
    301304 
    302305                # Store uploaded image. 
    303306                try: 
    304307                    os.mkdir(path) 
    305                     image.save(filename) 
     308                    out_file = open(filepath, 'wb+')  
     309                    file.seek(0) 
     310                    shutil.copyfileobj(file, out_file) 
     311                    out_file.close() 
    306312                except Exception, error: 
    307313                    api.delete_screenshot(context, screenshot['id']) 
     
    320326                    raise TracError('Error storing file. Is directory' \ 
    321327                      ' specified in path config option in [screenshots]' \ 
    322                       ' section of trac.ini existing?') 
     328                      ' section of trac.ini existing? Original message was: %s' \ 
     329                      % (error,)) 
    323330 
    324331                # Notify change listeners. 
  • screenshotsplugin/0.11/tracscreenshots/templates/screenshot-add.html

    r3141 r3271  
    2929            <input type="file" id="image" name="image" value=""/><br/> 
    3030          </div> 
    31           <div class="field"> 
     31          <div py:if="screenshots.has_tags" class="field"> 
    3232            <label for="tags">Additional tags:</label><br/> 
    3333            <input type="text" id="tags" name="tags" value="${(req.args.action == 'edit') and screenshots.screenshot.tags or ''}"/><br/>