Changeset 1087

Show
Ignore:
Timestamp:
08/06/06 08:27:12 (2 years ago)
Author:
Blackhex
Message:

VisitCouterMacro:

  • Cookie 'expires' value was not setted.
  • Macro now can be used without argumets when current wiki page visit count is displayed.
  • Cookie name has changed from 'visited' to 'visited-pages' to prevent name collistion.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • visitcoutermacro/visitcounter/core.py

    r853 r1087  
    1212Macro displays how many times was wiki page displayed. 
    1313 
    14 This macro accepts from one to tree parameters. First parameter is wiki page 
    15 name which visit count you want to display. Other parameters are optional. 
    16 Second parameter determines if displaying of macro should update specified page 
    17 visit count. Accepted values of this parameter are: True, False, true, false, 
    18 1, 0. Default value is true. Third parameter specifies number of digits for 
    19 visit count display. If its value is 0 then visit count is displayed as simple 
    20 text. Default value is 4. 
     14This macro accepts up to tree parameters. First parameter is wiki page 
     15name which visit count you want to display. If no parameters specified 
     16current page visit count is displayed. Second parameter determines if 
     17displaying of macro should update specified page visit count. Accepted values 
     18of this parameter are: True, False, true, false, 1, 0. Default value is true. 
     19Third parameter specifies number of digits for visit count display. If its 
     20value is 0 then visit count is displayed as simple text. Default value is 4. 
    2121 
    2222Examples: 
     
    7575        if name == 'VisitCounter': 
    7676            # Get config values or its default values. 
    77             count_file = self.config.get('visitcounter', 'file') or \ 
    78               '/var/lib/trac/visits/visits.log' 
    7977            expires = int(self.config.get('visitcounter', 'expires') or 0) 
    8078 
     
    8785 
    8886            # Get macro arguments. 
    89             args = content.split(',') 
     87            if content: 
     88                args = content.split(',') 
     89            else: 
     90                args = [] 
    9091            argc = len(args) 
    9192            for I in xrange(argc): 
     
    9394 
    9495            # Check right arguments count. 
    95             if argc < 1: 
    96                 raise TracError('VisitCounter macro take minimaly 1 argument') 
    9796            if argc > 3: 
    9897                raise TracError('VisitCounter macro take at most 3 arguments') 
    9998 
    10099            # Get argument values 
    101             page = args[0] 
     100            if argc >=1: 
     101                page = args[0] 
     102            else: 
     103                page = req.path_info[6:] or 'WikiStart' 
    102104            if argc >= 2: 
    103105                update = args[1] in ('True', 'true', '1') 
     
    115117            if update: 
    116118                # Getting list of visited page 
    117                 if req.session.has_key('visited'): 
    118                     visited = req.session.get('visited').split('|') 
     119                if req.session.has_key('visited-pages'): 
     120                    visited = req.session.get('visited-pages').split('|') 
    119121                else: 
    120122                    visited = [] 
     
    127129                    # Update cookie. 
    128130                    visited.append(page) 
    129                     req.session['visited'] = '|'.join(visited) 
    130  
     131                    req.session['visited-pages'] = '|'.join(visited) 
     132                    req.session['visited-pages']['expires'] = expires 
    131133            # Set template values and return rendered macro 
    132134            db.commit()