Django

Code

Changeset 4857

Show
Ignore:
Timestamp:
03/29/07 20:50:06 (2 years ago)
Author:
adrian
Message:

Fixed #3799 -- Added django.contrib.webdesign and moved 'lorem' template tag into there

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/defaulttags.py

    r4848 r4857  
    141141                compare_to = self.nodelist.render(context) 
    142142        except VariableDoesNotExist: 
    143             compare_to = None         
     143            compare_to = None 
    144144 
    145145        if  compare_to != self._last_seen: 
     
    281281        return '' 
    282282 
    283 class LoremNode(Node): 
    284     def __init__(self, count, method, common): 
    285         self.count, self.method, self.common = count, method, common 
    286  
    287     def render(self, context): 
    288         from django.utils.lorem_ipsum import words, paragraphs 
    289         try: 
    290             count = int(self.count.resolve(context)) 
    291         except (ValueError, TypeError): 
    292             count = 1 
    293         if self.method == 'w': 
    294             return words(count, common=self.common) 
    295         else: 
    296             paras = paragraphs(count, common=self.common) 
    297         if self.method == 'p': 
    298             paras = ['<p>%s</p>' % p for p in paras] 
    299         return '\n\n'.join(paras) 
    300  
    301283class NowNode(Node): 
    302284    def __init__(self, format_string): 
     
    339321        self.args = args 
    340322        self.kwargs = kwargs 
    341        
     323 
    342324    def render(self, context): 
    343325        from django.core.urlresolvers import reverse, NoReverseMatch 
     
    788770 
    789771#@register.tag 
    790 def lorem(parser, token): 
    791     """ 
    792     Creates random latin text useful for providing test data in templates. 
    793  
    794     Usage format:: 
    795  
    796         {% lorem [count] [method] [random] %} 
    797  
    798     ``count`` is a number (or variable) containing the number of paragraphs or 
    799     words to generate (default is 1). 
    800  
    801     ``method`` is either ``w`` for words, ``p`` for HTML paragraphs, ``b`` for 
    802     plain-text paragraph blocks (default is ``b``). 
    803  
    804     ``random`` is the word ``random``, which if given, does not use the common 
    805     paragraph (starting "Lorem ipsum dolor sit amet, consectetuer..."). 
    806  
    807     Examples: 
    808         * ``{% lorem %}`` will output the common "lorem ipsum" paragraph 
    809         * ``{% lorem 3 p %}`` will output the common "lorem ipsum" paragraph 
    810           and two random paragraphs each wrapped in HTML ``<p>`` tags 
    811         * ``{% lorem 2 w random %}`` will output two random latin words 
    812     """ 
    813     bits = list(token.split_contents()) 
    814     tagname = bits[0] 
    815     # Random bit 
    816     common = bits[-1] != 'random' 
    817     if not common: 
    818         bits.pop() 
    819     # Method bit 
    820     if bits[-1] in ('w', 'p', 'b'): 
    821         method = bits.pop() 
    822     else: 
    823         method = 'b' 
    824     # Count bit 
    825     if len(bits) > 1: 
    826         count = bits.pop() 
    827     else: 
    828         count = '1' 
    829     count = parser.compile_filter(count) 
    830     if len(bits) != 1: 
    831         raise TemplateSyntaxError, "Incorrect format for %r tag" % tagname 
    832     return LoremNode(count, method, common) 
    833 lorem = register.tag(lorem)     
    834  
    835 #@register.tag 
    836772def now(parser, token): 
    837773    """ 
     
    981917def url(parser, token): 
    982918    """ 
    983     Returns an absolute URL matching given view with its parameters.  
    984      
     919    Returns an absolute URL matching given view with its parameters. 
     920 
    985921    This is a way to define links that aren't tied to a particular URL configuration:: 
    986      
     922 
    987923        {% url path.to.some_view arg1,arg2,name1=value1 %} 
    988      
     924 
    989925    The first argument is a path to a view. It can be an absolute python path 
    990926    or just ``app_name.view_name`` without the project name if the view is 
     
    995931    For example if you have a view ``app_name.client`` taking client's id and 
    996932    the corresponding line in a URLconf looks like this:: 
    997      
     933 
    998934        ('^client/(\d+)/$', 'app_name.client') 
    999      
     935 
    1000936    and this app's URLconf is included into the project's URLconf under some 
    1001937    path:: 
    1002      
     938 
    1003939        ('^clients/', include('project_name.app_name.urls')) 
    1004      
     940 
    1005941    then in a template you can create a link for a certain client like this:: 
    1006      
     942 
    1007943        {% url app_name.client client.id %} 
    1008      
     944 
    1009945    The URL will look like ``/clients/client/123/``. 
    1010946    """ 
  • django/trunk/docs/templates.txt

    r4848 r4857  
    625625 
    626626See `Custom tag and filter libraries`_ for more information. 
    627  
    628 lorem 
    629 ~~~~~ 
    630  
    631 Display random latin text useful for providing sample data in templates. 
    632  
    633 Usage format: ``{% lorem [count] [method] [random] %}`` 
    634  
    635     ===========  ============================================================= 
    636     Argument     Description 
    637     ===========  ============================================================= 
    638     ``count``    A number (or variable) containing the number of paragraphs or 
    639                  words to generate (default is 1). 
    640     ``method``   Either ``w`` for words, ``p`` for HTML paragraphs or ``b`` 
    641                  for plain-text paragraph blocks (default is ``b``). 
    642     ``random``   The word ``random``, which if given, does not use the common 
    643                  paragraph ("Lorem ipsum dolor sit amet...") when generating 
    644                  text. 
    645  
    646 Examples: 
    647  
    648     * ``{% lorem %}`` will output the common "lorem ipsum" paragraph. 
    649     * ``{% lorem 3 p %}`` will output the common "lorem ipsum" paragraph 
    650       and two random paragraphs each wrapped in HTML ``<p>`` tags. 
    651     * ``{% lorem 2 w random %}`` will output two random latin words. 
    652627 
    653628now 
  • django/trunk/tests/regressiontests/templates/tests.py

    r4847 r4857  
    150150            # Dictionary lookup wins out when there is a string and int version of the key. 
    151151            'list-index07': ("{{ var.1 }}", {"var": {'1': "hello", 1: "world"}}, "hello"), 
    152              
     152 
    153153            # Basic filter usage 
    154154            'basic-syntax21': ("{{ var|upper }}", {"var": "Django is the greatest!"}, "DJANGO IS THE GREATEST!"), 
     
    655655            'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')), 
    656656 
    657             ### LOREM TAG ###################################################### 
    658             'lorem01': ('{% lorem %}', {}, 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'), 
    659             'lorem02': ('{% lorem p %}', {}, '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>'), 
    660             'lorem03': ('{% lorem 6 w %}', {}, 'lorem ipsum dolor sit amet consectetur'), 
    661  
    662657            ### NOW TAG ######################################################## 
    663658            # Simple case