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

newforms-admin: Merged from trunk up to [7120].

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7121 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Joseph Kocherhans 2008-02-15 17:05:48 +00:00
parent daa467d79e
commit 7c1242a7a3
84 changed files with 23646 additions and 11047 deletions

View File

@ -45,6 +45,8 @@ answer newbie questions, and generally made Django that much better:
Marty Alchin <gulopine@gamemusic.org> Marty Alchin <gulopine@gamemusic.org>
Daniel Alves Barbosa de Oliveira Vaz <danielvaz@gmail.com> Daniel Alves Barbosa de Oliveira Vaz <danielvaz@gmail.com>
AgarFu <heaven@croasanaso.sytes.net> AgarFu <heaven@croasanaso.sytes.net>
Dagur Páll Ammendrup <dagurp@gmail.com>
Collin Anderson <cmawebsite@gmail.com>
Andreas Andreas
andy@jadedplanet.net andy@jadedplanet.net
Fabrice Aneche <akh@nobugware.com> Fabrice Aneche <akh@nobugware.com>
@ -52,7 +54,7 @@ answer newbie questions, and generally made Django that much better:
Florian Apolloner Florian Apolloner
arien <regexbot@gmail.com> arien <regexbot@gmail.com>
David Ascher <http://ascher.ca/> David Ascher <http://ascher.ca/>
david@kazserve.org Jökull Sólberg Auðunsson <jokullsolberg@gmail.com>
Arthur <avandorp@gmail.com> Arthur <avandorp@gmail.com>
axiak@mit.edu axiak@mit.edu
Jiri Barton Jiri Barton
@ -100,6 +102,7 @@ answer newbie questions, and generally made Django that much better:
Dirk Datzert <dummy@habmalnefrage.de> Dirk Datzert <dummy@habmalnefrage.de>
Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/> Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/>
dave@thebarproject.com dave@thebarproject.com
david@kazserve.org
Jason Davies (Esaj) <http://www.jasondavies.com/> Jason Davies (Esaj) <http://www.jasondavies.com/>
Alex Dedul Alex Dedul
deric@monowerks.com deric@monowerks.com
@ -166,6 +169,7 @@ answer newbie questions, and generally made Django that much better:
Rob Hudson <http://rob.cogit8.org/> Rob Hudson <http://rob.cogit8.org/>
Jason Huggins <http://www.jrandolph.com/blog/> Jason Huggins <http://www.jrandolph.com/blog/>
Hyun Mi Ae Hyun Mi Ae
Ibon <ibonso@gmail.com>
Tom Insam Tom Insam
Baurzhan Ismagulov <ibr@radix50.net> Baurzhan Ismagulov <ibr@radix50.net>
james_027@yahoo.com james_027@yahoo.com
@ -233,7 +237,7 @@ answer newbie questions, and generally made Django that much better:
Christian Metts Christian Metts
michael.mcewan@gmail.com michael.mcewan@gmail.com
michal@plovarna.cz michal@plovarna.cz
mikko@sorl.net Mikko Hellsing <mikko@sorl.net>
Slawek Mikula <slawek dot mikula at gmail dot com> Slawek Mikula <slawek dot mikula at gmail dot com>
mitakummaa@gmail.com mitakummaa@gmail.com
mmarshall mmarshall
@ -307,6 +311,7 @@ answer newbie questions, and generally made Django that much better:
Don Spaulding <donspauldingii@gmail.com> Don Spaulding <donspauldingii@gmail.com>
Bjørn Stabell <bjorn@exoweb.net> Bjørn Stabell <bjorn@exoweb.net>
Georgi Stanojevski <glisha@gmail.com> Georgi Stanojevski <glisha@gmail.com>
starrynight <cmorgh@gmail.com>
Vasiliy Stavenko <stavenko@gmail.com> Vasiliy Stavenko <stavenko@gmail.com>
Thomas Steinacher <http://www.eggdrop.ch/> Thomas Steinacher <http://www.eggdrop.ch/>
Johan C. Stöver <johan@nilling.nl> Johan C. Stöver <johan@nilling.nl>

View File

