Changeset 869
- Timestamp:
- 10/14/05 16:33:45 (3 years ago)
- Files:
-
- django/branches/i18n/django/conf/global_settings.py (modified) (1 diff)
- django/branches/i18n/django/conf/project_template/settings/main.py (modified) (1 diff)
- django/branches/i18n/django/core/db/backends/mysql.py (modified) (1 diff)
- django/branches/i18n/django/core/db/backends/postgresql.py (modified) (2 diffs)
- django/branches/i18n/django/core/defaultfilters.py (deleted)
- django/branches/i18n/django/core/defaulttags.py (deleted)
- django/branches/i18n/django/core/extensions.py (modified) (1 diff)
- django/branches/i18n/django/core/rss.py (modified) (5 diffs)
- django/branches/i18n/django/core/template (added)
- django/branches/i18n/django/core/template/defaultfilters.py (added)
- django/branches/i18n/django/core/template/defaulttags.py (added)
- django/branches/i18n/django/core/template_file.py (deleted)
- django/branches/i18n/django/core/template/__init__.py (added)
- django/branches/i18n/django/core/template_loader.py (modified) (1 diff)
- django/branches/i18n/django/core/template/loader.py (added)
- django/branches/i18n/django/core/template/loaders (added)
- django/branches/i18n/django/core/template/loaders/filesystem.py (added)
- django/branches/i18n/django/core/template/loaders/__init__.py (added)
- django/branches/i18n/django/core/template.py (deleted)
- django/branches/i18n/django/middleware/admin.py (modified) (2 diffs)
- django/branches/i18n/django/views/admin/doc.py (modified) (1 diff)
- django/branches/i18n/django/views/admin/template.py (modified) (3 diffs)
- django/branches/i18n/django/views/auth/login.py (modified) (1 diff)
- django/branches/i18n/django/views/defaults.py (modified) (3 diffs)
- django/branches/i18n/django/views/registration/passwords.py (modified) (2 diffs)
- django/branches/i18n/docs/design_philosophies.txt (added)
- django/branches/i18n/docs/forms.txt (modified) (6 diffs)
- django/branches/i18n/docs/sessions.txt (modified) (1 diff)
- django/branches/i18n/docs/templates_python.txt (modified) (3 diffs)
- django/branches/i18n/docs/templates.txt (modified) (9 diffs)
- django/branches/i18n/docs/tutorial03.txt (modified) (4 diffs)
- django/branches/i18n/docs/tutorial04.txt (modified) (1 diff)
- django/branches/i18n/tests/othertests/templates.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/i18n/django/conf/global_settings.py
r815 r869 60 60 DATABASE_USER = '' 61 61 DATABASE_PASSWORD = '' 62 DATABASE_HOST = '' # Set to empty string for localhost 62 DATABASE_HOST = '' # Set to empty string for localhost. 63 DATABASE_PORT = '' # Set to empty string for default. 63 64 64 65 # Host for sending e-mail. django/branches/i18n/django/conf/project_template/settings/main.py
r512 r869 16 16 DATABASE_PASSWORD = '' # Not used with sqlite3. 17 17 DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. 18 DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. 18 19 19 20 SITE_ID = 1 django/branches/i18n/django/core/db/backends/mysql.py
r853 r869 54 54 55 55 def cursor(self): 56 from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_P ASSWORD, DEBUG56 from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG 57 57 if self.connection is None: 58 self.connection = Database.connect(user=DATABASE_USER, db=DATABASE_NAME, 59 passwd=DATABASE_PASSWORD, host=DATABASE_HOST, conv=django_conversions) 58 kwargs = { 59 'user': DATABASE_USER, 60 'db': DATABASE_NAME, 61 'passwd': DATABASE_PASSWORD, 62 'host': DATABASE_HOST, 63 'conv': django_conversions, 64 } 65 if DATABASE_PORT: 66 kwargs['port'] = DATABASE_PORT 67 self.connection = Database.connect(**kwargs) 60 68 if DEBUG: 61 69 return base.CursorDebugWrapper(MysqlDebugWrapper(self.connection.cursor()), self) django/branches/i18n/django/core/db/backends/postgresql.py
r853 r869 16 16 17 17 def cursor(self): 18 from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_P ASSWORD, DEBUG, TIME_ZONE18 from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG, TIME_ZONE 19 19 if self.connection is None: 20 20 if DATABASE_NAME == '': … … 28 28 if DATABASE_HOST: 29 29 conn_string += " host=%s" % DATABASE_HOST 30 if DATABASE_PORT: 31 conn_string += " port=%s" % DATABASE_PORT 30 32 self.connection = Database.connect(conn_string) 31 33 self.connection.set_isolation_level(1) # make transactions transparent to all cursors django/branches/i18n/django/core/extensions.py
r850 r869 3 3 # for convenience's sake. 4 4 5 from django.core import template_loader6 5 from django.core.exceptions import Http404, ObjectDoesNotExist 7 from django.core.template import Context 6 from django.core.template import Context, loader 8 7 from django.conf.settings import DEBUG, INTERNAL_IPS 9 8 from django.utils.httpwrappers import HttpResponse 10 9 11 10 def render_to_response(*args, **kwargs): 12 return HttpResponse( template_loader.render_to_string(*args, **kwargs))11 return HttpResponse(loader.render_to_string(*args, **kwargs)) 13 12 load_and_render = render_to_response # For backwards compatibility. 14 13 django/branches/i18n/django/core/rss.py
r775 r869 1 from django.core import template_loader2 1 from django.core.exceptions import ObjectDoesNotExist 3 from django.core.template import Context 2 from django.core.template import Context, loader 4 3 from django.models.core import sites 5 4 from django.utils import feedgenerator … … 29 28 get_list_kwargs_cb -- Function that takes the param and returns a 30 29 dictionary to use in addition to get_list_kwargs (if applicable). 31 30 32 31 get_pubdate_cb -- Function that takes the object and returns a datetime 33 32 to use as the publication date in the feed. … … 50 49 self.enc_length = enc_length 51 50 self.enc_mime_type = enc_mime_type 52 51 53 52 def get_feed(self, param_slug=None): 54 53 """ … … 65 64 current_site = sites.get_current() 66 65 f = self._get_feed_generator_object(param) 67 title_template = template_loader.get_template('rss/%s_title' % self.slug)68 description_template = template_loader.get_template('rss/%s_description' % self.slug)66 title_template = loader.get_template('rss/%s_title' % self.slug) 67 description_template = loader.get_template('rss/%s_description' % self.slug) 69 68 kwargs = self.get_list_kwargs.copy() 70 69 if param and self.get_list_kwargs_cb: … … 103 102 ) 104 103 return f 105 104 106 105 def _get_feed_generator_object(self, param): 107 106 current_site = sites.get_current() django/branches/i18n/django/core/template_loader.py
r717 r869 1 "Wrapper for loading templates from storage of some sort (e.g. files or db)" 2 import template 3 from template_file import load_template_source 1 # This module is DEPRECATED! 2 # 3 # You should no longer be using django.core.template_loader. 4 # 5 # Use django.core.template.loader instead. 4 6 5 class ExtendsError(Exception): 6 pass 7 8 def get_template(template_name): 9 """ 10 Returns a compiled template.Template object for the given template name, 11 handling template inheritance recursively. 12 """ 13 return get_template_from_string(load_template_source(template_name)) 14 15 def get_template_from_string(source): 16 """ 17 Returns a compiled template.Template object for the given template code, 18 handling template inheritance recursively. 19 """ 20 return template.Template(source) 21 22 def render_to_string(template_name, dictionary=None, context_instance=None): 23 """ 24 Loads the given template_name and renders it with the given dictionary as 25 context. The template_name may be a string to load a single template using 26 get_template, or it may be a tuple to use select_template to find one of 27 the templates in the list. Returns a string. 28 """ 29 dictionary = dictionary or {} 30 if isinstance(template_name, (list, tuple)): 31 t = select_template(template_name) 32 else: 33 t = get_template(template_name) 34 if context_instance: 35 context_instance.update(dictionary) 36 else: 37 context_instance = template.Context(dictionary) 38 return t.render(context_instance) 39 40 def select_template(template_name_list): 41 "Given a list of template names, returns the first that can be loaded." 42 for template_name in template_name_list: 43 try: 44 return get_template(template_name) 45 except template.TemplateDoesNotExist: 46 continue 47 # If we get here, none of the templates could be loaded 48 raise template.TemplateDoesNotExist, ', '.join(template_name_list) 49 50 class BlockNode(template.Node): 51 def __init__(self, name, nodelist, parent=None): 52 self.name, self.nodelist, self.parent = name, nodelist, parent 53 54 def __repr__(self): 55 return "<Block Node: %s. Contents: %r>" % (self.name, self.nodelist) 56 57 def render(self, context): 58 context.push() 59 # Save context in case of block.super(). 60 self.context = context 61 context['block'] = self 62 result = self.nodelist.render(context) 63 context.pop() 64 return result 65 66 def super(self): 67 if self.parent: 68 return self.parent.render(self.context) 69 return '' 70 71 def add_parent(self, nodelist): 72 if self.parent: 73 self.parent.add_parent(nodelist) 74 else: 75 self.parent = BlockNode(self.name, nodelist) 76 77 class ExtendsNode(template.Node): 78 def __init__(self, nodelist, parent_name, parent_name_var, template_dirs=None): 79 self.nodelist = nodelist 80 self.parent_name, self.parent_name_var = parent_name, parent_name_var 81 self.template_dirs = template_dirs 82 83 def get_parent(self, context): 84 if self.parent_name_var: 85 self.parent_name = template.resolve_variable_with_filters(self.parent_name_var, context) 86 parent = self.parent_name 87 if not parent: 88 error_msg = "Invalid template name in 'extends' tag: %r." % parent 89 if self.parent_name_var: 90 error_msg += " Got this from the %r variable." % self.parent_name_var 91 raise template.TemplateSyntaxError, error_msg 92 try: 93 return get_template_from_string(load_template_source(parent, self.template_dirs)) 94 except template.TemplateDoesNotExist: 95 raise template.TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent 96 97 def render(self, context): 98 compiled_parent = self.get_parent(context) 99 parent_is_child = isinstance(compiled_parent.nodelist[0], ExtendsNode) 100 parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) 101 for block_node in self.nodelist.get_nodes_by_type(BlockNode): 102 # Check for a BlockNode with this node's name, and replace it if found. 103 try: 104 parent_block = parent_blocks[block_node.name] 105 except KeyError: 106 # This BlockNode wasn't found in the parent template, but the 107 # parent block might be defined in the parent's *parent*, so we 108 # add this BlockNode to the parent's ExtendsNode nodelist, so 109 # it'll be checked when the parent node's render() is called. 110 if parent_is_child: 111 compiled_parent.nodelist[0].nodelist.append(block_node) 112 else: 113 # Keep any existing parents and add a new one. Used by BlockNode. 114 parent_block.parent = block_node.parent 115 parent_block.add_parent(parent_block.nodelist) 116 parent_block.nodelist = block_node.nodelist 117 return compiled_parent.render(context) 118 119 def do_block(parser, token): 120 """ 121 Define a block that can be overridden by child templates. 122 """ 123 bits = token.contents.split() 124 if len(bits) != 2: 125 raise template.TemplateSyntaxError, "'%s' tag takes only one argument" % bits[0] 126 block_name = bits[1] 127 # Keep track of the names of BlockNodes found in this template, so we can 128 # check for duplication. 129 try: 130 if block_name in parser.__loaded_blocks: 131 raise template.TemplateSyntaxError, "'%s' tag with name '%s' appears more than once" % (bits[0], block_name) 132 parser.__loaded_blocks.append(block_name) 133 except AttributeError: # parser._loaded_blocks isn't a list yet 134 parser.__loaded_blocks = [block_name] 135 nodelist = parser.parse(('endblock',)) 136 parser.delete_first_token() 137 return BlockNode(block_name, nodelist) 138 139 def do_extends(parser, token): 140 """ 141 Signal that this template extends a parent template. 142 143 This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) 144 uses the literal value "base" as the name of the parent template to extend, 145 or ``{% entends variable %}`` uses the value of ``variable`` as the name 146 of the parent template to extend. 147 """ 148 bits = token.contents.split() 149 if len(bits) != 2: 150 raise template.TemplateSyntaxError, "'%s' takes one argument" % bits[0] 151 parent_name, parent_name_var = None, None 152 if (bits[1].startswith('"') and bits[1].endswith('"')) or (bits[1].startswith("'") and bits[1].endswith("'")): 153 parent_name = bits[1][1:-1] 154 else: 155 parent_name_var = bits[1] 156 nodelist = parser.parse() 157 if nodelist.get_nodes_by_type(ExtendsNode): 158 raise template.TemplateSyntaxError, "'%s' cannot appear more than once in the same template" % bits[0] 159 return ExtendsNode(nodelist, parent_name, parent_name_var) 160 161 template.register_tag('block', do_block) 162 template.register_tag('extends', do_extends) 7 from django.core.template.loader import * django/branches/i18n/django/middleware/admin.py
r669 r869 1 1 from django.utils import httpwrappers 2 from django.core import template_loader3 from django.core.extensions import DjangoContext as Context2 from django.core.extensions import DjangoContext 3 from django.core.extensions import render_to_response 4 4 from django.models.auth import users 5 5 from django.views.registration import passwords … … 97 97 else: 98 98 post_data = encode_post_data({}) 99 t = template_loader.get_template(self.get_login_template_name()) 100 c = Context(request, { 99 return render_to_response(self.get_login_template_name(), { 101 100 'title': 'Log in', 102 101 'app_path': request.path, 103 102 'post_data': post_data, 104 103 'error_message': error_message 105 }) 106 return httpwrappers.HttpResponse(t.render(c)) 104 }, context_instance=DjangoContext(request)) 107 105 108 106 def authenticate_user(self, user, password): django/branches/i18n/django/views/admin/doc.py
r665 r869 5 5 from django.core.extensions import DjangoContext, render_to_response 6 6 from django.core.exceptions import Http404, ViewDoesNotExist 7 from django.core import template, template_loader, defaulttags, defaultfilters, urlresolvers 7 from django.core import template, template_loader, urlresolvers 8 from django.core.template import defaulttags, defaultfilters 8 9 try: 9 10 from django.parts.admin import doc django/branches/i18n/django/views/admin/template.py
r675 r869 1 from django.core import formfields, template_loader,validators1 from django.core import formfields, validators 2 2 from django.core import template 3 from django.core.template import loader 3 4 from django.core.extensions import DjangoContext, render_to_response 4 5 from django.models.core import sites … … 50 51 # for "extends" that uses the site's TEMPLATE_DIR instead 51 52 def new_do_extends(parser, token): 52 node = template_loader.do_extends(parser, token)53 node = loader.do_extends(parser, token) 53 54 node.template_dirs = settings_module.TEMPLATE_DIRS 54 55 return node … … 59 60 error = None 60 61 try: 61 tmpl = template_loader.get_template_from_string(field_data)62 tmpl = loader.get_template_from_string(field_data) 62 63 tmpl.render(template.Context({})) 63 64 except template.TemplateSyntaxError, e: 64 65 error = e 65 template.register_tag('extends', template_loader.do_extends)66 template.register_tag('extends', loader.do_extends) 66 67 if error: 67 68 raise validators.ValidationError, e.args django/branches/i18n/django/views/auth/login.py
r669 r869 1 1 from django.parts.auth.formfields import AuthenticationForm 2 from django.core import formfields , template_loader2 from django.core import formfields 3 3 from django.core.extensions import DjangoContext, render_to_response 4 4 from django.models.auth import users django/branches/i18n/django/views/defaults.py
r549 r869 1 from django.core import template_loader2 1 from django.core.exceptions import Http404, ObjectDoesNotExist 3 from django.core.template import Context 2 from django.core.template import Context, loader 4 3 from django.models.core import sites 5 4 from django.utils import httpwrappers … … 57 56 return httpwrappers.HttpResponseGone() 58 57 return httpwrappers.HttpResponseRedirect(r.new_path) 59 t = template_loader.get_template('404')58 t = loader.get_template('404') 60 59 c = Context() 61 60 return httpwrappers.HttpResponseNotFound(t.render(c)) … … 68 67 Context: None 69 68 """ 70 t = template_loader.get_template('500')69 t = loader.get_template('500') 71 70 c = Context() 72 71 return httpwrappers.HttpResponseServerError(t.render(c)) django/branches/i18n/django/views/registration/passwords.py
r665 r869 1 from django.core import formfields, template_loader,validators1 from django.core import formfields, validators 2 2 from django.core.extensions import DjangoContext, render_to_response 3 from django.core.template import loader 3 4 from django.models.auth import users 4 5 from django.views.decorators.auth import login_required … … 33 34 else: 34 35 site_name = domain = domain_override 35 t = template_loader.get_template('registration/password_reset_email')36 t = loader.get_template('registration/password_reset_email') 36 37 c = { 37 38 'new_password': new_pass, django/branches/i18n/docs/forms.txt
r610 r869 66 66 POSTed data from the browser and creates a new ``Place`` object:: 67 67 68 from django.core import template_loader69 68 from django.core.exceptions import Http404 70 from django.core.extensions import DjangoContext as Context69 from django.core.extensions import render_to_response 71 70 from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect 72 71 from django.models.places import places … … 113 112 # the last two arguments to FormWrapper for now. 114 113 form = formfields.FormWrapper(places.AddManipulator(), {}, {}) 115 116 # Create a template, context and response. 117 t = template_loader.get_template('places/naive_create_form') 118 c = Context(request, { 119 'form': form 120 }) 121 return HttpResponse(t.render(c)) 114 return render_to_response('places/naive_create_form', {'form': form}) 122 115 123 116 (This view, as well as all the following ones, has the same imports as in the … … 170 163 errors = manipulator.get_validation_errors(new_data) 171 164 if errors: 172 t = template_loader.get_template('places/errors') 173 c = Context(request, { 174 'errors': errors 175 } 176 return HttpResponse(t.render(c)) 165 return render_to_response('places/errors', {'errors': errors}) 177 166 else: 178 167 manipulator.do_html2python(request.POST) … … 246 235 # Create the FormWrapper, template, context, response. 247 236 form = formfields.FormWrapper(manipulator, new_data, errors) 248 t = template_loader.get_template("places/create_form") 249 c = Context(request, { 250 'form': form, 251 }) 252 return HttpResponse(t.render(c)) 237 return render_to_response('places/create_form', {'form': form}) 253 238 254 239 and here's the ``create_form`` template:: … … 339 324 340 325 form = formfields.FormWrapper(manipulator, new_data, errors) 341 t = template_loader.get_template("places/edit_form") 342 c = Context(request, { 343 'form': form, 344 'place': place, 345 }) 346 return HttpResponse(t.render(c)) 326 return render_to_response('places/edit_form', {'form': form, 'place': place}) 347 327 348 328 The only real differences are: … … 423 403 errors = new_data = {} 424 404 form = formfields.FormWrapper(manipulator, new_data, errors) 425 t = template_loader.get_template("contact_form") 426 c = Context(request, { 427 'form': form, 428 }) 429 return HttpResponse(t.render(c)) 405 return render_to_response('contact_form', {'form': form}) 430 406 431 407 Validators django/branches/i18n/docs/sessions.txt
r669 r869 137 137 return HttpResponse("Please enable cookies and try again.") 138 138 request.session.set_test_cookie() 139 t = template_loader.get_template("foo/login_form") 140 c = Context(request) 141 return HttpResponse(t.render(c)) 139 return render_to_response('foo/login_form') 142 140 143 141 Using sessions out of views django/branches/i18n/docs/templates_python.txt
r775 r869 308 308 Django has two ways to load templates from files: 309 309 310 ``django.core.template _loader.get_template(template_name)``310 ``django.core.template.loader.get_template(template_name)`` 311 311 ``get_template`` returns the compiled template (a ``Template`` object) for 312 312 the template with the given name. If the template doesn't exist, it raises 313 313 ``django.core.template.TemplateDoesNotExist``. 314 314 315 ``django.core.template _loader.select_template(template_name_list)``315 ``django.core.template.loader.select_template(template_name_list)`` 316 316 ``select_template`` is just like ``get_template``, except it takes a list 317 317 of template names. Of the list, it returns the first template that exists. … … 399 399 400 400 For a ton of examples, read the source code for Django's default filters 401 and tags. They're in ``django/core/ defaultfilters.py`` and402 ``django/core/ defaulttags.py``, respectively.401 and tags. They're in ``django/core/template/defaultfilters.py`` and 402 ``django/core/template/defaulttags.py``, respectively. 403 403 404 404 Writing custom template filters … … 711 711 For more examples of complex rendering, see the source code for ``{% if %}``, 712 712 ``{% for %}``, ``{% ifequal %}`` and ``{% ifchanged %}``. They live in 713 ``django/core/ defaulttags.py``.713 ``django/core/template/defaulttags.py``. django/branches/i18n/docs/templates.txt
r775 r869 377 377 ``forloop.counter`` The current iteration of the loop (1-indexed) 378 378 ``forloop.counter0`` The current iteration of the loop (0-indexed) 379 ``forloop.revcounter`` The number of iterations from the end of the 379 ``forloop.revcounter`` The number of iterations from the end of the 380 380 loop (1-indexed) 381 ``forloop.revcounter0`` The number of iterations from the end of the 381 ``forloop.revcounter0`` The number of iterations from the end of the 382 382 loop (0-indexed) 383 383 ``forloop.first`` True if this is the first time through the loop … … 570 570 571 571 ``add`` 572 Adds the arg to the value 572 Adds the arg to the value. 573 573 574 574 ``addslashes`` 575 Adds slashes - useful for passing strings to JavaScript, for example.575 Adds slashes. Useful for passing strings to JavaScript, for example. 576 576 577 577 ``capfirst`` 578 Capitalizes the first character of the value 578 Capitalizes the first character of the value. 579 579 580 580 ``center`` 581 Centers the value in a field of a given width 581 Centers the value in a field of a given width. 582 582 583 583 ``cut`` 584 Removes all values of arg from the given string 584 Removes all values of arg from the given string. 585 585 586 586 ``date`` 587 Formats a date according to the given format (same as the ``now`` tag) 587 Formats a date according to the given format (same as the ``now`` tag). 588 588 589 589 ``default`` 590 If value is unavailable, use given default 590 If value is unavailable, use given default. 591 592 ``default_if_none`` 593 If value is ``None``, use given default. 591 594 592 595 ``dictsort`` … … 599 602 600 603 ``divisibleby`` 601 Returns true if the value is divisible by the argument 604 Returns true if the value is divisible by the argument. 602 605 603 606 ``escape`` 604 Escapes a string's HTML 607 Escapes a string's HTML. 605 608 606 609 ``filesizeformat`` … … 609 612 610 613 ``first`` 611 Returns the first item in a list 614 Returns the first item in a list. 612 615 613 616 ``fix_ampersands`` 614 Replaces ampersands with ``&`` entities 617 Replaces ampersands with ``&`` entities. 615 618 616 619 ``floatformat`` 617 620 Displays a floating point number as 34.2 (with one decimal places) - but 618 only if there's a point to be displayed 621 only if there's a point to be displayed. 619 622 620 623 ``get_digit`` … … 625 628 626 629 ``join`` 627 Joins a list with a string, like Python's ``str.join(list)`` 630 Joins a list with a string, like Python's ``str.join(list)``. 628 631 629 632 ``length`` 630 Returns the length of the value - useful for lists633 Returns the length of the value. Useful for lists. 631 634 632 635 ``length_is`` 633 Returns a boolean of whether the value's length is the argument 636 Returns a boolean of whether the value's length is the argument. 634 637 635 638 ``linebreaks`` 636 Converts newlines into <p> and <br />s 639 Converts newlines into <p> and <br />s. 637 640 638 641 ``linebreaksbr`` 639 Converts newlines into <br />s 642 Converts newlines into <br />s. 640 643 641 644 ``linenumbers`` 642 Displays text with line numbers 645 Displays text with line numbers. 643 646 644 647 ``ljust`` 645 Left-aligns the value in a field of a given width 648 Left-aligns the value in a field of a given width. 646 649 647 650 **Argument:** field size 648 651 649 652 ``lower`` 650 Converts a string into all lowercase 653 Converts a string into all lowercase. 651 654 652 655 ``make_list`` … … 655 658 656 659 ``phone2numeric`` 657 Takes a phone number and converts it in to its numerical equivalent 660 Takes a phone number and converts it in to its numerical equivalent. 658 661 659 662 ``pluralize`` 660 Returns 's' if the value is not 1, for '1 vote' vs. '2 votes' 663 Returns 's' if the value is not 1, for '1 vote' vs. '2 votes'. 661 664 662 665 ``pprint`` 663 A wrapper around pprint.pprint -- for debugging, really 666 A wrapper around pprint.pprint -- for debugging, really. 664 667 665 668 ``random`` 666 Returns a random item from the list 669 Returns a random item from the list. 667 670 668 671 ``removetags`` 669 Removes a space separated list of [X]HTML tags from the output 672 Removes a space separated list of [X]HTML tags from the output. 670 673 671 674 ``rjust`` 672 Right-aligns the value in a field of a given width 675 Right-aligns the value in a field of a given width. 673 676 674 677 **Argument:** field size … … 697 700 698 701 ``striptags`` 699 Strips all [X]HTML tags 702 Strips all [X]HTML tags. 700 703 701 704 ``time`` … … 703 706 704 707 ``timesince`` 705 Formats a date as the time since that date (i.e. "4 days, 6 hours") 708 Formats a date as the time since that date (i.e. "4 days, 6 hours"). 706 709 707 710 ``title`` 708 Converts a string into titlecase 711 Converts a string into titlecase. 709 712 710 713 ``truncatewords`` 711 Truncates a string after a certain number of words 714 Truncates a string after a certain number of words. 712 715 713 716 **Argument:** Number of words to truncate after … … 734 737 735 738 ``upper`` 736 Converts a string into all uppercase 739 Converts a string into all uppercase. 737 740 738 741 ``urlencode`` 739 Escapes a value for use in a URL 742 Escapes a value for use in a URL. 740 743 741 744 ``urlize`` 742 Converts URLs in plain text into clickable links 745 Converts URLs in plain text into clickable links. 743 746 744 747 ``urlizetrunc`` 745 Converts URLs into clickable links, truncating URLs to the given character limit 746 747 **Argument:** Length to truncate URLs to. 748 Converts URLs into clickable links, truncating URLs to the given character 749 limit. 750 751 **Argument:** Length to truncate URLs to 748 752 749 753 ``wordcount`` 750 Returns the number of words 754 Returns the number of words. 751 755 752 756 ``wordwrap`` 753 Wraps words at specified line length 754 755 **Argument:** number of words to wrap the text at.757 Wraps words at specified line length. 758 759 **Argument:** number of words at which to wrap the text 756 760 757 761 ``yesno`` django/branches/i18n/docs/tutorial03.txt
r775 r869 192 192 So let's use Django's template system to separate the design from Python:: 193 193 194 from django.core import template_loader 195 from django.core.template import Context 194 from django.core.template import Context, loader 196 195 from django.models.polls import polls 197 196 from django.utils.httpwrappers import HttpResponse … … 199 198 def index(request): 200 199 latest_poll_list = polls.get_list(order_by=['-pub_date'], limit=5) 201 t = template_loader.get_template('polls/index')200 t = loader.get_template('polls/index') 202 201 c = Context({ 203 202 'latest_poll_list': latest_poll_list, … … 225 224 Within that, create a file called ``index.html``. Django requires that 226 225 templates have ".html" extension. Note that our 227 `` template_loader.get_template('polls/index')`` code from above maps to226 ``loader.get_template('polls/index')`` code from above maps to 228 227 "[template_directory]/polls/index.html" on the filesystem. 229 228 … … 257 256 return render_to_response('polls/index', {'latest_poll_list': latest_poll_list}) 258 257 259 Note that we no longer need to import `` template_loader``, ``Context`` or258 Note that we no longer need to import ``loader``, ``Context`` or 260 259 ``HttpResponse``. 261 260 django/branches/i18n/docs/tutorial04.txt
r678 r869 198 198 ``<app_label>/<module_name>_detail``. In our case, it'll use the template 199 199 ``"polls/polls_detail"``. Thus, rename your ``polls/detail.html`` template to 200 ``polls/polls_detail.html``, and change the `` template_loader.get_template()``201 line in``vote()``.200 ``polls/polls_detail.html``, and change the ``render_to_response()`` line in 201 ``vote()``. 202 202 203 203 Similarly, the ``object_list`` generic view uses a template called django/branches/i18n/tests/othertests/templates.py
r836 r869 1 from django.core import template, template_loader 1 from django.core import template 2 from django.core.template import loader 2 3 from django.utils.translation import activate, deactivate 3 4 … … 260 261 } 261 262 262 # This replaces the standard template _loader.263 # This replaces the standard template loader. 263 264 def test_template_loader(template_name, template_dirs=None): 264 265 try: … … 268 269 269 270 def run_tests(verbosity=0, standalone=False): 270 template_loader.load_template_source, old_template_loader = test_template_loader, template_loader.load_template_source271 loader.load_template_source, old_template_loader = test_template_loader, loader.load_template_source 271 272 failed_tests = [] 272 273 tests = TEMPLATE_TESTS.items() … … 276 277 activate('*', vals[1]['LANGUAGE_CODE']) 277 278 try: 278 output = template_loader.get_template(name).render(template.Context(vals[1]))279 output = loader.get_template(name).render(template.Context(vals[1])) 279 280 except Exception, e: 280 281 if e.__class__ == vals[2]: … … 295 296 print "Template test: %s -- FAILED. Expected %r, got %r" % (name, vals[2], output) 296 297 failed_tests.append(name) 297 template_loader.load_template_source = old_template_loader298 loader.load_template_source = old_template_loader 298 299 299 300 if failed_tests and not standalone:
