Ticket #3036: 3036.diff
File 3036.diff, 5.3 KB (added by , 17 years ago) |
---|
-
django/core/serializers/__init__.py
3 3 4 4 Usage:: 5 5 6 >>>from django.core import serializers7 >>>json = serializers.serialize("json", some_query_set)8 >>>objects = list(serializers.deserialize("json", json))6 from django.core import serializers 7 json = serializers.serialize("json", some_query_set) 8 objects = list(serializers.deserialize("json", json)) 9 9 10 10 To add your own serializers, use the SERIALIZATION_MODULES setting:: 11 11 -
django/core/validators.py
410 410 >>> v(8, None) 411 411 >>> v(16, None) 412 412 >>> v(17, None) 413 django.core.validators.ValidationError: ['This value must be a power of 2.'] 413 Traceback (most recent call last): 414 File "doctest.py", line 1212, in __run 415 compileflags, 1) in test.globs 416 File "<doctest django.core.validators.IsAPowerOf[4]>", line 1, in <module> 417 v(17, None) 418 File "django/core/validators.py", line 424, in __call__ 419 ValidationError: [u'This value must be a power of 2.'] 414 420 """ 415 421 def __init__(self, power_of): 416 422 self.power_of = power_of -
django/utils/feedgenerator.py
3 3 4 4 Sample usage: 5 5 6 >>> from django.utils import feedgenerator 6 7 >>> feed = feedgenerator.Rss201rev2Feed( 7 8 ... title=u"Poynter E-Media Tidbits", 8 9 ... link=u"http://www.poynter.org/column.asp?id=31", -
django/utils/datastructures.py
238 238 may contain dots to specify inner dictionaries. It's confusing, but this 239 239 example should make sense. 240 240 241 >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 242 'person.1.lastname': ['Willison'],243 'person.2.firstname': ['Adrian'],244 'person.2.lastname': ['Holovaty']})245 >>> d 246 {'person': {'1': {'lastname': ['Willison'], 'firstname': ['Simon']},247 '2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}}248 >>> d['person']249 {'1': {'firstname': ['Simon'], 'lastname': ['Willison'],250 '2': {'firstname': ['Adrian'], 'lastname': ['Holovaty']}251 >>> d['person'][' 1']252 {'firstname': ['Simon'], 'lastname': ['Willison']}241 >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], \ 242 'person.1.lastname': ['Willison'], \ 243 'person.2.firstname': ['Adrian'], \ 244 'person.2.lastname': ['Holovaty']}) 245 >>> d['person']['1']['lastname'] 246 ['Willison'] 247 >>> d['person']['1']['firstname'] 248 ['Simon'] 249 >>> d['person']['2']['lastname'] 250 ['Holovaty'] 251 >>> d['person']['2']['firstname'] 252 ['Adrian'] 253 253 254 254 # Gotcha: Results are unpredictable if the dots are "uneven": 255 255 >>> DotExpandedDict({'c.1': 2, 'c.2': 3, 'c': 1}) 256 >>>{'c': 1}256 {'c': 1} 257 257 """ 258 258 def __init__(self, key_to_list_mapping): 259 259 for k, v in key_to_list_mapping.items(): -
django/template/__init__.py
34 34 35 35 Sample code: 36 36 37 >>> import template 38 >>> s = ''' 37 38 39 >>> from django import template 40 >>> s = u''' 39 41 ... <html> 40 42 ... {% if test %} 41 43 ... <h1>{{ varvalue }}</h1> … … 49 51 50 52 >>> c = template.Context({'test':True, 'varvalue': 'Hello'}) 51 53 >>> t.render(c) 52 '\n<html>\n\n <h1>Hello</h1>\n\n</html>\n'54 u'\\n<html>\\n\\n <h1>Hello</h1>\\n\\n</html>\\n' 53 55 >>> c = template.Context({'test':False, 'varvalue': 'Hello'}) 54 56 >>> t.render(c) 55 '\n<html>\n\n</html>\n'57 u'\\n<html>\\n\\n</html>\\n' 56 58 """ 57 59 import re 58 60 from inspect import getargspec … … 528 530 and return a list of tuples of the filter name and arguments. 529 531 Sample: 530 532 >>> token = 'variable|default:"Default value"|date:"Y-m-d"' 531 >>> p = FilterParser(token) 532 >>> p.filters 533 [('default', 'Default value'), ('date', 'Y-m-d')] 534 >>> p.var 533 >>> p = Parser('') 534 >>> fe = FilterExpression(token, p) 535 >>> len(fe.filters) 536 2 537 >>> fe.var 535 538 'variable' 536 537 This class should never be instantiated outside of the538 get_filters_from_token helper function.539 539 """ 540 540 def __init__(self, token, parser): 541 541 self.token = token … … 646 646 647 647 >>> c = {'article': {'section':'News'}} 648 648 >>> resolve_variable('article.section', c) 649 'News'649 u'News' 650 650 >>> resolve_variable('article', c) 651 651 {'section': 'News'} 652 652 >>> class AClass: pass … … 654 654 >>> c.article = AClass() 655 655 >>> c.article.section = 'News' 656 656 >>> resolve_variable('article.section', c) 657 'News'657 u'News' 658 658 659 659 (The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.') 660 660 """