@ -47,7 +47,8 @@ LANGUAGES = (
('el', gettext_noop('Greek')), ('el', gettext_noop('Greek')),
('en', gettext_noop('English')), ('en', gettext_noop('English')),
('es', gettext_noop('Spanish')), ('es', gettext_noop('Spanish')),
('es_AR', gettext_noop('Argentinean Spanish')), ('es-ar', gettext_noop('Argentinean Spanish')),
('eu', gettext_noop('Basque')),
('fa', gettext_noop('Persian')), ('fa', gettext_noop('Persian')),
('fi', gettext_noop('Finnish')), ('fi', gettext_noop('Finnish')),
('fr', gettext_noop('French')), ('fr', gettext_noop('French')),

File diff suppressed because it is too large Load Diff

View File

@ -9,8 +9,8 @@ msgstr ""
"Project-Id-Version: djangojs\n" "Project-Id-Version: djangojs\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-05-20 18:25+0200\n" "POT-Creation-Date: 2007-05-20 18:25+0200\n"
"PO-Revision-Date: 2007-12-01 12:06+0100\n" "PO-Revision-Date: 2008-01-22 19:39+0100\n"
"Last-Translator: Antoni Aloy <antoni.aloy@trespams.com>\n" "Last-Translator: Marc Garcia <marc.garcia@accopensys.com>\n"
"Language-Team: español <ca@li.org>\n" "Language-Team: español <ca@li.org>\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -50,9 +50,7 @@ msgstr "Deseleccionar tots"
#: contrib/admin/media/js/dateparse.js:32 #: contrib/admin/media/js/dateparse.js:32
#: contrib/admin/media/js/calendar.js:24 #: contrib/admin/media/js/calendar.js:24
msgid "" msgid "January February March April May June July August September October November December"
"January February March April May June July August September October November "
"December"
msgstr "Gener Febrer Març Abril Maig Juny Juliol Agost Setembre Octubre Novembre Desembre" msgstr "Gener Febrer Març Abril Maig Juny Juliol Agost Setembre Octubre Novembre Desembre"
#: contrib/admin/media/js/dateparse.js:33 #: contrib/admin/media/js/dateparse.js:33
@ -61,7 +59,7 @@ msgstr "Diumenge Dilluns Dimarts Dimecres Dijous Divendres Dissabte"
#: contrib/admin/media/js/calendar.js:25 #: contrib/admin/media/js/calendar.js:25
msgid "S M T W T F S" msgid "S M T W T F S"
msgstr "D L M X J V S" msgstr "Dg Dl Dt Dc Dj Dv Ds"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:47 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:47
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:81 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:81

View File

@ -153,6 +153,7 @@ msgstr "Sgorau Carma"
#: contrib/comments/models.py:242 #: contrib/comments/models.py:242
#, python-format #, python-format
#, fuzzy
msgid "%(score)d rating by %(user)s" msgid "%(score)d rating by %(user)s"
msgstr "%(score)d" msgstr "%(score)d"

View File

@ -2614,6 +2614,34 @@ msgstr "Samstag"
msgid "Sunday" msgid "Sunday"
msgstr "Sonntag" msgstr "Sonntag"
#: utils/dates.py:10
msgid "Mon"
msgstr "Mo"
#: utils/dates.py:10
msgid "Tue"
msgstr "Di"
#: utils/dates.py:10
msgid "Wed"
msgstr "Mi"
#: utils/dates.py:10
msgid "Thu"
msgstr "Do"
#: utils/dates.py:10
msgid "Fri"
msgstr "Fr"
#: utils/dates.py:11
msgid "Sat"
msgstr "Sa"
#: utils/dates.py:11
msgid "Sun"
msgstr "So"
#: utils/dates.py:14 #: utils/dates.py:14
msgid "January" msgid "January"
msgstr "Januar" msgstr "Januar"

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,117 @@
# Spanish translation for the django-admin JS files.
# Copyright (C)
# This file is distributed under the same license as the PACKAGE package.
#
msgid ""
msgstr ""
"Project-Id-Version: Django JavaScript 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-07-14 13:47-0500\n"
"PO-Revision-Date: 2007-07-14 13:41-0500\n"
"Last-Translator: Jorge Gajon <gajon@gajon.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: contrib/admin/media/js/calendar.js:24
#: contrib/admin/media/js/dateparse.js:32
msgid ""
"January February March April May June July August September October November "
"December"
msgstr ""
"Urtarrila Otsaila Martxoa Apirila Maiatza Ekaina Uztaila Abuztua Iraila Urria "
"Azaroa Abendua"
#: contrib/admin/media/js/calendar.js:25
msgid "S M T W T F S"
msgstr "I A A A O O L"
#: contrib/admin/media/js/dateparse.js:33
msgid "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
msgstr "Igandea Astelehene Asteartea Asteazkena Osteguna Ostirala Larunbata"
#: contrib/admin/media/js/SelectFilter2.js:33
#, perl-format
msgid "Available %s"
msgstr "%s Erabilgarri"
#: contrib/admin/media/js/SelectFilter2.js:41
msgid "Choose all"
msgstr "Denak aukeratu"
#: contrib/admin/media/js/SelectFilter2.js:46
msgid "Add"
msgstr "Gehitu"
#: contrib/admin/media/js/SelectFilter2.js:48
msgid "Remove"
msgstr "Ezabatu"
#: contrib/admin/media/js/SelectFilter2.js:53
#, perl-format
msgid "Chosen %s"
msgstr "%s Aukeratuak"
#: contrib/admin/media/js/SelectFilter2.js:54
msgid "Select your choice(s) and click "
msgstr "Egin zure aukerak eta click egin "
#: contrib/admin/media/js/SelectFilter2.js:59
msgid "Clear all"
msgstr "Denak garbitu"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:47
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:81
msgid "Now"
msgstr "Orain"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:51
msgid "Clock"
msgstr "Erlojua"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:78
msgid "Choose a time"
msgstr "Aukeratu ordu bat"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:82
msgid "Midnight"
msgstr "Gauerdia"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:83
msgid "6 a.m."
msgstr "6 a.m."
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:84
msgid "Noon"
msgstr "Eguerdia"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:88
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:183
msgid "Cancel"
msgstr "Atzera"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:128
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:177
msgid "Today"
msgstr "Gaur"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:132
msgid "Calendar"
msgstr "Egutegia"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:175
msgid "Yesterday"
msgstr "Atzo"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:179
msgid "Tomorrow"
msgstr "Bihar"
#: contrib/admin/media/js/admin/CollapsedFieldsets.js:34
#: contrib/admin/media/js/admin/CollapsedFieldsets.js:72
msgid "Show"
msgstr "Erakutsi"
#: contrib/admin/media/js/admin/CollapsedFieldsets.js:63
msgid "Hide"
msgstr "Izkutatu"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -8,8 +8,8 @@ msgstr ""
"Project-Id-Version: django 1.0\n" "Project-Id-Version: django 1.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-09-14 12:33+0100\n" "POT-Creation-Date: 2007-09-14 12:33+0100\n"
"PO-Revision-Date: 2007-09-14 14:19+0100\n" "PO-Revision-Date: 2008-01-23 11:04+0100\n"
"Last-Translator: Michael Thornhill <michael.thornhill@gmail.com>\n" "Last-Translator: Michael Thornhill <michael@maithu.com>\n"
"Language-Team: Gaeilge <ga@li.org>\n" "Language-Team: Gaeilge <ga@li.org>\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -18,99 +18,99 @@ msgstr ""
#: contrib/admin/media/js/calendar.js:24 #: contrib/admin/media/js/calendar.js:24
#: contrib/admin/media/js/dateparse.js:32 #: contrib/admin/media/js/dateparse.js:32
msgid "January February March April May June July August September October November December" msgid "January February March April May June July August September October November December"
msgstr "" msgstr "Eanair Feabhra Márta Aibreán Bealtaine Meitheamh Iúil Lúnasa Mean Fómhair Deireadh Fómhair Nollaig"
#: contrib/admin/media/js/calendar.js:25 #: contrib/admin/media/js/calendar.js:25
msgid "S M T W T F S" msgid "S M T W T F S"
msgstr "" msgstr "D L M C D A S"
#: contrib/admin/media/js/dateparse.js:33 #: contrib/admin/media/js/dateparse.js:33
msgid "Sunday Monday Tuesday Wednesday Thursday Friday Saturday" msgid "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
msgstr "" msgstr "Domhnaigh Luain Máirt Céadaoin Déardaoin Aoine Sathairn"
#: contrib/admin/media/js/SelectFilter2.js:33 #: contrib/admin/media/js/SelectFilter2.js:33
#, perl-format #, perl-format
msgid "Available %s" msgid "Available %s"
msgstr "" msgstr "%s ar fáil"
#: contrib/admin/media/js/SelectFilter2.js:41 #: contrib/admin/media/js/SelectFilter2.js:41
msgid "Choose all" msgid "Choose all"
msgstr "" msgstr "Roghnaigh iomlán"
#: contrib/admin/media/js/SelectFilter2.js:46 #: contrib/admin/media/js/SelectFilter2.js:46
msgid "Add" msgid "Add"
msgstr "" msgstr "Cuir le"
#: contrib/admin/media/js/SelectFilter2.js:48 #: contrib/admin/media/js/SelectFilter2.js:48
msgid "Remove" msgid "Remove"
msgstr "" msgstr "Bain amach"
#: contrib/admin/media/js/SelectFilter2.js:53 #: contrib/admin/media/js/SelectFilter2.js:53
#, perl-format #, perl-format
msgid "Chosen %s" msgid "Chosen %s"
msgstr "" msgstr "Roghnófar %s"
#: contrib/admin/media/js/SelectFilter2.js:54 #: contrib/admin/media/js/SelectFilter2.js:54
msgid "Select your choice(s) and click " msgid "Select your choice(s) and click "
msgstr "" msgstr "Roghnaigh do rogha agus cniog"
#: contrib/admin/media/js/SelectFilter2.js:59 #: contrib/admin/media/js/SelectFilter2.js:59
msgid "Clear all" msgid "Clear all"
msgstr "" msgstr "Glan iomlán"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:47 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:47
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:81 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:81
msgid "Now" msgid "Now"
msgstr "" msgstr "Anois"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:51 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:51
msgid "Clock" msgid "Clock"
msgstr "" msgstr "Clog"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:78 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:78
msgid "Choose a time" msgid "Choose a time"
msgstr "" msgstr "Roghnaigh am"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:82 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:82
msgid "Midnight" msgid "Midnight"
msgstr "" msgstr "Meán oíche"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:83 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:83
msgid "6 a.m." msgid "6 a.m."
msgstr "" msgstr "6 a.m."
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:84 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:84
msgid "Noon" msgid "Noon"
msgstr "" msgstr "Nóin"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:88 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:88
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:183 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:183
msgid "Cancel" msgid "Cancel"
msgstr "" msgstr "Cealaigh"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:128 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:128
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:177 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:177
msgid "Today" msgid "Today"
msgstr "" msgstr "Inniu"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:132 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:132
msgid "Calendar" msgid "Calendar"
msgstr "" msgstr "Féilire"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:175 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:175
msgid "Yesterday" msgid "Yesterday"
msgstr "" msgstr "Inné"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:179 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:179
msgid "Tomorrow" msgid "Tomorrow"
msgstr "" msgstr "Amárach"
#: contrib/admin/media/js/admin/CollapsedFieldsets.js:34 #: contrib/admin/media/js/admin/CollapsedFieldsets.js:34
#: contrib/admin/media/js/admin/CollapsedFieldsets.js:72 #: contrib/admin/media/js/admin/CollapsedFieldsets.js:72
msgid "Show" msgid "Show"
msgstr "" msgstr "Taispeán"
#: contrib/admin/media/js/admin/CollapsedFieldsets.js:63 #: contrib/admin/media/js/admin/CollapsedFieldsets.js:63
msgid "Hide" msgid "Hide"
msgstr "" msgstr "Folaigh"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -971,6 +971,7 @@ msgstr ""
#: contrib/admin/templates/admin/delete_confirmation.html:21 #: contrib/admin/templates/admin/delete_confirmation.html:21
#, python-format #, python-format
#,fuzzy
msgid "" msgid ""
"Are you sure you want to delete the %(object_name)s \"%(escaped_object)s\"? " "Are you sure you want to delete the %(object_name)s \"%(escaped_object)s\"? "
"All of the following related items will be deleted:" "All of the following related items will be deleted:"
@ -2181,6 +2182,7 @@ msgstr ""
#: core/validators.py:256 #: core/validators.py:256
#, python-format #, python-format
#,fuzzy
msgid "Watch your mouth! The word %s is not allowed here." msgid "Watch your mouth! The word %s is not allowed here."
msgstr "" msgstr ""
"ನಾಲಿಗೆ ಬಿಗಿ ಹಿಡಿಯಿರಿ! %s " "ನಾಲಿಗೆ ಬಿಗಿ ಹಿಡಿಯಿರಿ! %s "
@ -2486,6 +2488,7 @@ msgstr ""
#: forms/__init__.py:381 #: forms/__init__.py:381
#, python-format #, python-format
#,fuzzy
msgid "Ensure your text is less than %s character." msgid "Ensure your text is less than %s character."
msgstr "" msgstr ""
"ನಿಮ್ಮ ಗದ್ಯ %s ಅಕ್ಷರಕ್ಕಿಂತ " "ನಿಮ್ಮ ಗದ್ಯ %s ಅಕ್ಷರಕ್ಕಿಂತ "

File diff suppressed because it is too large Load Diff

View File

@ -851,6 +851,7 @@ msgstr "Remover"
#: contrib/admin/templates/admin/delete_confirmation.html:14 #: contrib/admin/templates/admin/delete_confirmation.html:14
#, python-format #, python-format
#, fuzzy
msgid "" msgid ""
"Deleting the %(object_name)s '%(escaped_object)s' would result in deleting " "Deleting the %(object_name)s '%(escaped_object)s' would result in deleting "
"related objects, but your account doesn't have permission to delete the " "related objects, but your account doesn't have permission to delete the "
@ -1933,6 +1934,7 @@ msgstr[1] "Por favor introduza um número décimal com um máximo de %s digitos.
#: core/validators.py:381 #: core/validators.py:381
#, python-format #, python-format
#, fuzzy
msgid "" msgid ""
"Please enter a valid decimal number with a whole part of at most %s digit." "Please enter a valid decimal number with a whole part of at most %s digit."
msgid_plural "" msgid_plural ""
@ -1973,6 +1975,7 @@ msgstr "Não foi possível extrair nada de %s."
#: core/validators.py:466 #: core/validators.py:466
#, python-format #, python-format
#, fuzzy
msgid "" msgid ""
"The URL %(url)s returned the invalid Content-Type header '%(contenttype)s'." "The URL %(url)s returned the invalid Content-Type header '%(contenttype)s'."
msgstr "O URL %(url)s devolveu um tipo de conteúdo inválido no header: '%s(contenttype)s'." msgstr "O URL %(url)s devolveu um tipo de conteúdo inválido no header: '%s(contenttype)s'."

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: djangojs\n" "Project-Id-Version: djangojs\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-03-06 02:29+0100\n" "POT-Creation-Date: 2008-02-01 15:31+0100\n"
"PO-Revision-Date: 2007-03-06 10:30+0100\n" "PO-Revision-Date: 2008-02-01 15:32+0100\n"
"Last-Translator: Mikko Hellsing <mikko@sorl.net>\n" "Last-Translator: Mikko Hellsing <mikko@sorl.net>\n"
"Language-Team: Django I18N <Django-I18N@googlegroups.com>\n" "Language-Team: Django I18N <Django-I18N@googlegroups.com>\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -20,7 +20,7 @@ msgstr ""
#: contrib/admin/media/js/SelectFilter2.js:33 #: contrib/admin/media/js/SelectFilter2.js:33
#, perl-format #, perl-format
msgid "Available %s" msgid "Available %s"
msgstr "Tillgänglig %s" msgstr "Tillgängliga %s"
#: contrib/admin/media/js/SelectFilter2.js:41 #: contrib/admin/media/js/SelectFilter2.js:41
msgid "Choose all" msgid "Choose all"
@ -37,7 +37,7 @@ msgstr "Ta bort"
#: contrib/admin/media/js/SelectFilter2.js:53 #: contrib/admin/media/js/SelectFilter2.js:53
#, perl-format #, perl-format
msgid "Chosen %s" msgid "Chosen %s"
msgstr "Vald %s" msgstr "Valda %s"
#: contrib/admin/media/js/SelectFilter2.js:54 #: contrib/admin/media/js/SelectFilter2.js:54
msgid "Select your choice(s) and click " msgid "Select your choice(s) and click "
@ -47,8 +47,8 @@ msgstr "Gör dina val och klicka på "
msgid "Clear all" msgid "Clear all"
msgstr "Ta bort alla" msgstr "Ta bort alla"
#: contrib/admin/media/js/dateparse.js:32
#: contrib/admin/media/js/calendar.js:24 #: contrib/admin/media/js/calendar.js:24
#: contrib/admin/media/js/dateparse.js:32
msgid "" msgid ""
"January February March April May June July August September October November " "January February March April May June July August September October November "
"December" "December"
@ -56,14 +56,14 @@ msgstr ""
"Januari Februari Mars April Maj Juni Juli Augusti September Oktober November " "Januari Februari Mars April Maj Juni Juli Augusti September Oktober November "
"December" "December"
#: contrib/admin/media/js/dateparse.js:33
msgid "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
msgstr "Söndag Måndag Tisdag Onsdag Torsdag Fredag Lördag"
#: contrib/admin/media/js/calendar.js:25 #: contrib/admin/media/js/calendar.js:25
msgid "S M T W T F S" msgid "S M T W T F S"
msgstr "S M T O T F L" msgstr "S M T O T F L"
#: contrib/admin/media/js/dateparse.js:33
msgid "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
msgstr "Söndag Måndag Tisdag Onsdag Torsdag Fredag Lördag"
#: contrib/admin/media/js/admin/CollapsedFieldsets.js:34 #: contrib/admin/media/js/admin/CollapsedFieldsets.js:34
#: contrib/admin/media/js/admin/CollapsedFieldsets.js:72 #: contrib/admin/media/js/admin/CollapsedFieldsets.js:72
msgid "Show" msgid "Show"
@ -119,4 +119,3 @@ msgstr "Igår"
#: contrib/admin/media/js/admin/DateTimeShortcuts.js:179 #: contrib/admin/media/js/admin/DateTimeShortcuts.js:179
msgid "Tomorrow" msgid "Tomorrow"
msgstr "Imorgon" msgstr "Imorgon"

View File

@ -18,7 +18,7 @@ DATABASE_PORT = '' # Set to empty string for default. Not used with
# Local time zone for this installation. Choices can be found here: # Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be avilable on all operating systems. # although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your # If running in a Windows environment this must be set to the same as your
# system time zone. # system time zone.
TIME_ZONE = 'America/Chicago' TIME_ZONE = 'America/Chicago'

View File

@ -1,5 +1,5 @@
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
urlpatterns = patterns('django.views', urlpatterns = patterns('django.views',
(r'^(?P<content_type_id>\d+)/(?P<object_id>\d+)/$', 'defaults.shortcut'), (r'^(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'defaults.shortcut'),
) )

View File

@ -2,7 +2,7 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('', urlpatterns = patterns('',
#('^$', 'django.contrib.admin.views.main.index'), #('^$', 'django.contrib.admin.views.main.index'),
('^r/(\d+)/(.*)/$', 'django.views.defaults.shortcut'), ('^r/', include('django.conf.urls.shortcut')),
#('^jsi18n/$', i18n_view, {'packages': 'django.conf'}), #('^jsi18n/$', i18n_view, {'packages': 'django.conf'}),
#('^logout/$', 'django.contrib.auth.views.logout'), #('^logout/$', 'django.contrib.auth.views.logout'),
#('^password_change/$', 'django.contrib.auth.views.password_change'), #('^password_change/$', 'django.contrib.auth.views.password_change'),

View File

@ -1,25 +1,27 @@
import datetime
from django.db import models from django.db import models
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.conf import settings from django.conf import settings
import datetime
MIN_PHOTO_DIMENSION = 5 MIN_PHOTO_DIMENSION = 5
MAX_PHOTO_DIMENSION = 1000 MAX_PHOTO_DIMENSION = 1000
# option codes for comment-form hidden fields # Option codes for comment-form hidden fields.
PHOTOS_REQUIRED = 'pr' PHOTOS_REQUIRED = 'pr'
PHOTOS_OPTIONAL = 'pa' PHOTOS_OPTIONAL = 'pa'
RATINGS_REQUIRED = 'rr' RATINGS_REQUIRED = 'rr'
RATINGS_OPTIONAL = 'ra' RATINGS_OPTIONAL = 'ra'
IS_PUBLIC = 'ip' IS_PUBLIC = 'ip'
# what users get if they don't have any karma # What users get if they don't have any karma.
DEFAULT_KARMA = 5 DEFAULT_KARMA = 5
KARMA_NEEDED_BEFORE_DISPLAYED = 3 KARMA_NEEDED_BEFORE_DISPLAYED = 3
class CommentManager(models.Manager): class CommentManager(models.Manager):
def get_security_hash(self, options, photo_options, rating_options, target): def get_security_hash(self, options, photo_options, rating_options, target):
""" """
@ -61,7 +63,9 @@ class CommentManager(models.Manager):
return True return True
return False return False
class Comment(models.Model): class Comment(models.Model):
"""A comment by a registered user."""
user = models.ForeignKey(User) user = models.ForeignKey(User)
content_type = models.ForeignKey(ContentType) content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField(_('object ID')) object_id = models.IntegerField(_('object ID'))
@ -124,7 +128,7 @@ class Comment(models.Model):
get_content_object.short_description = _('Content object') get_content_object.short_description = _('Content object')
def _fill_karma_cache(self): def _fill_karma_cache(self):
"Helper function that populates good/bad karma caches" """Helper function that populates good/bad karma caches."""
good, bad = 0, 0 good, bad = 0, 0
for k in self.karmascore_set: for k in self.karmascore_set:
if k.score == -1: if k.score == -1:
@ -153,8 +157,9 @@ class Comment(models.Model):
{'user': self.user.username, 'date': self.submit_date, {'user': self.user.username, 'date': self.submit_date,
'comment': self.comment, 'domain': self.site.domain, 'url': self.get_absolute_url()} 'comment': self.comment, 'domain': self.site.domain, 'url': self.get_absolute_url()}
class FreeComment(models.Model): class FreeComment(models.Model):
# A FreeComment is a comment by a non-registered user. """A comment by a non-registered user."""
content_type = models.ForeignKey(ContentType) content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField(_('object ID')) object_id = models.IntegerField(_('object ID'))
comment = models.TextField(_('comment'), max_length=3000) comment = models.TextField(_('comment'), max_length=3000)
@ -193,6 +198,7 @@ class FreeComment(models.Model):
get_content_object.short_description = _('Content object') get_content_object.short_description = _('Content object')
class KarmaScoreManager(models.Manager): class KarmaScoreManager(models.Manager):
def vote(self, user_id, comment_id, score): def vote(self, user_id, comment_id, score):
try: try:
@ -214,6 +220,7 @@ class KarmaScoreManager(models.Manager):
return DEFAULT_KARMA return DEFAULT_KARMA
return int(round((4.5 * score) + 5.5)) return int(round((4.5 * score) + 5.5))
class KarmaScore(models.Model): class KarmaScore(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User)
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)
@ -229,6 +236,7 @@ class KarmaScore(models.Model):
def __unicode__(self): def __unicode__(self):
return _("%(score)d rating by %(user)s") % {'score': self.score, 'user': self.user} return _("%(score)d rating by %(user)s") % {'score': self.score, 'user': self.user}
class UserFlagManager(models.Manager): class UserFlagManager(models.Manager):
def flag(self, comment, user): def flag(self, comment, user):
""" """
@ -239,7 +247,7 @@ class UserFlagManager(models.Manager):
if int(comment.user_id) == int(user.id): if int(comment.user_id) == int(user.id):
return # A user can't flag his own comment. Fail silently. return # A user can't flag his own comment. Fail silently.
try: try:
f = self.objects.get(user__pk=user.id, comment__pk=comment.id) f = self.get(user__pk=user.id, comment__pk=comment.id)
except self.model.DoesNotExist: except self.model.DoesNotExist:
from django.core.mail import mail_managers from django.core.mail import mail_managers
f = self.model(None, user.id, comment.id, None) f = self.model(None, user.id, comment.id, None)
@ -247,6 +255,7 @@ class UserFlagManager(models.Manager):
mail_managers('Comment flagged', message, fail_silently=True) mail_managers('Comment flagged', message, fail_silently=True)
f.save() f.save()
class UserFlag(models.Model): class UserFlag(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User)
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)
@ -261,6 +270,7 @@ class UserFlag(models.Model):
def __unicode__(self): def __unicode__(self):
return _("Flag by %r") % self.user return _("Flag by %r") % self.user
class ModeratorDeletion(models.Model): class ModeratorDeletion(models.Model):
user = models.ForeignKey(User, verbose_name='moderator') user = models.ForeignKey(User, verbose_name='moderator')
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)

View File

@ -105,7 +105,7 @@ class EasyInstance(object):
return self.instance._get_pk_val() return self.instance._get_pk_val()
def url(self): def url(self):
return '%s%s/%s/objects/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, iri_to_uri(self.pk())) return mark_safe('%s%s/%s/objects/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, iri_to_uri(self.pk())))
def fields(self): def fields(self):
""" """

