From 5d425b36bf8cacc2ac84c84d89084a889d7b1b1a Mon Sep 17 00:00:00 2001
From: DaNmarner <danmarner@gmail.com>
Date: Thu, 17 Mar 2011 12:06:14 -0500
Subject: [PATCH] Made raise in docs the new style
---
django/middleware/common.py | 4 ++--
django/utils/unittest/case.py | 2 +-
docs/howto/custom-template-tags.txt | 14 +++++++-------
docs/ref/templates/api.txt | 2 +-
docs/topics/forms/formsets.txt | 2 +-
5 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/django/middleware/common.py b/django/middleware/common.py
index 07c6ff6..2252c8f 100644
|
a
|
b
|
class CommonMiddleware(object):
|
| 68 | 68 | _is_valid_path("%s/" % request.path_info, urlconf)): |
| 69 | 69 | new_url[1] = new_url[1] + '/' |
| 70 | 70 | if settings.DEBUG and request.method == 'POST': |
| 71 | | raise RuntimeError, ("" |
| | 71 | raise RuntimeError(("" |
| 72 | 72 | "You called this URL via POST, but the URL doesn't end " |
| 73 | 73 | "in a slash and you have APPEND_SLASH set. Django can't " |
| 74 | 74 | "redirect to the slash URL while maintaining POST data. " |
| 75 | 75 | "Change your form to point to %s%s (note the trailing " |
| 76 | 76 | "slash), or set APPEND_SLASH=False in your Django " |
| 77 | | "settings.") % (new_url[0], new_url[1]) |
| | 77 | "settings.") % (new_url[0], new_url[1])) |
| 78 | 78 | |
| 79 | 79 | if new_url == old_url: |
| 80 | 80 | # No redirects required. |
diff --git a/django/utils/unittest/case.py b/django/utils/unittest/case.py
index 8d943e2..e284800 100644
|
a
|
b
|
class TestCase(unittest.TestCase):
|
| 997 | 997 | excName = expected_exception.__name__ |
| 998 | 998 | else: |
| 999 | 999 | excName = str(expected_exception) |
| 1000 | | raise self.failureException, "%s not raised" % excName |
| | 1000 | raise self.failureException("%s not raised" % excName) |
| 1001 | 1001 | |
| 1002 | 1002 | |
| 1003 | 1003 | def assertRegexpMatches(self, text, expected_regexp, msg=None): |
diff --git a/docs/howto/custom-template-tags.txt b/docs/howto/custom-template-tags.txt
index ec4cd35..7dc6cce 100644
|
a
|
b
|
object::
|
| 351 | 351 | # split_contents() knows not to split quoted strings. |
| 352 | 352 | tag_name, format_string = token.split_contents() |
| 353 | 353 | except ValueError: |
| 354 | | raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0] |
| | 354 | raise template.TemplateSyntaxError("%r tag requires a single argument" % token.contents.split()[0]) |
| 355 | 355 | if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")): |
| 356 | | raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name |
| | 356 | raise template.TemplateSyntaxError("%r tag's argument should be in quotes" % tag_name) |
| 357 | 357 | return CurrentTimeNode(format_string[1:-1]) |
| 358 | 358 | |
| 359 | 359 | Notes: |
| … |
… |
Now your tag should begin to look like this::
|
| 596 | 596 | # split_contents() knows not to split quoted strings. |
| 597 | 597 | tag_name, date_to_be_formatted, format_string = token.split_contents() |
| 598 | 598 | except ValueError: |
| 599 | | raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0] |
| | 599 | raise template.TemplateSyntaxError("%r tag requires exactly two arguments" % token.contents.split()[0]) |
| 600 | 600 | if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")): |
| 601 | | raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name |
| | 601 | raise template.TemplateSyntaxError("%r tag's argument should be in quotes" % tag_name) |
| 602 | 602 | return FormatTimeNode(date_to_be_formatted, format_string[1:-1]) |
| 603 | 603 | |
| 604 | 604 | You also have to change the renderer to retrieve the actual contents of the |
| … |
… |
class, like so::
|
| 863 | 863 | # Splitting by None == splitting by spaces. |
| 864 | 864 | tag_name, arg = token.contents.split(None, 1) |
| 865 | 865 | except ValueError: |
| 866 | | raise template.TemplateSyntaxError, "%r tag requires arguments" % token.contents.split()[0] |
| | 866 | raise template.TemplateSyntaxError("%r tag requires arguments" % token.contents.split()[0]) |
| 867 | 867 | m = re.search(r'(.*?) as (\w+)', arg) |
| 868 | 868 | if not m: |
| 869 | | raise template.TemplateSyntaxError, "%r tag had invalid arguments" % tag_name |
| | 869 | raise template.TemplateSyntaxError("%r tag had invalid arguments" % tag_name) |
| 870 | 870 | format_string, var_name = m.groups() |
| 871 | 871 | if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")): |
| 872 | | raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name |
| | 872 | raise template.TemplateSyntaxError("%r tag's argument should be in quotes" % tag_name) |
| 873 | 873 | return CurrentTimeNode3(format_string[1:-1], var_name) |
| 874 | 874 | |
| 875 | 875 | The difference here is that ``do_current_time()`` grabs the format string and |
diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt
index ba78f15..4cfa4da 100644
|
a
|
b
|
straight lookups. Here are some things to keep in mind:
|
| 170 | 170 | >>> t = Template("My name is {{ person.first_name }}.") |
| 171 | 171 | >>> class PersonClass3: |
| 172 | 172 | ... def first_name(self): |
| 173 | | ... raise AssertionError, "foo" |
| | 173 | ... raise AssertionError("foo") |
| 174 | 174 | >>> p = PersonClass3() |
| 175 | 175 | >>> t.render(Context({"person": p})) |
| 176 | 176 | Traceback (most recent call last): |
diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt
index 41438f2..a3721fd 100644
|
a
|
b
|
is where you define your own validation that works at the formset level::
|
| 216 | 216 | ... form = self.forms[i] |
| 217 | 217 | ... title = form.cleaned_data['title'] |
| 218 | 218 | ... if title in titles: |
| 219 | | ... raise forms.ValidationError, "Articles in a set must have distinct titles." |
| | 219 | ... raise forms.ValidationError("Articles in a set must have distinct titles.") |
| 220 | 220 | ... titles.append(title) |
| 221 | 221 | |
| 222 | 222 | >>> ArticleFormSet = formset_factory(ArticleForm, formset=BaseArticleFormSet) |