1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

boulder-oracle-sprint: Merged to [4853].

git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4855 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Boulder Sprinters 2007-03-29 22:13:04 +00:00
parent 61c3c5bc7f
commit 1c3fccabd0
7 changed files with 110 additions and 9 deletions

View File

@ -4,7 +4,7 @@ from django.contrib.sites.models import Site
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
class FlatPage(models.Model): class FlatPage(models.Model):
url = models.CharField(_('URL'), maxlength=100, validator_list=[validators.isAlphaNumericURL], url = models.CharField(_('URL'), maxlength=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes.")) help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes."))
title = models.CharField(_('title'), maxlength=200) title = models.CharField(_('title'), maxlength=200)
content = models.TextField(_('content')) content = models.TextField(_('content'))

View File

@ -280,6 +280,24 @@ class LoadNode(Node):
def render(self, context): def render(self, context):
return '' return ''
class LoremNode(Node):
def __init__(self, count, method, common):
self.count, self.method, self.common = count, method, common
def render(self, context):
from django.utils.lorem_ipsum import words, paragraphs
try:
count = int(self.count.resolve(context))
except (ValueError, TypeError):
count = 1
if self.method == 'w':
return words(count, common=self.common)
else:
paras = paragraphs(count, common=self.common)
if self.method == 'p':
paras = ['<p>%s</p>' % p for p in paras]
return '\n\n'.join(paras)
class NowNode(Node): class NowNode(Node):
def __init__(self, format_string): def __init__(self, format_string):
self.format_string = format_string self.format_string = format_string
@ -768,6 +786,52 @@ def load(parser, token):
return LoadNode() return LoadNode()
load = register.tag(load) load = register.tag(load)
#@register.tag
def lorem(parser, token):
"""
Creates random latin text useful for providing test data in templates.
Usage format::
{% lorem [count] [method] [random] %}
``count`` is a number (or variable) containing the number of paragraphs or
words to generate (default is 1).
``method`` is either ``w`` for words, ``p`` for HTML paragraphs, ``b`` for
plain-text paragraph blocks (default is ``b``).
``random`` is the word ``random``, which if given, does not use the common
paragraph (starting "Lorem ipsum dolor sit amet, consectetuer...").
Examples:
* ``{% lorem %}`` will output the common "lorem ipsum" paragraph
* ``{% lorem 3 p %}`` will output the common "lorem ipsum" paragraph
and two random paragraphs each wrapped in HTML ``<p>`` tags
* ``{% lorem 2 w random %}`` will output two random latin words
"""
bits = list(token.split_contents())
tagname = bits[0]
# Random bit
common = bits[-1] != 'random'
if not common:
bits.pop()
# Method bit
if bits[-1] in ('w', 'p', 'b'):
method = bits.pop()
else:
method = 'b'
# Count bit
if len(bits) > 1:
count = bits.pop()
else:
count = '1'
count = parser.compile_filter(count)
if len(bits) != 1:
raise TemplateSyntaxError, "Incorrect format for %r tag" % tagname
return LoremNode(count, method, common)
lorem = register.tag(lorem)
#@register.tag #@register.tag
def now(parser, token): def now(parser, token):
""" """

View File

@ -84,5 +84,5 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
teardown_test_environment() teardown_test_environment()
return len(result.failures) return len(result.failures) + len(result.errors)

View File

@ -625,6 +625,31 @@ Load a custom template tag set.
See `Custom tag and filter libraries`_ for more information. See `Custom tag and filter libraries`_ for more information.
lorem
~~~~~
Display random latin text useful for providing sample data in templates.
Usage format: ``{% lorem [count] [method] [random] %}``
=========== =============================================================
Argument Description
=========== =============================================================
``count`` A number (or variable) containing the number of paragraphs or
words to generate (default is 1).
``method`` Either ``w`` for words, ``p`` for HTML paragraphs or ``b``
for plain-text paragraph blocks (default is ``b``).
``random`` The word ``random``, which if given, does not use the common
paragraph ("Lorem ipsum dolor sit amet...") when generating
text.
Examples:
* ``{% lorem %}`` will output the common "lorem ipsum" paragraph.
* ``{% lorem 3 p %}`` will output the common "lorem ipsum" paragraph
and two random paragraphs each wrapped in HTML ``<p>`` tags.
* ``{% lorem 2 w random %}`` will output two random latin words.
now now
~~~ ~~~

View File

