Changeset 6637
- Timestamp:
- 11/02/07 21:15:27 (1 year ago)
- Files:
-
- django/branches/queryset-refactor/django/conf/locale/es/LC_MESSAGES/django.mo (modified) (previous)
- django/branches/queryset-refactor/django/conf/locale/es/LC_MESSAGES/django.po (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/auth/forms.py (modified) (1 diff)
- django/branches/queryset-refactor/django/core/management/commands/startapp.py (modified) (2 diffs)
- django/branches/queryset-refactor/django/core/management/__init__.py (modified) (1 diff)
- django/branches/queryset-refactor/django/db/backends/__init__.py (modified) (1 diff)
- django/branches/queryset-refactor/django/db/backends/postgresql_psycopg2/base.py (modified) (2 diffs)
- django/branches/queryset-refactor/django/db/backends/util.py (modified) (5 diffs)
- django/branches/queryset-refactor/django/newforms/fields.py (modified) (4 diffs)
- django/branches/queryset-refactor/django/utils/translation/trans_real.py (modified) (4 diffs)
- django/branches/queryset-refactor/docs/django-admin.txt (modified) (1 diff)
- django/branches/queryset-refactor/tests/regressiontests/forms/regressions.py (modified) (1 diff)
- django/branches/queryset-refactor/tests/regressiontests/i18n/misc.py (added)
- django/branches/queryset-refactor/tests/regressiontests/i18n/tests.py (modified) (2 diffs)
- django/branches/queryset-refactor/tests/regressiontests/templates/urls.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/queryset-refactor/django/conf/locale/es/LC_MESSAGES/django.po
r6597 r6637 1017 1017 #: contrib/admin/views/main.py:780 1018 1018 msgid "Database error" 1019 msgstr "Er orr en la base de datos"1019 msgstr "Error en la base de datos" 1020 1020 1021 1021 #: contrib/auth/forms.py:17 django/branches/queryset-refactor/django/contrib/auth/forms.py
r5803 r6637 105 105 'user': user, 106 106 } 107 send_mail( 'Password reset on %s'% site_name, t.render(Context(c)), None, [user.email])107 send_mail(_('Password reset on %s') % site_name, t.render(Context(c)), None, [user.email]) 108 108 109 109 class PasswordChangeForm(oldforms.Manipulator): django/branches/queryset-refactor/django/core/management/commands/startapp.py
r6466 r6637 1 from django.core.management.base import copy_helper, CommandError, LabelCommand2 1 import os 3 2 3 from django.core.management.base import copy_helper, CommandError, LabelCommand 4 4 5 class Command(LabelCommand): 5 help = "Creates a Django app directory structure for the given app name in the current directory." 6 help = ("Creates a Django app directory structure for the given app name" 7 " in the current directory.") 6 8 args = "[appname]" 7 9 label = 'application name' … … 15 17 if directory is None: 16 18 directory = os.getcwd() 17 # Determine the project_name a bit naively -- by looking at the name of 18 # the parent directory. 19 project_dir = os.path.normpath(os.path.join(directory, os.pardir)) 20 parent_dir = os.path.basename(project_dir) 19 # Determine the project_name by using the basename of directory, 20 # which should be the full path of the project directory (or the 21 # current directory if no directory was passed). 21 22 project_name = os.path.basename(directory) 22 23 if app_name == project_name: 23 raise CommandError("You cannot create an app with the same name (%r) as your project." % app_name) 24 copy_helper(self.style, 'app', app_name, directory, parent_dir) 24 raise CommandError("You cannot create an app with the same name" 25 " (%r) as your project." % app_name) 26 copy_helper(self.style, 'app', app_name, directory, project_name) 25 27 26 28 class ProjectCommand(Command): 27 help = "Creates a Django app directory structure for the given app name in this project's directory." 29 help = ("Creates a Django app directory structure for the given app name" 30 " in this project's directory.") 28 31 29 32 def __init__(self, project_directory): django/branches/queryset-refactor/django/core/management/__init__.py
r6597 r6637 243 243 Configures the runtime environment. This can also be used by external 244 244 scripts wanting to set up a similar environment to manage.py. 245 Returns the project directory (assuming the passed settings module is 246 directly in the project directory). 245 247 """ 246 248 # Add this project to sys.path so that it's importable in the conventional django/branches/queryset-refactor/django/db/backends/__init__.py
r6335 r6637 128 128 raise NotImplementedError('Full-text search is not implemented for this database backend') 129 129 130 def last_executed_query(self, cursor, sql, params): 131 """ 132 Returns a string of the query last executed by the given cursor, with 133 placeholders replaced with actual values. 134 135 `sql` is the raw query containing placeholders, and `params` is the 136 sequence of parameters. These are used by default, but this method 137 exists for database backends to provide a better implementation 138 according to their own quoting schemes. 139 """ 140 from django.utils.encoding import smart_unicode, force_unicode 141 142 # Convert params to contain Unicode values. 143 to_unicode = lambda s: force_unicode(s, strings_only=True) 144 if isinstance(params, (list, tuple)): 145 u_params = tuple([to_unicode(val) for val in params]) 146 else: 147 u_params = dict([(to_unicode(k), to_unicode(v)) for k, v in params.items()]) 148 149 return smart_unicode(sql) % u_params 150 130 151 def last_insert_id(self, cursor, table_name, pk_name): 131 152 """ django/branches/queryset-refactor/django/db/backends/postgresql_psycopg2/base.py
r6012 r6637 6 6 7 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures 8 from django.db.backends.postgresql.operations import DatabaseOperations 8 from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations 9 9 try: 10 10 import psycopg2 as Database … … 21 21 class DatabaseFeatures(BaseDatabaseFeatures): 22 22 needs_datetime_string_cast = False 23 24 class DatabaseOperations(PostgresqlDatabaseOperations): 25 def last_executed_query(self, cursor, sql, params): 26 # With psycopg2, cursor objects have a "query" attribute that is the 27 # exact query sent to the database. See docs here: 28 # http://www.initd.org/tracker/psycopg/wiki/psycopg2_documentation#postgresql-status-message-and-executed-query 29 return cursor.query 23 30 24 31 class DatabaseWrapper(BaseDatabaseWrapper): django/branches/queryset-refactor/django/db/backends/util.py
r5971 r6637 2 2 import md5 3 3 from time import time 4 from django.utils.encoding import smart_unicode, force_unicode5 4 6 5 try: … … 12 11 def __init__(self, cursor, db): 13 12 self.cursor = cursor 14 self.db = db 13 self.db = db # Instance of a BaseDatabaseWrapper subclass 15 14 16 15 def execute(self, sql, params=()): … … 20 19 finally: 21 20 stop = time() 21 sql = self.db.ops.last_executed_query(self.cursor, sql, params) 22 22 self.db.queries.append({ 23 'sql': s mart_unicode(sql) % convert_args(params),23 'sql': sql, 24 24 'time': "%.3f" % (stop - start), 25 25 }) … … 32 32 stop = time() 33 33 self.db.queries.append({ 34 'sql': ' MANY: ' + sql + ' ' + smart_unicode(tuple(param_list)),34 'sql': '%s times: %s' % (len(param_list), sql), 35 35 'time': "%.3f" % (stop - start), 36 36 }) … … 41 41 else: 42 42 return getattr(self.cursor, attr) 43 44 def convert_args(args):45 """46 Convert sequence or dictionary to contain unicode values.47 """48 to_unicode = lambda s: force_unicode(s, strings_only=True)49 if isinstance(args, (list, tuple)):50 return tuple([to_unicode(val) for val in args])51 else:52 return dict([(to_unicode(k), to_unicode(v)) for k, v in args.items()])53 43 54 44 ############################################### django/branches/queryset-refactor/django/newforms/fields.py
r6597 r6637 1 1 """ 2 Field classes 2 Field classes. 3 3 """ 4 4 … … 7 7 import re 8 8 import time 9 10 from django.utils.translation import ugettext 11 from django.utils.encoding import StrAndUnicode, smart_unicode 12 13 from util import ErrorList, ValidationError 14 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput 15 9 # Python 2.3 fallbacks 16 10 try: 17 11 from decimal import Decimal, DecimalException 18 12 except ImportError: 19 13 from django.utils._decimal import Decimal, DecimalException 14 try: 15 set 16 except NameError: 17 from sets import Set as set 18 19 from django.utils.translation import ugettext 20 from django.utils.encoding import StrAndUnicode, smart_unicode 21 22 from util import ErrorList, ValidationError 23 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput 24 20 25 21 26 __all__ = ( … … 24 29 'DEFAULT_TIME_INPUT_FORMATS', 'TimeField', 25 30 'DEFAULT_DATETIME_INPUT_FORMATS', 'DateTimeField', 26 'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField', 'BooleanField',27 ' ChoiceField', 'NullBooleanField', 'MultipleChoiceField',31 'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField', 32 'BooleanField', 'NullBooleanField', 'ChoiceField', 'MultipleChoiceField', 28 33 'ComboField', 'MultiValueField', 'FloatField', 'DecimalField', 29 34 'SplitDateTimeField', 'IPAddressField', … … 33 38 EMPTY_VALUES = (None, '') 34 39 35 try:36 set37 except NameError:38 from sets import Set as set # Python 2.3 fallback39 40 try:41 from decimal import Decimal42 except ImportError:43 from django.utils._decimal import Decimal # Python 2.3 fallback44 40 45 41 class Field(object): django/branches/queryset-refactor/django/utils/translation/trans_real.py
r6597 r6637 1 1 "Translation helper functions" 2 2 3 import os, re, sys 3 import locale 4 import os 5 import re 6 import sys 4 7 import gettext as gettext_module 5 8 from cStringIO import StringIO 9 6 10 from django.utils.encoding import force_unicode 7 11 … … 26 30 _default = None 27 31 28 # This is a cache for accept-header to translation object mappings to prevent29 # the accept parser to run multiple times for one user.32 # This is a cache for normalised accept-header languages to prevent multiple 33 # file lookups when checking the same locale on repeated requests. 30 34 _accepted = {} 31 35 32 def to_locale(language): 36 # Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9. 37 accept_language_re = re.compile(r''' 38 ([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*) # "en", "en-au", "x-y-z", "*" 39 (?:;q=(0(?:\.\d{,3})?|1(?:.0{,3})?))? # Optional "q=1.00", "q=0.8" 40 (?:\s*,\s*|$) # Multiple accepts per header. 41 ''', re.VERBOSE) 42 43 def to_locale(language, to_lower=False): 33 44 "Turns a language name (en-us) into a locale name (en_US)." 34 45 p = language.find('-') 35 46 if p >= 0: 36 return language[:p].lower()+'_'+language[p+1:].upper() 47 if to_lower: 48 return language[:p].lower()+'_'+language[p+1:].lower() 49 else: 50 return language[:p].lower()+'_'+language[p+1:].upper() 37 51 else: 38 52 return language.lower() … … 335 349 return lang_code 336 350 337 lang_code = request.COOKIES.get('django_language' , None)338 if lang_code in supported and lang_code is not Noneand check_for_language(lang_code):351 lang_code = request.COOKIES.get('django_language') 352 if lang_code and lang_code in supported and check_for_language(lang_code): 339 353 return lang_code 340 354 341 accept = request.META.get('HTTP_ACCEPT_LANGUAGE', None) 342 if accept is not None: 343 344 t = _accepted.get(accept, None) 345 if t is not None: 346 return t 347 348 def _parsed(el): 349 p = el.find(';q=') 350 if p >= 0: 351 lang = el[:p].strip() 352 order = int(float(el[p+3:].strip())*100) 353 else: 354 lang = el 355 order = 100 356 p = lang.find('-') 357 if p >= 0: 358 mainlang = lang[:p] 359 else: 360 mainlang = lang 361 return (lang, mainlang, order) 362 363 langs = [_parsed(el) for el in accept.split(',')] 364 langs.sort(lambda a,b: -1*cmp(a[2], b[2])) 365 366 for lang, mainlang, order in langs: 367 if lang in supported or mainlang in supported: 368 langfile = gettext_module.find('django', globalpath, [to_locale(lang)]) 369 if langfile: 370 # reconstruct the actual language from the language 371 # filename, because otherwise we might incorrectly 372 # report de_DE if we only have de available, but 373 # did find de_DE because of language normalization 374 lang = langfile[len(globalpath):].split(os.path.sep)[1] 375 _accepted[accept] = lang 376 return lang 355 accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '') 356 for lang, unused in parse_accept_lang_header(accept): 357 if lang == '*': 358 break 359 360 # We have a very restricted form for our language files (no encoding 361 # specifier, since they all must be UTF-8 and only one possible 362 # language each time. So we avoid the overhead of gettext.find() and 363 # look up the MO file manually. 364 365 normalized = locale.locale_alias.get(to_locale(lang, True)) 366 if not normalized: 367 continue 368 369 # Remove the default encoding from locale_alias 370 normalized = normalized.split('.')[0] 371 372 if normalized in _accepted: 373 # We've seen this locale before and have an MO file for it, so no 374 # need to check again. 375 return _accepted[normalized] 376 377 for lang in (normalized, normalized.split('_')[0]): 378 if lang not in supported: 379 continue 380 langfile = os.path.join(globalpath, lang, 'LC_MESSAGES', 381 'django.mo') 382 if os.path.exists(langfile): 383 _accepted[normalized] = lang 384 return lang 377 385 378 386 return settings.LANGUAGE_CODE … … 506 514 return out.getvalue() 507 515 516 def parse_accept_lang_header(lang_string): 517 """ 518 Parses the lang_string, which is the body of an HTTP Accept-Language 519 header, and returns a list of (lang, q-value), ordered by 'q' values. 520 521 Any format errors in lang_string results in an empty list being returned. 522 """ 523 result = [] 524 pieces = accept_language_re.split(lang_string) 525 if pieces[-1]: 526 return [] 527 for i in range(0, len(pieces) - 1, 3): 528 first, lang, priority = pieces[i : i + 3] 529 if first: 530 return [] 531 priority = priority and float(priority) or 1.0 532 result.append((lang, priority)) 533 result.sort(lambda x, y: -cmp(x[1], y[1])) 534 return result 535 django/branches/queryset-refactor/docs/django-admin.txt
r6466 r6637 742 742 **New in Django development version** 743 743 744 If you want to add an action of your own to ``manage.py``, you can. 745 Simply add a ``management/commands`` directory to your application. 746 Each python module in that directory will be discovered and registered as 744 Applications can register their own actions with ``manage.py``. For example, 745 you might want to add a ``manage.py`` action for a Django app that you're 746 distributing. 747 748 To do this, just add a ``management/commands`` directory to your application. 749 Each Python module in that directory will be auto-discovered and registered as 747 750 a command that can be executed as an action when you run ``manage.py``:: 748 751 749 /fancy_blog752 blog/ 750 753 __init__.py 751 754 models.py 752 /management755 management/ 753 756 __init__.py 754 /commands757 commands/ 755 758 __init__.py 756 759 explode.py 757 760 views.py 758 761 759 In this example, ``explode`` command will be made available to any project762 In this example, the ``explode`` command will be made available to any project 760 763 that includes the ``fancy_blog`` application in ``settings.INSTALLED_APPS``. 761 764 django/branches/queryset-refactor/tests/regressiontests/forms/regressions.py
r6382 r6637 27 27 early and still send back the right translation. 28 28 29 # XFAIL30 29 >>> activate('de') 31 30 >>> print f.as_p() django/branches/queryset-refactor/tests/regressiontests/i18n/tests.py
r6466 r6637 1 1 # coding: utf-8 2 import misc 2 3 3 ur"""4 regressions = ur""" 4 5 Format string interpolation should work with *_lazy objects. 5 6 … … 40 41 u'django' 41 42 """ 43 44 __test__ = { 45 'regressions': regressions, 46 'misc': misc.tests, 47 } django/branches/queryset-refactor/tests/regressiontests/templates/urls.py
r5876 r6637 8 8 (r'^$', views.index), 9 9 (r'^client/(\d+)/$', views.client), 10 (r'^client/( \d+)/(?P<action>[^/]+)/$', views.client_action),10 (r'^client/(?P<id>\d+)/(?P<action>[^/]+)/$', views.client_action), 11 11 url(r'^named-client/(\d+)/$', views.client, name="named.client"), 12 12