View File

@ -20,7 +20,7 @@ class ARProvinceSelect(Select):
class ARPostalCodeField(RegexField): class ARPostalCodeField(RegexField):
""" """
A field that accepts a `classic´ NNNN Postal Code or a CPA. A field that accepts a 'classic' NNNN Postal Code or a CPA.
See http://www.correoargentino.com.ar/consulta_cpa/home.php See http://www.correoargentino.com.ar/consulta_cpa/home.php
""" """
@ -44,7 +44,7 @@ class ARPostalCodeField(RegexField):
class ARDNIField(CharField): class ARDNIField(CharField):
""" """
A field that validates `Documento Nacional de Identidad´ (DNI) numbers. A field that validates 'Documento Nacional de Identidad' (DNI) numbers.
""" """
default_error_messages = { default_error_messages = {
'invalid': ugettext("This field requires only numbers."), 'invalid': ugettext("This field requires only numbers."),
@ -73,7 +73,7 @@ class ARDNIField(CharField):
class ARCUITField(RegexField): class ARCUITField(RegexField):
""" """
This field validates a CUIT (Código Único de Identificación Tributaria). A This field validates a CUIT (Código Único de Identificación Tributaria). A
CUIT is of the form XX-XXXXXXXX-V. The last digit is a check digit. CUIT is of the form XX-XXXXXXXX-V. The last digit is a check digit.
""" """
default_error_messages = { default_error_messages = {

View File

@ -55,7 +55,7 @@ NORTHERN_IRELAND_REGION_CHOICES = (
("County Antrim", _("County Antrim")), ("County Antrim", _("County Antrim")),
("County Armagh", _("County Armagh")), ("County Armagh", _("County Armagh")),
("County Down", _("County Down")), ("County Down", _("County Down")),
("County Fermanagh", _("County Down")), ("County Fermanagh", _("County Fermanagh")),
("County Londonderry", _("County Londonderry")), ("County Londonderry", _("County Londonderry")),
("County Tyrone", _("County Tyrone")), ("County Tyrone", _("County Tyrone")),
) )

View File

@ -6,7 +6,7 @@ from django.utils.encoding import smart_unicode, iri_to_uri
from django.conf import settings from django.conf import settings
def add_domain(domain, url): def add_domain(domain, url):
if not url.startswith('http://'): if not (url.startswith('http://') or url.startswith('https://')):
# 'url' must already be ASCII and URL-quoted, so no need for encoding # 'url' must already be ASCII and URL-quoted, so no need for encoding
# conversions here. # conversions here.
url = iri_to_uri(u'http://%s%s' % (domain, url)) url = iri_to_uri(u'http://%s%s' % (domain, url))
@ -82,7 +82,8 @@ class Feed(object):
link = link, link = link,
description = self.__get_dynamic_attr('description', obj), description = self.__get_dynamic_attr('description', obj),
language = settings.LANGUAGE_CODE.decode(), language = settings.LANGUAGE_CODE.decode(),
feed_url = add_domain(current_site, self.__get_dynamic_attr('feed_url', obj)), feed_url = add_domain(current_site.domain,
self.__get_dynamic_attr('feed_url', obj)),
author_name = self.__get_dynamic_attr('author_name', obj), author_name = self.__get_dynamic_attr('author_name', obj),
author_link = self.__get_dynamic_attr('author_link', obj), author_link = self.__get_dynamic_attr('author_link', obj),
author_email = self.__get_dynamic_attr('author_email', obj), author_email = self.__get_dynamic_attr('author_email', obj),

View File

@ -111,13 +111,13 @@ class BaseHandler(object):
except SystemExit: except SystemExit:
pass # See http://code.djangoproject.com/ticket/1023 pass # See http://code.djangoproject.com/ticket/1023
except: # Handle everything else, including SuspiciousOperation, etc. except: # Handle everything else, including SuspiciousOperation, etc.
if settings.DEBUG:
from django.views import debug
return debug.technical_500_response(request, *sys.exc_info())
else:
# Get the exception info now, in case another exception is thrown later. # Get the exception info now, in case another exception is thrown later.
exc_info = sys.exc_info() exc_info = sys.exc_info()
receivers = dispatcher.send(signal=signals.got_request_exception, request=request) receivers = dispatcher.send(signal=signals.got_request_exception, request=request)
if settings.DEBUG:
from django.views import debug
return debug.technical_500_response(request, *exc_info)
else:
# When DEBUG is False, send an error message to the admins. # When DEBUG is False, send an error message to the admins.
subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path) subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
try: try:

View File

@ -59,7 +59,7 @@ class Command(BaseCommand):
else: else:
formats = [] formats = []
if verbosity > 2: if verbosity >= 2:
if formats: if formats:
print "Loading '%s' fixtures..." % fixture_name print "Loading '%s' fixtures..." % fixture_name
else: else:
@ -109,7 +109,7 @@ class Command(BaseCommand):
return return
fixture.close() fixture.close()
except: except:
if verbosity > 2: if verbosity >= 2:
print "No %s fixture '%s' in %s." % \ print "No %s fixture '%s' in %s." % \
(format, fixture_name, humanize(fixture_dir)) (format, fixture_name, humanize(fixture_dir))
@ -125,7 +125,7 @@ class Command(BaseCommand):
transaction.leave_transaction_management() transaction.leave_transaction_management()
if count[0] == 0: if count[0] == 0:
if verbosity > 2: if verbosity >= 2:
print "No fixtures found." print "No fixtures found."
else: else:
if verbosity > 0: if verbosity > 0:

View File

@ -1,7 +1,7 @@
from django.core.management.base import AppCommand from django.core.management.base import AppCommand
class Command(AppCommand): class Command(AppCommand):
help = "Prints the CREATE TABLE, initial-data and CREATE INDEX SQL statements for the given model module name(s)." help = "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s)."
output_transaction = True output_transaction = True

View File

@ -24,7 +24,8 @@ class ModelBase(type):
def __new__(cls, name, bases, attrs): def __new__(cls, name, bases, attrs):
# If this isn't a subclass of Model, don't do anything special. # If this isn't a subclass of Model, don't do anything special.
try: try:
if not filter(lambda b: issubclass(b, Model), bases): parents = [b for b in bases if issubclass(b, Model)]
if not parents:
return super(ModelBase, cls).__new__(cls, name, bases, attrs) return super(ModelBase, cls).__new__(cls, name, bases, attrs)
except NameError: except NameError:
# 'Model' isn't defined yet, meaning we're looking at Django's own # 'Model' isn't defined yet, meaning we're looking at Django's own
@ -39,9 +40,10 @@ class ModelBase(type):
types.ClassType('MultipleObjectsReturned', (MultipleObjectsReturned, ), {})) types.ClassType('MultipleObjectsReturned', (MultipleObjectsReturned, ), {}))
# Build complete list of parents # Build complete list of parents
for base in bases: for base in parents:
# TODO: Checking for the presence of '_meta' is hackish. # Things without _meta aren't functional models, so they're
if '_meta' in dir(base): # uninteresting parents.
if hasattr(base, '_meta'):
new_class._meta.parents.append(base) new_class._meta.parents.append(base)
new_class._meta.parents.extend(base._meta.parents) new_class._meta.parents.extend(base._meta.parents)
@ -79,6 +81,35 @@ class ModelBase(type):
# registered version. # registered version.
return get_model(new_class._meta.app_label, name, False) return get_model(new_class._meta.app_label, name, False)
def add_to_class(cls, name, value):
if name == 'Admin':
assert type(value) == types.ClassType, "%r attribute of %s model must be a class, not a %s object" % (name, cls.__name__, type(value))
value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_')]))
if hasattr(value, 'contribute_to_class'):
value.contribute_to_class(cls, name)
else:
setattr(cls, name, value)
def _prepare(cls):
# Creates some methods once self._meta has been populated.
opts = cls._meta
opts._prepare(cls)
if opts.order_with_respect_to:
cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls))
setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls))
# Give the class a docstring -- its definition.
if cls.__doc__ is None:
cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields]))
if hasattr(cls, 'get_absolute_url'):
cls.get_absolute_url = curry(get_absolute_url, opts, cls.get_absolute_url)
dispatcher.send(signal=signals.class_prepared, sender=cls)
class Model(object): class Model(object):
__metaclass__ = ModelBase __metaclass__ = ModelBase
@ -110,7 +141,7 @@ class Model(object):
# There is a rather weird disparity here; if kwargs, it's set, then args # There is a rather weird disparity here; if kwargs, it's set, then args
# overrides it. It should be one or the other; don't duplicate the work # overrides it. It should be one or the other; don't duplicate the work
# The reason for the kwargs check is that standard iterator passes in by # The reason for the kwargs check is that standard iterator passes in by
# args, and nstantiation for iteration is 33% faster. # args, and instantiation for iteration is 33% faster.
args_len = len(args) args_len = len(args)
if args_len > len(self._meta.fields): if args_len > len(self._meta.fields):
# Daft, but matches old exception sans the err msg. # Daft, but matches old exception sans the err msg.
@ -176,37 +207,9 @@ class Model(object):
raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0]
dispatcher.send(signal=signals.post_init, sender=self.__class__, instance=self) dispatcher.send(signal=signals.post_init, sender=self.__class__, instance=self)
def add_to_class(cls, name, value):
if hasattr(value, 'contribute_to_class'):
value.contribute_to_class(cls, name)
else:
setattr(cls, name, value)
add_to_class = classmethod(add_to_class)
def _prepare(cls):
# Creates some methods once self._meta has been populated.
opts = cls._meta
opts._prepare(cls)
if opts.order_with_respect_to:
cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls))
setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls))
# Give the class a docstring -- its definition.
if cls.__doc__ is None:
cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields]))
if hasattr(cls, 'get_absolute_url'):
cls.get_absolute_url = curry(get_absolute_url, opts, cls.get_absolute_url)
dispatcher.send(signal=signals.class_prepared, sender=cls)
_prepare = classmethod(_prepare)
def save(self, raw=False): def save(self, raw=False):
dispatcher.send(signal=signals.pre_save, sender=self.__class__, instance=self) dispatcher.send(signal=signals.pre_save, sender=self.__class__,
instance=self, raw=raw)
non_pks = [f for f in self._meta.fields if not f.primary_key] non_pks = [f for f in self._meta.fields if not f.primary_key]
cursor = connection.cursor() cursor = connection.cursor()
@ -267,7 +270,7 @@ class Model(object):
# Run any post-save hooks. # Run any post-save hooks.
dispatcher.send(signal=signals.post_save, sender=self.__class__, dispatcher.send(signal=signals.post_save, sender=self.__class__,
instance=self, created=(not record_exists)) instance=self, created=(not record_exists), raw=raw)
save.alters_data = True save.alters_data = True