@ -276,7 +276,7 @@ for testing purposes:
``status_code`` The HTTP status of the response. See RFC2616_ for a ``status_code`` The HTTP status of the response. See RFC2616_ for a
full list of HTTP status codes. full list of HTTP status codes.
``content`` The body of the response. The is the final page ``content`` The body of the response. This is the final page
content as rendered by the view, or any error message content as rendered by the view, or any error message
(such as the URL for a 302 redirect). (such as the URL for a 302 redirect).
@ -468,7 +468,8 @@ failed::
FAILED (failures=1) FAILED (failures=1)
The return code for the script will indicate the number of tests that failed. The return code for the script is the total number of failed and erroneous
tests. If all the tests pass, the return code is 0.
Regardless of whether the tests pass or fail, the test database is destroyed when Regardless of whether the tests pass or fail, the test database is destroyed when
all the tests have been executed. all the tests have been executed.

View File

@ -133,8 +133,8 @@ Now, edit ``settings.py``. It's a normal Python module with module-level
variables representing Django settings. Change these settings to match your variables representing Django settings. Change these settings to match your
database's connection parameters: database's connection parameters:
* ``DATABASE_ENGINE`` -- Either 'postgresql', 'mysql' or 'sqlite3'. * ``DATABASE_ENGINE`` -- Either 'postgresql_psycopg2', 'mysql' or 'sqlite3'.
More coming soon. Other backends are `also available`_.
* ``DATABASE_NAME`` -- The name of your database, or the full (absolute) * ``DATABASE_NAME`` -- The name of your database, or the full (absolute)
path to the database file if you're using SQLite. path to the database file if you're using SQLite.
* ``DATABASE_USER`` -- Your database username (not used for SQLite). * ``DATABASE_USER`` -- Your database username (not used for SQLite).
@ -143,6 +143,8 @@ database's connection parameters:
empty string if your database server is on the same physical machine empty string if your database server is on the same physical machine
(not used for SQLite). (not used for SQLite).
.. _also available: ../settings/
.. admonition:: Note .. admonition:: Note
If you're using PostgreSQL or MySQL, make sure you've created a database by If you're using PostgreSQL or MySQL, make sure you've created a database by
@ -319,7 +321,8 @@ Now Django knows ``mysite`` includes the ``polls`` app. Let's run another comman
python manage.py sql polls python manage.py sql polls
You should see the following (the CREATE TABLE SQL statements for the polls app):: You should see something similar to the following (the CREATE TABLE SQL statements
for the polls app)::
BEGIN; BEGIN;
CREATE TABLE "polls_poll" ( CREATE TABLE "polls_poll" (
@ -337,6 +340,8 @@ You should see the following (the CREATE TABLE SQL statements for the polls app)
Note the following: Note the following:
* The exact output will vary depending on the database you are using.
* Table names are automatically generated by combining the name of the app * Table names are automatically generated by combining the name of the app
(``polls``) and the lowercase name of the model -- ``poll`` and (``polls``) and the lowercase name of the model -- ``poll`` and
``choice``. (You can override this behavior.) ``choice``. (You can override this behavior.)
@ -365,8 +370,9 @@ If you're interested, also run the following commands:
* ``python manage.py validate polls`` -- Checks for any errors in the * ``python manage.py validate polls`` -- Checks for any errors in the
construction of your models. construction of your models.
* ``python manage.py sqlinitialdata polls`` -- Outputs any initial data * ``python manage.py sqlcustom polls`` -- Outputs any custom SQL statements
required for Django's admin framework and your models. (such as table modifications or constraints) that are defined for the
application.
* ``python manage.py sqlclear polls`` -- Outputs the necessary ``DROP * ``python manage.py sqlclear polls`` -- Outputs the necessary ``DROP
TABLE`` statements for this app, according to which tables already exist TABLE`` statements for this app, according to which tables already exist

View File

@ -654,6 +654,11 @@ class Templates(unittest.TestCase):
'with01': ('{% with dict.key as key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, '50'), 'with01': ('{% with dict.key as key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, '50'),
'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')), 'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')),
### LOREM TAG ######################################################
'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.'),
'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>'),
'lorem03': ('{% lorem 6 w %}', {}, 'lorem ipsum dolor sit amet consectetur'),
### NOW TAG ######################################################## ### NOW TAG ########################################################
# Simple case # Simple case
'now01' : ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)), 'now01' : ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),