View File

@ -22,11 +22,11 @@ class GZipMiddleware(object):
if response.has_header('Content-Encoding'): if response.has_header('Content-Encoding'):
return response return response
# Older versions of IE have issues with gzipped javascript. # Older versions of IE have issues with gzipped pages containing either
# See http://code.djangoproject.com/ticket/2449 # Javascript and PDF.
is_ie = "msie" in request.META.get('HTTP_USER_AGENT', '').lower() if "msie" in request.META.get('HTTP_USER_AGENT', '').lower():
is_js = "javascript" in response.get('Content-Type', '').lower() ctype = response.get('Content-Type', '').lower()
if is_ie and is_js: if "javascript" in ctype or ctype == "application/pdf":
return response return response
ae = request.META.get('HTTP_ACCEPT_ENCODING', '') ae = request.META.get('HTTP_ACCEPT_ENCODING', '')

View File

@ -466,6 +466,8 @@ class ImageField(FileField):
f = super(ImageField, self).clean(data, initial) f = super(ImageField, self).clean(data, initial)
if f is None: if f is None:
return None return None
elif not data and initial:
return initial
from PIL import Image from PIL import Image
from cStringIO import StringIO from cStringIO import StringIO
try: try:

View File

@ -22,24 +22,41 @@ def pretty_name(name):
name = name[0].upper() + name[1:] name = name[0].upper() + name[1:]
return name.replace('_', ' ') return name.replace('_', ' ')
class DeclarativeFieldsMetaclass(type): def get_declared_fields(bases, attrs, with_base_fields=True):
""" """
Metaclass that converts Field attributes to a dictionary called Create a list of form field instances from the passed in 'attrs', plus any
'base_fields', taking into account parent class 'base_fields' as well. similar fields on the base classes (in 'bases'). This is used by both the
Form and ModelForm metclasses.
If 'with_base_fields' is True, all fields from the bases are used.
Otherwise, only fields in the 'declared_fields' attribute on the bases are
used. The distinction is useful in ModelForm subclassing.
Also integrates any additional media definitions Also integrates any additional media definitions
""" """
def __new__(cls, name, bases, attrs):
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)] fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter)) fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
# If this class is subclassing another Form, add that Form's fields. # If this class is subclassing another Form, add that Form's fields.
# Note that we loop over the bases in *reverse*. This is necessary in # Note that we loop over the bases in *reverse*. This is necessary in
# order to preserve the correct order of fields. # order to preserve the correct order of fields.
if with_base_fields:
for base in bases[::-1]: for base in bases[::-1]:
if hasattr(base, 'base_fields'): if hasattr(base, 'base_fields'):
fields = base.base_fields.items() + fields fields = base.base_fields.items() + fields
else:
for base in bases[::-1]:
if hasattr(base, 'declared_fields'):
fields = base.declared_fields.items() + fields
attrs['base_fields'] = SortedDict(fields) return SortedDict(fields)
class DeclarativeFieldsMetaclass(type):
"""
Metaclass that converts Field attributes to a dictionary called
'base_fields', taking into account parent class 'base_fields' as well.
"""
def __new__(cls, name, bases, attrs):
attrs['base_fields'] = get_declared_fields(bases, attrs)
new_class = type.__new__(cls, name, bases, attrs) new_class = type.__new__(cls, name, bases, attrs)
if 'media' not in attrs: if 'media' not in attrs:

View File

@ -11,7 +11,7 @@ from django.utils.datastructures import SortedDict
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from util import ValidationError, ErrorList from util import ValidationError, ErrorList
from forms import BaseForm from forms import BaseForm, get_declared_fields
from fields import Field, ChoiceField, IntegerField, EMPTY_VALUES from fields import Field, ChoiceField, IntegerField, EMPTY_VALUES
from formsets import BaseFormSet, formset_for_form, DELETION_FIELD_NAME from formsets import BaseFormSet, formset_for_form, DELETION_FIELD_NAME
from widgets import Select, SelectMultiple, HiddenInput, MultipleHiddenInput from widgets import Select, SelectMultiple, HiddenInput, MultipleHiddenInput
@ -213,57 +213,39 @@ class ModelFormOptions(object):
self.fields = getattr(options, 'fields', None) self.fields = getattr(options, 'fields', None)
self.exclude = getattr(options, 'exclude', None) self.exclude = getattr(options, 'exclude', None)
class ModelFormMetaclass(type): class ModelFormMetaclass(type):
def __new__(cls, name, bases, attrs, def __new__(cls, name, bases, attrs,
formfield_callback=lambda f: f.formfield()): formfield_callback=lambda f: f.formfield()):
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)] try:
fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter)) parents = [b for b in bases if issubclass(b, ModelForm)]
except NameError:
# We are defining ModelForm itself.
parents = None
if not parents:
return super(ModelFormMetaclass, cls).__new__(cls, name, bases,
attrs)
# If this class is subclassing another Form, add that Form's fields. new_class = type.__new__(cls, name, bases, attrs)
# Note that we loop over the bases in *reverse*. This is necessary in declared_fields = get_declared_fields(bases, attrs, False)
# order to preserve the correct order of fields. opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
for base in bases[::-1]: if opts.model:
if hasattr(base, 'base_fields'): # If a model is defined, extract form fields from it.
fields = base.base_fields.items() + fields fields = fields_for_model(opts.model, opts.fields,
declared_fields = SortedDict(fields)
opts = ModelFormOptions(attrs.get('Meta', None))
attrs['_meta'] = opts
# Don't allow more than one Meta model defenition in bases. The fields
# would be generated correctly, but the save method won't deal with
# more than one object.
base_models = []
for base in bases:
base_opts = getattr(base, '_meta', None)
base_model = getattr(base_opts, 'model', None)
if base_model is not None:
base_models.append(base_model)
if len(base_models) > 1:
raise ImproperlyConfigured("%s's base classes define more than one model." % name)
# If a model is defined, extract form fields from it and add them to base_fields
if attrs['_meta'].model is not None:
# Don't allow a subclass to define a different Meta model than a
# parent class has. Technically the right fields would be generated,
# but the save method will not deal with more than one model.
for base in bases:
base_opts = getattr(base, '_meta', None)
base_model = getattr(base_opts, 'model', None)
if base_model and base_model is not opts.model:
raise ImproperlyConfigured('%s defines a different model than its parent.' % name)
model_fields = fields_for_model(opts.model, opts.fields,
opts.exclude, formfield_callback) opts.exclude, formfield_callback)
# fields declared in base classes override fields from the model # Override default model fields with any custom declared ones
model_fields.update(declared_fields) # (plus, include all the other declared fields).
attrs['base_fields'] = model_fields fields.update(declared_fields)
else: else:
attrs['base_fields'] = declared_fields fields = declared_fields
return type.__new__(cls, name, bases, attrs) new_class.declared_fields = declared_fields
new_class.base_fields = fields
return new_class
class BaseModelForm(BaseForm): class BaseModelForm(BaseForm):
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
initial=None, error_class=ErrorList, label_suffix=':', instance=None): initial=None, error_class=ErrorList, label_suffix=':',
instance=None):
opts = self._meta opts = self._meta
if instance is None: if instance is None:
# if we didn't get an instance, instantiate a new one # if we didn't get an instance, instantiate a new one
@ -279,7 +261,8 @@ class BaseModelForm(BaseForm):
def save(self, commit=True): def save(self, commit=True):
""" """
Saves this ``form``'s cleaned_data into model instance ``self.instance``. Saves this ``form``'s cleaned_data into model instance
``self.instance``.
If commit=True, then the changes to ``instance`` will be saved to the If commit=True, then the changes to ``instance`` will be saved to the
database. Returns ``instance``. database. Returns ``instance``.

View File

@ -547,7 +547,7 @@ class MultiWidget(Widget):
if id_: if id_:
final_attrs = dict(final_attrs, id='%s_%s' % (id_, i)) final_attrs = dict(final_attrs, id='%s_%s' % (id_, i))
output.append(widget.render(name + '_%s' % i, widget_value, final_attrs)) output.append(widget.render(name + '_%s' % i, widget_value, final_attrs))
return self.format_output(output) return mark_safe(self.format_output(output))
def id_for_label(self, id_): def id_for_label(self, id_):
# See the comment for RadioSelect.id_for_label() # See the comment for RadioSelect.id_for_label()

View File

@ -289,6 +289,14 @@ class Parser(object):
return NodeList() return NodeList()
def extend_nodelist(self, nodelist, node, token): def extend_nodelist(self, nodelist, node, token):
if node.must_be_first and nodelist:
try:
if nodelist.contains_nontext:
raise AttributeError
except AttributeError:
raise TemplateSyntaxError("%r must be the first tag in the template." % node)
if isinstance(nodelist, NodeList) and not isinstance(node, TextNode):
nodelist.contains_nontext = True
nodelist.append(node) nodelist.append(node)
def enter_command(self, command, token): def enter_command(self, command, token):
@ -708,6 +716,10 @@ class Variable(object):
return current return current
class Node(object): class Node(object):
# Set this to True for nodes that must be first in the template (although
# they can be preceded by text nodes.
must_be_first = False
def render(self, context): def render(self, context):
"Return the node rendered as a string" "Return the node rendered as a string"
pass pass
@ -725,6 +737,10 @@ class Node(object):
return nodes return nodes
class NodeList(list): class NodeList(list):
# Set to True the first time a non-TextNode is inserted by
# extend_nodelist().
contains_nontext = False
def render(self, context): def render(self, context):
bits = [] bits = []
for node in self: for node in self:

View File

@ -343,7 +343,7 @@ def force_escape(value):
""" """
from django.utils.html import escape from django.utils.html import escape
return mark_safe(escape(value)) return mark_safe(escape(value))
escape = stringfilter(escape) force_escape = stringfilter(force_escape)
force_escape.is_safe = True force_escape.is_safe = True
def linebreaks(value, autoescape=None): def linebreaks(value, autoescape=None):

View File

@ -1,5 +1,5 @@
from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable
from django.template import Library, Node from django.template import Library, Node, TextNode
from django.template.loader import get_template, get_template_from_string, find_template_source from django.template.loader import get_template, get_template_from_string, find_template_source
from django.conf import settings from django.conf import settings
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
@ -37,11 +37,18 @@ class BlockNode(Node):
self.parent = BlockNode(self.name, nodelist) self.parent = BlockNode(self.name, nodelist)
class ExtendsNode(Node): class ExtendsNode(Node):
must_be_first = True
def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None): def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
self.nodelist = nodelist self.nodelist = nodelist
self.parent_name, self.parent_name_expr = parent_name, parent_name_expr self.parent_name, self.parent_name_expr = parent_name, parent_name_expr
self.template_dirs = template_dirs self.template_dirs = template_dirs
def __repr__(self):
if self.parent_name_expr:
return "<ExtendsNode: extends %s>" % self.parent_name_expr.token
return '<ExtendsNode: extends "%s">' % self.parent_name
def get_parent(self, context): def get_parent(self, context):
if self.parent_name_expr: if self.parent_name_expr:
self.parent_name = self.parent_name_expr.resolve(context) self.parent_name = self.parent_name_expr.resolve(context)
@ -49,7 +56,7 @@ class ExtendsNode(Node):
if not parent: if not parent:
error_msg = "Invalid template name in 'extends' tag: %r." % parent error_msg = "Invalid template name in 'extends' tag: %r." % parent
if self.parent_name_expr: if self.parent_name_expr:
error_msg += " Got this from the %r variable." % self.parent_name_expr #TODO nice repr. error_msg += " Got this from the '%s' variable." % self.parent_name_expr.token
raise TemplateSyntaxError, error_msg raise TemplateSyntaxError, error_msg
if hasattr(parent, 'render'): if hasattr(parent, 'render'):
return parent # parent is a Template object return parent # parent is a Template object
@ -62,7 +69,10 @@ class ExtendsNode(Node):
def render(self, context): def render(self, context):
compiled_parent = self.get_parent(context) compiled_parent = self.get_parent(context)
parent_is_child = isinstance(compiled_parent.nodelist[0], ExtendsNode) pos = 0
while isinstance(compiled_parent.nodelist[pos], TextNode):
pos += 1
parent_is_child = isinstance(compiled_parent.nodelist[pos], ExtendsNode)
parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)])
for block_node in self.nodelist.get_nodes_by_type(BlockNode): for block_node in self.nodelist.get_nodes_by_type(BlockNode):
# Check for a BlockNode with this node's name, and replace it if found. # Check for a BlockNode with this node's name, and replace it if found.
@ -74,7 +84,7 @@ class ExtendsNode(Node):
# add this BlockNode to the parent's ExtendsNode nodelist, so # add this BlockNode to the parent's ExtendsNode nodelist, so
# it'll be checked when the parent node's render() is called. # it'll be checked when the parent node's render() is called.
if parent_is_child: if parent_is_child:
compiled_parent.nodelist[0].nodelist.append(block_node) compiled_parent.nodelist[pos].nodelist.append(block_node)
else: else:
# Keep any existing parents and add a new one. Used by BlockNode. # Keep any existing parents and add a new one. Used by BlockNode.
parent_block.parent = block_node.parent parent_block.parent = block_node.parent

View File

@ -274,5 +274,5 @@ class Client:
Causes the authenticated user to be logged out. Causes the authenticated user to be logged out.
""" """
session = __import__(settings.SESSION_ENGINE, {}, {}, ['']).SessionStore() session = __import__(settings.SESSION_ENGINE, {}, {}, ['']).SessionStore()
session.delete(session_key=self.cookies['sessionid'].value) session.delete(session_key=self.cookies[settings.SESSION_COOKIE_NAME].value)
self.cookies = SimpleCookie() self.cookies = SimpleCookie()

View File

@ -70,7 +70,14 @@ class TestCase(unittest.TestCase):
include a call to super().setUp(). include a call to super().setUp().
""" """
self.client = Client() self.client = Client()
try:
self._pre_setup() self._pre_setup()
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
import sys
result.addError(self, sys.exc_info())
return
super(TestCase, self).__call__(result) super(TestCase, self).__call__(result)
def assertRedirects(self, response, expected_url, status_code=302, def assertRedirects(self, response, expected_url, status_code=302,
@ -103,7 +110,7 @@ class TestCase(unittest.TestCase):
def assertContains(self, response, text, count=None, status_code=200): def assertContains(self, response, text, count=None, status_code=200):
""" """
Asserts that a response indicates that a page was retreived Asserts that a response indicates that a page was retrieved
successfully, (i.e., the HTTP status code was as expected), and that successfully, (i.e., the HTTP status code was as expected), and that
``text`` occurs ``count`` times in the content of the response. ``text`` occurs ``count`` times in the content of the response.
If ``count`` is None, the count doesn't matter - the assertion is true If ``count`` is None, the count doesn't matter - the assertion is true

View File

@ -2,6 +2,9 @@ class MergeDict(object):
""" """
A simple class for creating new "virtual" dictionaries that actually look A simple class for creating new "virtual" dictionaries that actually look
up values in more than one dictionary, passed in the constructor. up values in more than one dictionary, passed in the constructor.
If a key appears in more than one of the passed in dictionaries, only the
first occurrence will be used.
""" """
def __init__(self, *dicts): def __init__(self, *dicts):
self.dicts = dicts self.dicts = dicts
@ -25,11 +28,9 @@ class MergeDict(object):
def getlist(self, key): def getlist(self, key):
for dict_ in self.dicts: for dict_ in self.dicts:
try: if key in dict_.keys():
return dict_.getlist(key) return dict_.getlist(key)
except KeyError: return []
pass
raise KeyError
def items(self): def items(self):
item_list = [] item_list = []

View File

@ -98,5 +98,5 @@ def iri_to_uri(iri):
# section 3.1 of RFC 3987. # section 3.1 of RFC 3987.
if iri is None: if iri is None:
return iri return iri
return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?') return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?*')

View File

@ -53,7 +53,7 @@ class SyndicationFeed(object):
'title': to_unicode(title), 'title': to_unicode(title),
'link': iri_to_uri(link), 'link': iri_to_uri(link),
'description': to_unicode(description), 'description': to_unicode(description),
'language': force_unicode(language), 'language': to_unicode(language),
'author_email': to_unicode(author_email), 'author_email': to_unicode(author_email),
'author_name': to_unicode(author_name), 'author_name': to_unicode(author_name),
'author_link': iri_to_uri(author_link), 'author_link': iri_to_uri(author_link),

View File

@ -102,18 +102,23 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
if middle.startswith('www.') or ('@' not in middle and not middle.startswith('http://') and \ if middle.startswith('www.') or ('@' not in middle and not middle.startswith('http://') and \
len(middle) > 0 and middle[0] in string.ascii_letters + string.digits and \ len(middle) > 0 and middle[0] in string.ascii_letters + string.digits and \
(middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))): (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))):
middle = '<a href="http://%s"%s>%s</a>' % ( middle = 'http://%s' % middle
urlquote(middle, safe='/&=:;#?+'), nofollow_attr,
trim_url(middle))
if middle.startswith('http://') or middle.startswith('https://'): if middle.startswith('http://') or middle.startswith('https://'):
middle = '<a href="%s"%s>%s</a>' % ( url = urlquote(middle, safe='/&=:;#?+*')
urlquote(middle, safe='/&=:;#?+'), nofollow_attr, if autoescape and not safe_input:
trim_url(middle)) url = escape(url)
if '@' in middle and not middle.startswith('www.') and \ trimmed_url = trim_url(middle)
middle = '<a href="%s"%s>%s</a>' % (url, nofollow_attr,
trimmed_url)
elif '@' in middle and not middle.startswith('www.') and \
not ':' in middle and simple_email_re.match(middle): not ':' in middle and simple_email_re.match(middle):
if autoescape:
middle = conditional_escape(middle)
middle = '<a href="mailto:%s">%s</a>' % (middle, middle) middle = '<a href="mailto:%s">%s</a>' % (middle, middle)
if lead + middle + trail != word: if lead + middle + trail != word:
words[i] = lead + middle + trail if autoescape and not safe_input:
lead, trail = escape(lead), escape(trail)
words[i] = mark_safe('%s%s%s' % (lead, middle, trail))
elif autoescape and not safe_input: elif autoescape and not safe_input:
words[i] = escape(word) words[i] = escape(word)
elif safe_input: elif safe_input:

View File

@ -42,7 +42,10 @@ accept_language_re = re.compile(r'''
''', re.VERBOSE) ''', re.VERBOSE)
def to_locale(language, to_lower=False): def to_locale(language, to_lower=False):
"Turns a language name (en-us) into a locale name (en_US)." """
Turns a language name (en-us) into a locale name (en_US). If 'to_lower' is
True, the last component is lower-cased (en_us).
"""
p = language.find('-') p = language.find('-')
if p >= 0: if p >= 0:
if to_lower: if to_lower:
@ -357,19 +360,20 @@ def get_language_from_request(request):
return lang_code return lang_code
accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '') accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
for lang, unused in parse_accept_lang_header(accept): for accept_lang, unused in parse_accept_lang_header(accept):
if lang == '*': if accept_lang == '*':
break break
# We have a very restricted form for our language files (no encoding # We have a very restricted form for our language files (no encoding
# specifier, since they all must be UTF-8 and only one possible # specifier, since they all must be UTF-8 and only one possible
# language each time. So we avoid the overhead of gettext.find() and # language each time. So we avoid the overhead of gettext.find() and
# look up the MO file manually. # work out the MO file manually.
normalized = locale.locale_alias.get(to_locale(lang, True)) # 'normalized' is the root name of the locale in POSIX format (which is
# the format used for the directories holding the MO files).
normalized = locale.locale_alias.get(to_locale(accept_lang, True))
if not normalized: if not normalized:
continue continue
# Remove the default encoding from locale_alias # Remove the default encoding from locale_alias
normalized = normalized.split('.')[0] normalized = normalized.split('.')[0]
@ -378,10 +382,11 @@ def get_language_from_request(request):
# need to check again. # need to check again.
return _accepted[normalized] return _accepted[normalized]
for lang in (normalized, normalized.split('_')[0]): for lang, dirname in ((accept_lang, normalized),
(accept_lang.split('-')[0], normalized.split('_')[0])):
if lang not in supported: if lang not in supported:
continue continue
langfile = os.path.join(globalpath, lang, 'LC_MESSAGES', langfile = os.path.join(globalpath, dirname, 'LC_MESSAGES',
'django.mo') 'django.mo')
if os.path.exists(langfile): if os.path.exists(langfile):
_accepted[normalized] = lang _accepted[normalized] = lang

View File

@ -73,6 +73,12 @@ def technical_500_response(request, exc_type, exc_value, tb):
template_info = None template_info = None
template_does_not_exist = False template_does_not_exist = False
loader_debug_info = None loader_debug_info = None
# Handle deprecated string exceptions
if isinstance(exc_type, basestring):
exc_value = Exception('Deprecated String Exception: %r' % exc_type)
exc_type = type(exc_value)
if issubclass(exc_type, TemplateDoesNotExist): if issubclass(exc_type, TemplateDoesNotExist):
from django.template.loader import template_source_loaders from django.template.loader import template_source_loaders
template_does_not_exist = True template_does_not_exist = True
@ -192,9 +198,11 @@ def _get_lines_from_file(filename, lineno, context_lines, loader=None, module_na
Returns (pre_context_lineno, pre_context, context_line, post_context). Returns (pre_context_lineno, pre_context, context_line, post_context).
""" """
source = None source = None
if loader is not None: if loader is not None and hasattr(loader, "get_source"):
source = loader.get_source(module_name).splitlines() source = loader.get_source(module_name)
else: if source is not None:
source = source.splitlines()
if source is None:
try: try:
f = open(filename) f = open(filename)
try: try:
@ -431,11 +439,11 @@ TECHNICAL_500_TEMPLATE = """
{% if frame.context_line %} {% if frame.context_line %}
<div class="context" id="c{{ frame.id }}"> <div class="context" id="c{{ frame.id }}">
{% if frame.pre_context %} {% if frame.pre_context %}
<ol start="{{ frame.pre_context_lineno }}" class="pre-context" id="pre{{ frame.id }}">{% for line in frame.pre_context %}<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ line|escape }}</li>{% endfor %}</ol> <ol start="{{ frame.pre_context_lineno }}" class="pre-context" id="pre{{ frame.id }}">{% for line in frame.pre_context %}{% if line %}<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ line|escape }}</li>{% endif %}{% endfor %}</ol>
{% endif %} {% endif %}
<ol start="{{ frame.lineno }}" class="context-line"><li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ frame.context_line|escape }} <span>...</span></li></ol> <ol start="{{ frame.lineno }}" class="context-line"><li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ frame.context_line|escape }} <span>...</span></li></ol>
{% if frame.post_context %} {% if frame.post_context %}
<ol start='{{ frame.lineno|add:"1" }}' class="post-context" id="post{{ frame.id }}">{% for line in frame.post_context %}<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ line|escape }}</li>{% endfor %}</ol> <ol start='{{ frame.lineno|add:"1" }}' class="post-context" id="post{{ frame.id }}">{% for line in frame.post_context %}{% if line %}<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ line|escape }}</li>{% endif %}{% endfor %}</ol>
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}

View File

@ -88,7 +88,7 @@ change:
API changes may be necessary. API changes may be necessary.
- Generic relations will most likely be moved out of core and into the - Generic relations will most likely be moved out of core and into the
content-types contrib package to avoid core dependancies on optional content-types contrib package to avoid core dependencies on optional
components. components.
- The comments framework, which is yet undocumented, will likely get a complete - The comments framework, which is yet undocumented, will likely get a complete

View File

@ -215,7 +215,7 @@ each ``TaggedItem`` will have a ``content_object`` field that returns the
object it's related to, and you can also assign to that field or use it when object it's related to, and you can also assign to that field or use it when
creating a ``TaggedItem``:: creating a ``TaggedItem``::
>>> from django.contrib.models.auth import User >>> from django.contrib.auth.models import User
>>> guido = User.objects.get(username='Guido') >>> guido = User.objects.get(username='Guido')
>>> t = TaggedItem(content_object=guido, tag='bdfl') >>> t = TaggedItem(content_object=guido, tag='bdfl')
>>> t.save() >>> t.save()
@ -235,7 +235,7 @@ a "reverse" generic relationship to enable an additional API. For example::
``Bookmark`` instances will each have a ``tags`` attribute, which can ``Bookmark`` instances will each have a ``tags`` attribute, which can
be used to retrieve their associated ``TaggedItems``:: be used to retrieve their associated ``TaggedItems``::
>>> b = Bookmark('http://www.djangoproject.com/') >>> b = Bookmark(url='http://www.djangoproject.com/')
>>> b.save() >>> b.save()
>>> t1 = TaggedItem(content_object=b, tag='django') >>> t1 = TaggedItem(content_object=b, tag='django')
>>> t1.save() >>> t1.save()

View File

@ -5,7 +5,7 @@ Third-party distributions of Django
Several third-party distributors are now providing versions of Django integrated Several third-party distributors are now providing versions of Django integrated
with their package-management systems. These can make installation and upgrading with their package-management systems. These can make installation and upgrading
much easier for users of Django since the integration includes the ability to much easier for users of Django since the integration includes the ability to
automatically install dependancies (like database adapters) that Django automatically install dependencies (like database adapters) that Django
requires. requires.
Typically, these packages are based on the latest stable release of Django, so Typically, these packages are based on the latest stable release of Django, so

View File

@ -767,7 +767,7 @@ a command that can be executed as an action when you run ``manage.py``::
views.py views.py
In this example, the ``explode`` command will be made available to any project In this example, the ``explode`` command will be made available to any project
that includes the ``fancy_blog`` application in ``settings.INSTALLED_APPS``. that includes the ``blog`` application in ``settings.INSTALLED_APPS``.
The ``explode.py`` module has only one requirement -- it must define a class The ``explode.py`` module has only one requirement -- it must define a class
called ``Command`` that extends ``django.core.management.base.BaseCommand``. called ``Command`` that extends ``django.core.management.base.BaseCommand``.

View File

@ -292,6 +292,14 @@ translation string. Example::
In this case, both the tag and the filter will see the already-translated In this case, both the tag and the filter will see the already-translated
string, so they don't need to be aware of translations. string, so they don't need to be aware of translations.
.. note::
In this example, the translation infrastructure will be passed the string
``"yes,no"``, not the individual strings ``"yes"`` and ``"no"``. The
translated string will need to contain the comma so that the filter
parsing code knows how to split up the arguments. For example, a German
translator might translate the string ``"yes,no"`` as ``"ja,nein"``
(keeping the comma intact).
.. _Django templates: ../templates_python/ .. _Django templates: ../templates_python/
Working with lazy translation objects Working with lazy translation objects

View File

@ -138,7 +138,7 @@ Installing a distribution-specific package
Check the `distribution specific notes`_ to see if your Check the `distribution specific notes`_ to see if your
platform/distribution provides official Django packages/installers. platform/distribution provides official Django packages/installers.
Distribution-provided packages will typically allow for automatic Distribution-provided packages will typically allow for automatic
installation of dependancies and easy upgrade paths. installation of dependencies and easy upgrade paths.
Installing an official release Installing an official release
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -113,10 +113,23 @@ postal code or a CPA_.
.. _CPA: http://www.correoargentino.com.ar/consulta_cpa/home.php .. _CPA: http://www.correoargentino.com.ar/consulta_cpa/home.php
ARDNIField
----------
A form field that validates input as a Documento Nacional de Identidad (DNI)
number.
ARCUITField
-----------
A form field that validates input as a Código Único de Identificación
Tributaria (CUIT) number.
ARProvinceSelect ARProvinceSelect
---------------- ----------------
A ``Select`` widget that uses a list of Argentina's provinces as its choices. A ``Select`` widget that uses a list of Argentina's provinces and autonomous
cities as its choices.
Australia (``django.contrib.localflavor.au``) Australia (``django.contrib.localflavor.au``)
============================================= =============================================

View File

@ -384,7 +384,7 @@ The admin represents this as an ``<input type="text">`` (a single-line input).
``IPAddressField`` ``IPAddressField``
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
An IP address, in string format (i.e. "24.124.1.30"). An IP address, in string format (e.g. "192.0.2.30").
The admin represents this as an ``<input type="text">`` (a single-line input). The admin represents this as an ``<input type="text">`` (a single-line input).
@ -952,7 +952,7 @@ the relationship should work. All are optional:
``limit_choices_to`` See the description under ``ForeignKey`` above. ``limit_choices_to`` See the description under ``ForeignKey`` above.
``symmetrical`` Only used in the definition of ManyToManyFields on self. ``symmetrical`` Only used in the definition of ManyToManyFields on self.
Consider the following model: Consider the following model::
class Person(models.Model): class Person(models.Model):
friends = models.ManyToManyField("self") friends = models.ManyToManyField("self")
@ -1872,7 +1872,7 @@ more simply as::
If you define a ``__unicode__()`` method on your model and not a ``__str__()`` If you define a ``__unicode__()`` method on your model and not a ``__str__()``
method, Django will automatically provide you with a ``__str__()`` that calls method, Django will automatically provide you with a ``__str__()`` that calls
``__unicode()__`` and then converts the result correctly to a UTF-8 encoded ``__unicode__()`` and then converts the result correctly to a UTF-8 encoded
string object. This is recommended development practice: define only string object. This is recommended development practice: define only
``__unicode__()`` and let Django take care of the conversion to string objects ``__unicode__()`` and let Django take care of the conversion to string objects
when required. when required.

View File

@ -113,7 +113,7 @@ In addition, each generated form field has attributes set as follows:
``default`` value will be initially selected instead). ``default`` value will be initially selected instead).
Finally, note that you can override the form field used for a given model Finally, note that you can override the form field used for a given model
field. See "Overriding the default field types" below. field. See `Overriding the default field types`_ below.
A full example A full example
-------------- --------------
@ -295,7 +295,7 @@ model fields:
Overriding the default field types Overriding the default field types
---------------------------------- ----------------------------------
The default field types, as described in the "Field types" table above, are The default field types, as described in the `Field types`_ table above, are
sensible defaults. If you have a ``DateField`` in your model, chances are you'd sensible defaults. If you have a ``DateField`` in your model, chances are you'd
want that to be represented as a ``DateField`` in your form. But want that to be represented as a ``DateField`` in your form. But
``ModelForm`` gives you the flexibility of changing the form field type ``ModelForm`` gives you the flexibility of changing the form field type
@ -311,3 +311,48 @@ field, you could do the following::
... ...
... class Meta: ... class Meta:
... model = Article ... model = Article
If you want to override a field's default widget, then specify the ``widget``
parameter when declaring the form field::
>>> class ArticleForm(ModelForm):
... pub_date = DateField(widget=MyDateWidget())
...
... class Meta:
... model = Article
Form inheritance
----------------
As with the basic forms, you can extend and reuse ``ModelForms`` by inheriting
them. Normally, this will be useful if you need to declare some extra fields
or extra methods on a parent class for use in a number of forms derived from
models. For example, using the previous ``ArticleForm`` class::
>>> class EnhancedArticleForm(ArticleForm):
... def clean_pub_date(self):
... ...
This creates a form that behaves identically to ``ArticleForm``, except there
is some extra validation and cleaning for the ``pub_date`` field.
You can also subclass the parent's ``Meta`` inner class if you want to change
the ``Meta.fields`` or ``Meta.excludes`` lists::
>>> class RestrictedArticleForm(EnhancedArticleForm):
... class Meta(ArticleForm.Meta):
... exclude = ['body']
This adds in the extra method from the ``EnhancedArticleForm`` and modifies
the original ``ArticleForm.Meta`` to remove one field.
There are a couple of things to note, however. Most of these won't normally be
of concern unless you are trying to do something tricky with subclassing.
* Normal Python name resolution rules apply. If you have multiple base
classes that declare a ``Meta`` inner class, only the first one will be
used. This means the child's ``Meta``, if it exists, otherwise the
``Meta`` of the first parent, etc.
* For technical reasons, you cannot have a subclass that is inherited from
both a ``ModelForm`` and a ``Form`` simultaneously.

View File

@ -575,6 +575,10 @@ Three things to note about 404 views:
to the template: ``request_path``, which is the URL that resulted to the template: ``request_path``, which is the URL that resulted
in the 404. in the 404.
* The 404 view is passed a ``RequestContext`` and will have access to
variables supplied by your ``TEMPLATE_CONTEXT_PROCESSORS`` (e.g.
``MEDIA_URL``).
* If ``DEBUG`` is set to ``True`` (in your settings module), then your 404 * If ``DEBUG`` is set to ``True`` (in your settings module), then your 404
view will never be used, and the traceback will be displayed instead. view will never be used, and the traceback will be displayed instead.
@ -587,8 +591,9 @@ the view ``django.views.defaults.server_error``, which loads and renders the
template ``500.html``. template ``500.html``.
This means you need to define a ``500.html`` template in your root template This means you need to define a ``500.html`` template in your root template
directory. This template will be used for all server errors. The directory. This template will be used for all server errors. The default 500
default 500 view passes no variables to this template. view passes no variables to this template and is rendered with an empty
``Context`` to lessen the chance of additional errors.
This ``server_error`` view should suffice for 99% of Web applications, but if This ``server_error`` view should suffice for 99% of Web applications, but if
you want to override the view, you can specify ``handler500`` in your you want to override the view, you can specify ``handler500`` in your

View File

@ -22,16 +22,29 @@ Required arguments
Optional arguments Optional arguments
------------------ ------------------
``context`` ``dictionary``
A dictionary of values to add to the template context. By default, this A dictionary of values to add to the template context. By default, this
is an empty dictionary. If a value in the dictionary is callable, the is an empty dictionary. If a value in the dictionary is callable, the
view will call it just before rendering the template. view will call it just before rendering the template.
``context_instance``
The context instance to render the template with. By default, the template
will be rendered with a ``Context`` instance (filled with values from
``dictionary``). If you need to use `context processors`_, you will want to
render the template with a ``RequestContext`` instance instead. Your code
might look something like this::
return render_to_response('my_template.html',
my_data_dictionary,
context_instance=RequestContext(request))
``mimetype`` ``mimetype``
**New in Django development version:** The MIME type to use for the **New in Django development version:** The MIME type to use for the
resulting document. Defaults to the value of the ``DEFAULT_CONTENT_TYPE`` resulting document. Defaults to the value of the ``DEFAULT_CONTENT_TYPE``
setting. setting.
.. _`context processors`: ../templates_python/#subclassing-context-requestcontext
Example Example
------- -------
@ -57,8 +70,6 @@ This example is equivalent to::
r = HttpResponse(t.render(c), r = HttpResponse(t.render(c),
mimetype="application/xhtml+xml") mimetype="application/xhtml+xml")
.. _an HttpResponse object: ../request_response/#httpresponse-objects
``get_object_or_404`` ``get_object_or_404``
===================== =====================

View File

@ -190,6 +190,28 @@ The remaining arguments should be tuples in this format::
...where ``optional dictionary`` and ``optional name`` are optional. (See ...where ``optional dictionary`` and ``optional name`` are optional. (See
`Passing extra options to view functions`_ below.) `Passing extra options to view functions`_ below.)
.. note::
Since `patterns()` is a function call, it accepts a maximum of 255
arguments (URL patterns, in this case). This is a limit for all Python
function calls. This will rarely be problem in practice, since you'll
typically structure your URL patterns modularly by using `include()`
sections. However, on the off-chance you do hit the 255-argument limit,
realise that `patterns()` returns a Python list, so you can split up the
construction of the list.
::
urlpatterns = patterns('',
...
)
urlpatterns += patterns('',
...
)
Python lists have unlimited size, so there's no limit to how many URL
patterns you can construct; merely that you may only create 254 at a time
(the 255-th argument is the initial prefix argument).
url url
--- ---

View File

@ -65,6 +65,13 @@ class TextFile(models.Model):
def __unicode__(self): def __unicode__(self):
return self.description return self.description
class ImageFile(models.Model):
description = models.CharField(max_length=20)
image = models.FileField(upload_to=tempfile.gettempdir())
def __unicode__(self):
return self.description
__test__ = {'API_TESTS': """ __test__ = {'API_TESTS': """
>>> from django import newforms as forms >>> from django import newforms as forms
>>> from django.newforms.models import ModelForm >>> from django.newforms.models import ModelForm
@ -148,29 +155,52 @@ familiar with the mechanics.
... class Meta: ... class Meta:
... model = Category ... model = Category
>>> class BadForm(CategoryForm): >>> class OddForm(CategoryForm):
... class Meta: ... class Meta:
... model = Article ... model = Article
Traceback (most recent call last):
... OddForm is now an Article-related thing, because BadForm.Meta overrides
ImproperlyConfigured: BadForm defines a different model than its parent. CategoryForm.Meta.
>>> OddForm.base_fields.keys()
['headline', 'slug', 'pub_date', 'writer', 'article', 'status', 'categories']
>>> class ArticleForm(ModelForm): >>> class ArticleForm(ModelForm):
... class Meta: ... class Meta:
... model = Article ... model = Article
First class with a Meta class wins.
>>> class BadForm(ArticleForm, CategoryForm): >>> class BadForm(ArticleForm, CategoryForm):
... pass ... pass
Traceback (most recent call last): >>> OddForm.base_fields.keys()
... ['headline', 'slug', 'pub_date', 'writer', 'article', 'status', 'categories']
ImproperlyConfigured: BadForm's base classes define more than one model.
This one is OK since the subclass specifies the same model as the parent. Subclassing without specifying a Meta on the class will use the parent's Meta
(or the first parent in the MRO if there are multiple parent classes).
>>> class SubCategoryForm(CategoryForm): >>> class CategoryForm(ModelForm):
... class Meta: ... class Meta:
... model = Category ... model = Category
>>> class SubCategoryForm(CategoryForm):
... pass
>>> SubCategoryForm.base_fields.keys()
['name', 'slug', 'url']
We can also subclass the Meta inner class to change the fields list.
>>> class CategoryForm(ModelForm):
... checkbox = forms.BooleanField()
...
... class Meta:
... model = Category
>>> class SubCategoryForm(CategoryForm):
... class Meta(CategoryForm.Meta):
... exclude = ['url']
>>> print SubCategoryForm()
<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr>
<tr><th><label for="id_slug">Slug:</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr>
<tr><th><label for="id_checkbox">Checkbox:</label></th><td><input type="checkbox" name="checkbox" id="id_checkbox" /></td></tr>
# Old form_for_x tests ####################################################### # Old form_for_x tests #######################################################
@ -718,7 +748,7 @@ True
... class Meta: ... class Meta:
... model = TextFile ... model = TextFile
Test conditions when files is either not given or empty. # Test conditions when files is either not given or empty.
>>> f = TextFileForm(data={'description': u'Assistance'}) >>> f = TextFileForm(data={'description': u'Assistance'})
>>> f.is_valid() >>> f.is_valid()
@ -727,7 +757,7 @@ False
>>> f.is_valid() >>> f.is_valid()
False False
Upload a file and ensure it all works as expected. # Upload a file and ensure it all works as expected.
>>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': {'filename': 'test1.txt', 'content': 'hello world'}}) >>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': {'filename': 'test1.txt', 'content': 'hello world'}})
>>> f.is_valid() >>> f.is_valid()
@ -738,8 +768,8 @@ True
>>> instance.file >>> instance.file
u'.../test1.txt' u'.../test1.txt'
Edit an instance that already has the file defined in the model. This will not # Edit an instance that already has the file defined in the model. This will not
save the file again, but leave it exactly as it is. # save the file again, but leave it exactly as it is.
>>> f = TextFileForm(data={'description': u'Assistance'}, instance=instance) >>> f = TextFileForm(data={'description': u'Assistance'}, instance=instance)
>>> f.is_valid() >>> f.is_valid()
@ -750,11 +780,11 @@ u'.../test1.txt'
>>> instance.file >>> instance.file
u'.../test1.txt' u'.../test1.txt'
Delete the current file since this is not done by Django. # Delete the current file since this is not done by Django.
>>> os.unlink(instance.get_file_filename()) >>> os.unlink(instance.get_file_filename())
Override the file by uploading a new one. # Override the file by uploading a new one.
>>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': {'filename': 'test2.txt', 'content': 'hello world'}}, instance=instance) >>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': {'filename': 'test2.txt', 'content': 'hello world'}}, instance=instance)
>>> f.is_valid() >>> f.is_valid()
@ -765,7 +795,7 @@ u'.../test2.txt'
>>> instance.delete() >>> instance.delete()
Test the non-required FileField # Test the non-required FileField
>>> f = TextFileForm(data={'description': u'Assistance'}) >>> f = TextFileForm(data={'description': u'Assistance'})
>>> f.fields['file'].required = False >>> f.fields['file'].required = False
@ -782,4 +812,71 @@ True
>>> instance.file >>> instance.file
u'.../test3.txt' u'.../test3.txt'
>>> instance.delete() >>> instance.delete()
# ImageField ###################################################################
# ImageField and FileField are nearly identical, but they differ slighty when
# it comes to validation. This specifically tests that #6302 is fixed for
# both file fields and image fields.
>>> class ImageFileForm(ModelForm):
... class Meta:
... model = ImageFile
>>> image_data = open(os.path.join(os.path.dirname(__file__), "test.png")).read()
>>> f = ImageFileForm(data={'description': u'An image'}, files={'image': {'filename': 'test.png', 'content': image_data}})
>>> f.is_valid()
True
>>> type(f.cleaned_data['image'])
<class 'django.newforms.fields.UploadedFile'>
>>> instance = f.save()
>>> instance.image
u'.../test.png'
# Edit an instance that already has the image defined in the model. This will not
# save the image again, but leave it exactly as it is.
>>> f = ImageFileForm(data={'description': u'Look, it changed'}, instance=instance)
>>> f.is_valid()
True
>>> f.cleaned_data['image']
u'.../test.png'
>>> instance = f.save()
>>> instance.image
u'.../test.png'
# Delete the current image since this is not done by Django.
>>> os.unlink(instance.get_image_filename())
# Override the file by uploading a new one.
>>> f = ImageFileForm(data={'description': u'Changed it'}, files={'image': {'filename': 'test2.png', 'content': image_data}}, instance=instance)
>>> f.is_valid()
True
>>> instance = f.save()
>>> instance.image
u'.../test2.png'
>>> instance.delete()
# Test the non-required ImageField
>>> f = ImageFileForm(data={'description': u'Test'})
>>> f.fields['image'].required = False
>>> f.is_valid()
True
>>> instance = f.save()
>>> instance.image
''
>>> f = ImageFileForm(data={'description': u'And a final one'}, files={'image': {'filename': 'test3.png', 'content': image_data}}, instance=instance)
>>> f.is_valid()
True
>>> instance = f.save()
>>> instance.image
u'.../test3.png'
>>> instance.delete()
"""} """}

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

View File

@ -2,8 +2,8 @@
6. Specifying ordering 6. Specifying ordering
Specify default ordering for a model using the ``ordering`` attribute, which Specify default ordering for a model using the ``ordering`` attribute, which
should be a list or tuple of field names. This tells Django how to order the should be a list or tuple of field names. This tells Django how to order
results of ``get_list()`` and other similar functions. queryset results.
If a field name in ``ordering`` starts with a hyphen, that field will be If a field name in ``ordering`` starts with a hyphen, that field will be
ordered in descending order. Otherwise, it'll be ordered in ascending order. ordered in descending order. Otherwise, it'll be ordered in ascending order.

View File

@ -13,8 +13,16 @@ class Person(models.Model):
return u"%s %s" % (self.first_name, self.last_name) return u"%s %s" % (self.first_name, self.last_name)
def pre_save_nokwargs_test(sender, instance):
print 'pre_save_nokwargs signal'
def post_save_nokwargs_test(sender, instance):
print 'post_save_nokwargs signal'
def pre_save_test(sender, instance, **kwargs): def pre_save_test(sender, instance, **kwargs):
print 'pre_save signal,', instance print 'pre_save signal,', instance
if kwargs.get('raw'):
print 'Is raw'
def post_save_test(sender, instance, **kwargs): def post_save_test(sender, instance, **kwargs):
print 'post_save signal,', instance print 'post_save signal,', instance
@ -23,6 +31,8 @@ def post_save_test(sender, instance, **kwargs):
print 'Is created' print 'Is created'
else: else:
print 'Is updated' print 'Is updated'
if kwargs.get('raw'):
print 'Is raw'
def pre_delete_test(sender, instance, **kwargs): def pre_delete_test(sender, instance, **kwargs):
print 'pre_delete signal,', instance print 'pre_delete signal,', instance
@ -33,6 +43,8 @@ def post_delete_test(sender, instance, **kwargs):
print 'instance.id is None: %s' % (instance.id == None) print 'instance.id is None: %s' % (instance.id == None)
__test__ = {'API_TESTS':""" __test__ = {'API_TESTS':"""
>>> dispatcher.connect(pre_save_nokwargs_test, signal=models.signals.pre_save)
>>> dispatcher.connect(post_save_nokwargs_test, signal=models.signals.post_save)
>>> dispatcher.connect(pre_save_test, signal=models.signals.pre_save) >>> dispatcher.connect(pre_save_test, signal=models.signals.pre_save)
>>> dispatcher.connect(post_save_test, signal=models.signals.post_save) >>> dispatcher.connect(post_save_test, signal=models.signals.post_save)
>>> dispatcher.connect(pre_delete_test, signal=models.signals.pre_delete) >>> dispatcher.connect(pre_delete_test, signal=models.signals.pre_delete)
@ -40,16 +52,29 @@ __test__ = {'API_TESTS':"""
>>> p1 = Person(first_name='John', last_name='Smith') >>> p1 = Person(first_name='John', last_name='Smith')
>>> p1.save() >>> p1.save()
pre_save_nokwargs signal
pre_save signal, John Smith pre_save signal, John Smith
post_save_nokwargs signal
post_save signal, John Smith post_save signal, John Smith
Is created Is created
>>> p1.first_name = 'Tom' >>> p1.first_name = 'Tom'
>>> p1.save() >>> p1.save()
pre_save_nokwargs signal
pre_save signal, Tom Smith pre_save signal, Tom Smith
post_save_nokwargs signal
post_save signal, Tom Smith post_save signal, Tom Smith
Is updated Is updated
>>> p1.save(raw=True)
pre_save_nokwargs signal
pre_save signal, Tom Smith
Is raw
post_save_nokwargs signal
post_save signal, Tom Smith
Is updated
Is raw
>>> p1.delete() >>> p1.delete()
pre_delete signal, Tom Smith pre_delete signal, Tom Smith
instance.id is not None: True instance.id is not None: True
@ -59,13 +84,17 @@ instance.id is None: False
>>> p2 = Person(first_name='James', last_name='Jones') >>> p2 = Person(first_name='James', last_name='Jones')
>>> p2.id = 99999 >>> p2.id = 99999
>>> p2.save() >>> p2.save()
pre_save_nokwargs signal
pre_save signal, James Jones pre_save signal, James Jones
post_save_nokwargs signal
post_save signal, James Jones post_save signal, James Jones
Is created Is created
>>> p2.id = 99998 >>> p2.id = 99998
>>> p2.save() >>> p2.save()
pre_save_nokwargs signal
pre_save signal, James Jones pre_save signal, James Jones
post_save_nokwargs signal
post_save signal, James Jones post_save signal, James Jones
Is created Is created
@ -78,6 +107,8 @@ instance.id is None: False
>>> Person.objects.all() >>> Person.objects.all()
[<Person: James Jones>] [<Person: James Jones>]
>>> dispatcher.disconnect(pre_save_nokwargs_test, signal=models.signals.pre_save)
>>> dispatcher.disconnect(post_save_nokwargs_test, signal=models.signals.post_save)
>>> dispatcher.disconnect(post_delete_test, signal=models.signals.post_delete) >>> dispatcher.disconnect(post_delete_test, signal=models.signals.post_delete)
>>> dispatcher.disconnect(pre_delete_test, signal=models.signals.pre_delete) >>> dispatcher.disconnect(pre_delete_test, signal=models.signals.pre_delete)
>>> dispatcher.disconnect(post_save_test, signal=models.signals.post_save) >>> dispatcher.disconnect(post_save_test, signal=models.signals.post_save)

View File

@ -20,6 +20,19 @@
>>> md2['chris'] >>> md2['chris']
'cool' 'cool'
MergeDict can merge MultiValueDicts
>>> multi1 = MultiValueDict({'key1': ['value1'], 'key2': ['value2', 'value3']})
>>> multi2 = MultiValueDict({'key2': ['value4'], 'key4': ['value5', 'value6']})
>>> mm = MergeDict(multi1, multi2)
# Although 'key2' appears in both dictionaries, only the first value is used.
>>> mm.getlist('key2')
['value2', 'value3']
>>> mm.getlist('key4')
['value5', 'value6']
>>> mm.getlist('undefined')
[]
### MultiValueDict ########################################################## ### MultiValueDict ##########################################################
>>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']}) >>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']})

View File

@ -1,7 +1,14 @@
import sys
tests = """ tests = """
>>> from django.utils.translation.trans_real import parse_accept_lang_header >>> from django.utils.translation.trans_real import parse_accept_lang_header
>>> p = parse_accept_lang_header >>> p = parse_accept_lang_header
#
# Testing HTTP header parsing. First, we test that we can parse the values
# according to the spec (and that we extract all the pieces in the right order).
#
Good headers. Good headers.
>>> p('de') >>> p('de')
[('de', 1.0)] [('de', 1.0)]
@ -54,4 +61,53 @@ Bad headers; should always return [].
>>> p('') >>> p('')
[] []
#
# Now test that we parse a literal HTTP header correctly.
#
>>> from django.utils.translation.trans_real import get_language_from_request
>>> g = get_language_from_request
>>> from django.http import HttpRequest
>>> r = HttpRequest
>>> r.COOKIES = {}
These tests assumes the es, es_AR, pt and pt_BR translations exit in the Django
source tree.
>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'pt-br'}
>>> g(r)
'pt-br'
>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'pt'}
>>> g(r)
'pt'
>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es,de'}
>>> g(r)
'es'
>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es-ar,de'}
>>> g(r)
'es-ar'
"""
# Python 2.3 returns slightly different results for completely bogus locales,
# so we omit this test for that anything below 2.4. It's relatively harmless in
# any cases (GIGO). This also means this won't be executed on Jython currently,
# but life's like that sometimes.
if sys.version_info >= (2, 4):
tests += """
This test assumes there won't be a Django translation to a US variation
of the Spanish language, a safe assumption. When the user sets it
as the preferred language, the main 'es' translation should be selected
instead.
>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es-us'}
>>> g(r)
'es'
"""
tests += """
This tests the following scenario: there isn't a main language (zh)
translation of Django but there is a translation to variation (zh_CN)
the user sets zh-cn as the preferred language, it should be selected by
Django without falling back nor ignoring it.
>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,de'}
>>> g(r)
'zh-cn'
""" """

View File

@ -98,8 +98,8 @@ def get_filter_tests():
'filter-upper01': ('{% autoescape off %}{{ a|upper }} {{ b|upper }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a &amp; b")}, u"A & B A &AMP; B"), 'filter-upper01': ('{% autoescape off %}{{ a|upper }} {{ b|upper }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a &amp; b")}, u"A & B A &AMP; B"),
'filter-upper02': ('{{ a|upper }} {{ b|upper }}', {"a": "a & b", "b": mark_safe("a &amp; b")}, u"A &amp; B A &amp;AMP; B"), 'filter-upper02': ('{{ a|upper }} {{ b|upper }}', {"a": "a & b", "b": mark_safe("a &amp; b")}, u"A &amp; B A &amp;AMP; B"),
'filter-urlize01': ('{% autoescape off %}{{ a|urlize }} {{ b|urlize }}{% endautoescape %}', {"a": "http://example.com/x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/x=&y=" rel="nofollow">http://example.com/x=&y=</a> <a href="http://example.com?x=&y=" rel="nofollow">http://example.com?x=&y=</a>'), 'filter-urlize01': ('{% autoescape off %}{{ a|urlize }} {{ b|urlize }}{% endautoescape %}', {"a": "http://example.com/?x=&y=", "b": mark_safe("http://example.com?x=&amp;y=")}, u'<a href="http://example.com/?x=&y=" rel="nofollow">http://example.com/?x=&y=</a> <a href="http://example.com?x=&amp;y=" rel="nofollow">http://example.com?x=&amp;y=</a>'),
'filter-urlize02': ('{{ a|urlize }} {{ b|urlize }}', {"a": "http://example.com/x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/x=&y=" rel="nofollow">http://example.com/x=&amp;y=</a> <a href="http://example.com?x=&y=" rel="nofollow">http://example.com?x=&y=</a>'), 'filter-urlize02': ('{{ a|urlize }} {{ b|urlize }}', {"a": "http://example.com/?x=&y=", "b": mark_safe("http://example.com?x=&amp;y=")}, u'<a href="http://example.com/?x=&amp;y=" rel="nofollow">http://example.com/?x=&amp;y=</a> <a href="http://example.com?x=&amp;y=" rel="nofollow">http://example.com?x=&amp;y=</a>'),
'filter-urlize03': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": mark_safe("a &amp; b")}, 'a &amp; b'), 'filter-urlize03': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": mark_safe("a &amp; b")}, 'a &amp; b'),
'filter-urlize04': ('{{ a|urlize }}', {"a": mark_safe("a &amp; b")}, 'a &amp; b'), 'filter-urlize04': ('{{ a|urlize }}', {"a": mark_safe("a &amp; b")}, 'a &amp; b'),
@ -108,8 +108,12 @@ def get_filter_tests():
'filter-urlize05': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": "<script>alert('foo')</script>"}, "<script>alert('foo')</script>"), 'filter-urlize05': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": "<script>alert('foo')</script>"}, "<script>alert('foo')</script>"),
'filter-urlize06': ('{{ a|urlize }}', {"a": "<script>alert('foo')</script>"}, '&lt;script&gt;alert(&#39;foo&#39;)&lt;/script&gt;'), 'filter-urlize06': ('{{ a|urlize }}', {"a": "<script>alert('foo')</script>"}, '&lt;script&gt;alert(&#39;foo&#39;)&lt;/script&gt;'),
'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'), # mailto: testing for urlize
'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&y=')}, u'&quot;Unsafe&quot; <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'), 'filter-urlize07': ('{{ a|urlize }}', {"a": "Email me at me@example.com"}, 'Email me at <a href="mailto:me@example.com">me@example.com</a>'),
'filter-urlize08': ('{{ a|urlize }}', {"a": "Email me at <me@example.com>"}, 'Email me at &lt;<a href="mailto:me@example.com">me@example.com</a>&gt;'),
'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&amp;y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&amp;y=" rel="nofollow">http:...</a>'),
'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&amp;y=')}, u'&quot;Unsafe&quot; <a href="http://example.com/x=&amp;y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&amp;y=" rel="nofollow">http:...</a>'),
'filter-wordcount01': ('{% autoescape off %}{{ a|wordcount }} {{ b|wordcount }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a &amp; b")}, "3 3"), 'filter-wordcount01': ('{% autoescape off %}{{ a|wordcount }} {{ b|wordcount }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a &amp; b")}, "3 3"),
'filter-wordcount02': ('{{ a|wordcount }} {{ b|wordcount }}', {"a": "a & b", "b": mark_safe("a &amp; b")}, "3 3"), 'filter-wordcount02': ('{{ a|wordcount }} {{ b|wordcount }}', {"a": "a & b", "b": mark_safe("a &amp; b")}, "3 3"),

View File

@ -736,7 +736,7 @@ class Templates(unittest.TestCase):
'i18n09': ('{% load i18n %}{% trans "Page not found" noop %}', {'LANGUAGE_CODE': 'de'}, "Page not found"), 'i18n09': ('{% load i18n %}{% trans "Page not found" noop %}', {'LANGUAGE_CODE': 'de'}, "Page not found"),
# translation of a variable with a translated filter # translation of a variable with a translated filter
'i18n10': ('{{ bool|yesno:_("ja,nein") }}', {'bool': True}, 'ja'), 'i18n10': ('{{ bool|yesno:_("yes,no,maybe") }}', {'bool': True, 'LANGUAGE_CODE': 'de'}, 'Ja'),
# translation of a variable with a non-translated filter # translation of a variable with a non-translated filter
'i18n11': ('{{ bool|yesno:"ja,nein" }}', {'bool': True}, 'ja'), 'i18n11': ('{{ bool|yesno:"ja,nein" }}', {'bool': True}, 'ja'),