Django

Code

Changeset 3523

Show
Ignore:
Timestamp:
08/04/06 18:27:18 (2 years ago)
Author:
jpellerin
Message:

[multi-db] Merge trunk to [3522]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/multiple-db-support/AUTHORS

    r3502 r3523  
    7171    gandalf@owca.info 
    7272    Baishampayan Ghose 
     73    martin.glueck@gmail.com 
     74    Simon Greenhill <dev@simon.net.nz> 
    7375    Espen Grindhaug <http://grindhaug.org/> 
    7476    Brant Harris 
  • django/branches/multiple-db-support/django/conf/locale/ru/LC_MESSAGES/django.po

    r3151 r3523  
    142142 
    143143#: contrib/comments/models.py:237 
     144#, fuzzy 
    144145msgid "karma score" 
    145146msgstr "Карма счёт" 
     
    736737#, python-format 
    737738msgid "Models available in the %(name)s application." 
    738 msgstr "Модели доступны в %(name)s приложении." 
     739msgstr "Модели доступны в %(name) приложении." 
    739740 
    740741#: contrib/admin/templates/admin/index.html:28 
  • django/branches/multiple-db-support/django/conf/urls/defaults.py

    r411 r3523  
    1111    pattern_list = [] 
    1212    for t in tuples: 
    13         if type(t[1]) == list: 
    14             pattern_list.append(RegexURLResolver(t[0], t[1][0])) 
     13        regex, view_or_include = t[:2] 
     14        default_kwargs = t[2:] 
     15        if type(view_or_include) == list: 
     16            pattern_list.append(RegexURLResolver(regex, view_or_include[0], *default_kwargs)) 
    1517        else: 
    16             pattern_list.append(RegexURLPattern(t[0], prefix and (prefix + '.' + t[1]) or t[1], *t[2:])) 
     18            pattern_list.append(RegexURLPattern(regex, prefix and (prefix + '.' + view_or_include) or view_or_include, *default_kwargs)) 
    1719    return pattern_list 
  • django/branches/multiple-db-support/django/contrib/admin/media/js/admin/DateTimeShortcuts.js

    r3303 r3523  
    99    calendarDivName1: 'calendarbox', // name of calendar <div> that gets toggled 
    1010    calendarDivName2: 'calendarin',  // name of <div> that contains calendar 
     11    calendarLinkName: 'calendarlink',// name of the link that is used to toggle 
    1112    clockDivName: 'clockbox',        // name of clock <div> that gets toggled 
     13    clockLinkName: 'clocklink',      // name of the link that is used to toggle 
    1214    admin_media_prefix: '', 
    1315    init: function() { 
     
    4749        var clock_link = document.createElement('a'); 
    4850        clock_link.setAttribute('href', 'javascript:DateTimeShortcuts.openClock(' + num + ');'); 
     51        clock_link.id = DateTimeShortcuts.clockLinkName + num; 
    4952        quickElement('img', clock_link, '', 'src', DateTimeShortcuts.admin_media_prefix + 'img/admin/icon_clock.gif', 'alt', gettext('Clock')); 
    5053        shortcuts_span.appendChild(document.createTextNode('\240')); 
     
    7073        clock_box.style.display = 'none'; 
    7174        clock_box.style.position = 'absolute'; 
    72         if (getStyle(document.body,'direction')!='rtl') { 
    73             clock_box.style.left = findPosX(clock_link) + 17 + 'px'; 
    74         } 
    75         else { 
    76             // since style's width is in em, it'd be tough to calculate 
    77             // px value of it. let's use an estimated px for now 
    78             // TODO: IE returns wrong value for findPosX when in rtl mode 
    79             //       (it returns as it was left aligned), needs to be fixed. 
    80             clock_box.style.left = findPosX(clock_link) - 110 + 'px'; 
    81         } 
    82         clock_box.style.top = findPosY(clock_link) - 30 + 'px'; 
    8375        clock_box.className = 'clockbox module'; 
    8476        clock_box.setAttribute('id', DateTimeShortcuts.clockDivName + num); 
     
    9991    }, 
    10092    openClock: function(num) { 
    101         document.getElementById(DateTimeShortcuts.clockDivName + num).style.display = 'block'; 
     93        var clock_box = document.getElementById(DateTimeShortcuts.clockDivName+num) 
     94        var clock_link = document.getElementById(DateTimeShortcuts.clockLinkName+num) 
     95     
     96        // Recalculate the clockbox position 
     97        // is it left-to-right or right-to-left layout ? 
     98        if (getStyle(document.body,'direction')!='rtl') { 
     99            clock_box.style.left = findPosX(clock_link) + 17 + 'px'; 
     100        } 
     101        else { 
     102            // since style's width is in em, it'd be tough to calculate 
     103            // px value of it. let's use an estimated px for now 
     104            // TODO: IE returns wrong value for findPosX when in rtl mode 
     105            //       (it returns as it was left aligned), needs to be fixed. 
     106            clock_box.style.left = findPosX(clock_link) - 110 + 'px'; 
     107        } 
     108        clock_box.style.top = findPosY(clock_link) - 30 + 'px'; 
     109     
     110        // Show the clock box 
     111        clock_box.style.display = 'block'; 
    102112        addEvent(window, 'click', function() { DateTimeShortcuts.dismissClock(num); return true; }); 
    103113    }, 
     
    124134        var cal_link = document.createElement('a'); 
    125135        cal_link.setAttribute('href', 'javascript:DateTimeShortcuts.openCalendar(' + num + ');'); 
     136        cal_link.id = DateTimeShortcuts.calendarLinkName + num; 
    126137        quickElement('img', cal_link, '', 'src', DateTimeShortcuts.admin_media_prefix + 'img/admin/icon_calendar.gif', 'alt', gettext('Calendar')); 
    127138        shortcuts_span.appendChild(document.createTextNode('\240')); 
     
    150161        cal_box.style.display = 'none'; 
    151162        cal_box.style.position = 'absolute'; 
    152         // is it left-to-right or right-to-left layout ? 
    153         if (getStyle(document.body,'direction')!='rtl') { 
    154             cal_box.style.left = findPosX(cal_link) + 17 + 'px'; 
    155         } 
    156         else { 
    157             // since style's width is in em, it'd be tough to calculate 
    158             // px value of it. let's use an estimated px for now 
    159             // TODO: IE returns wrong value for findPosX when in rtl mode 
    160             //       (it returns as it was left aligned), needs to be fixed. 
    161             cal_box.style.left = findPosX(cal_link) - 180 + 'px'; 
    162         } 
    163         cal_box.style.top = findPosY(cal_link) - 75 + 'px'; 
    164163        cal_box.className = 'calendarbox module'; 
    165164        cal_box.setAttribute('id', DateTimeShortcuts.calendarDivName1 + num); 
     
    196195    }, 
    197196    openCalendar: function(num) { 
    198         document.getElementById(DateTimeShortcuts.calendarDivName1+num).style.display = 'block'; 
     197        var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1+num) 
     198        var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName+num) 
     199     
     200        // Recalculate the clockbox position 
     201        // is it left-to-right or right-to-left layout ? 
     202        if (getStyle(document.body,'direction')!='rtl') { 
     203            cal_box.style.left = findPosX(cal_link) + 17 + 'px'; 
     204        } 
     205        else { 
     206            // since style's width is in em, it'd be tough to calculate 
     207            // px value of it. let's use an estimated px for now 
     208            // TODO: IE returns wrong value for findPosX when in rtl mode 
     209            //       (it returns as it was left aligned), needs to be fixed. 
     210            cal_box.style.left = findPosX(cal_link) - 180 + 'px'; 
     211        } 
     212        cal_box.style.top = findPosY(cal_link) - 75 + 'px'; 
     213     
     214        cal_box.style.display = 'block'; 
    199215        addEvent(window, 'click', function() { DateTimeShortcuts.dismissCalendar(num); return true; }); 
    200216    }, 
  • django/branches/multiple-db-support/django/contrib/admin/media/js/admin/RelatedObjectLookups.js

    r3066 r3523  
    1212        href = triggeringLink.href + '?pop=1'; 
    1313    } 
    14     var win = window.open(href, name, 'height=500,width=740,resizable=yes,scrollbars=yes'); 
     14    var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes'); 
    1515    win.focus(); 
    1616    return false; 
  • django/branches/multiple-db-support/django/contrib/admin/urls.py

    r3258 r3523  
    2929    ('^doc/templates/(?P<template>.*)/$', 'django.contrib.admin.views.doc.template_detail'), 
    3030 
     31    # "Add user" -- a special-case view 
     32    ('^auth/user/add/$', 'django.contrib.admin.views.auth.user_add_stage'), 
     33 
    3134    # Add/change/delete/history 
    3235    ('^([^/]+)/([^/]+)/$', 'django.contrib.admin.views.main.change_list'), 
  • django/branches/multiple-db-support/django/contrib/auth/forms.py

    r3502 r3523  
    55from django.core import validators 
    66from django import forms 
     7 
     8class UserCreationForm(forms.Manipulator): 
     9    "A form that creates a user, with no privileges, from the given username and password." 
     10    def __init__(self): 
     11        self.fields = ( 
     12            forms.TextField(field_name='username', length=30, maxlength=30, is_required=True, 
     13                validator_list=[validators.isAlphaNumeric, self.isValidUsername]), 
     14            forms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True), 
     15            forms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True, 
     16                validator_list=[validators.AlwaysMatchesOtherField('password1', "The two password fields didn't match.")]), 
     17        ) 
     18 
     19    def isValidUsername(self, field_data, all_data): 
     20        try: 
     21            User.objects.get(username=field_data) 
     22        except User.DoesNotExist: 
     23            return 
     24        raise validators.ValidationError, 'A user with that username already exists.' 
     25 
     26    def save(self, new_data): 
     27        "Creates the user." 
     28        return User.objects.create_user(new_data['username'], '', new_data['password1']) 
    729 
    830class AuthenticationForm(forms.Manipulator): 
  • django/branches/multiple-db-support/django/core/management.py

    r3502 r3523  
    830830                        except models.FieldDoesNotExist: 
    831831                            e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn) 
     832                # date_hierarchy 
     833                if opts.admin.date_hierarchy: 
     834                    try: 
     835                        f = opts.get_field(opts.admin.date_hierarchy) 
     836                    except models.FieldDoesNotExist: 
     837                        e.add(opts, '"admin.date_hierarchy" refers to %r, which isn\'t a field.' % opts.admin.date_hierarchy) 
    832838 
    833839        # Check ordering attribute. 
  • django/branches/multiple-db-support/django/core/urlresolvers.py

    r3502 r3523  
    131131 
    132132class RegexURLResolver(object): 
    133     def __init__(self, regex, urlconf_name): 
     133    def __init__(self, regex, urlconf_name, default_kwargs=None): 
    134134        # regex is a string representing a regular expression. 
    135135        # urlconf_name is a string representing the module containing urlconfs. 
     
    137137        self.urlconf_name = urlconf_name 
    138138        self.callback = None 
     139        self.default_kwargs = default_kwargs or {} 
    139140 
    140141    def resolve(self, path): 
     
    150151                else: 
    151152                    if sub_match: 
    152                         return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match[2]) 
     153                        sub_match_dict = dict(self.default_kwargs, **sub_match[2]) 
     154                        return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match_dict) 
    153155                    tried.append(pattern.regex.pattern) 
    154156            raise Resolver404, {'tried': tried, 'path': new_path} 
  • django/branches/multiple-db-support/django/db/backends/ansi/sql.py

    r3387 r3523  
    138138                    table = opts.db_table 
    139139                    col = opts.get_field(f.rel.field_name).column 
     140                    # For MySQL, r_name must be unique in the first 64  
     141                    # characters. So we are careful with character usage here. 
     142                    r_name = '%s_refs_%s_%x' % (r_col, col, 
     143                                                abs(hash((r_table, table)))) 
    140144                    sql = style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \ 
    141                         (quote_name(table), 
    142                         quote_name('%s_referencing_%s_%s' % (r_col, r_table, col)), 
     145                        (quote_name(table), quote_name(r_name), 
    143146                        quote_name(r_col), quote_name(r_table), quote_name(col)) 
    144147                    pending.setdefault(rel_class, []).append( 
  • django/branches/multiple-db-support/django/db/models/fields/__init__.py

    r3502 r3523  
    290290            return first_choice + list(self.choices) 
    291291        rel_model = self.rel.to 
    292         return first_choice + [(x._get_pk_val(), str(x)) 
    293                                for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)] 
     292        if hasattr(self.rel, 'get_related_field'): 
     293            lst = [(getattr(x, self.rel.get_related_field().attname), str(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)] 
     294        else: 
     295            lst = [(x._get_pk_val(), str(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)] 
     296        return first_choice + lst 
    294297 
    295298    def get_choices_default(self): 
  • django/branches/multiple-db-support/django/db/models/fields/related.py

    r3366 r3523  
    2626    # Has the model already been loaded? 
    2727    # If so, resolve the string reference right away 
    28     model = get_model(rel_cls._meta.app_label,field.rel.to
     28    model = get_model(rel_cls._meta.app_label, field.rel.to, False
    2929    if model: 
    3030        field.rel.to = model 
  • django/branches/multiple-db-support/django/middleware/gzip.py

    r3113 r3523  
    1313    def process_response(self, request, response): 
    1414        patch_vary_headers(response, ('Accept-Encoding',)) 
    15         if response.has_header('Content-Encoding'): 
     15         
     16        # Avoid gzipping if we've already got a content-encoding or if the 
     17        # content-type is Javascript (silly IE...) 
     18        is_js = "javascript" in response.headers.get('Content-Type', '').lower() 
     19        if response.has_header('Content-Encoding') or is_js: 
    1620            return response 
    1721 
  • django/branches/multiple-db-support/docs/add_ons.txt

    r3258 r3523  
    33===================== 
    44 
    5 Django aims to follow Python's "batteries included" philosophy. It ships with a 
    6 variety of extra, optional tools that solve common Web-development problems. 
     5Django aims to follow Python's `"batteries included" philosophy`_. It ships 
     6with a variety of extra, optional tools that solve common Web-development 
     7problems. 
    78 
    89This code lives in ``django/contrib`` in the Django distribution. Here's a 
    910rundown of the packages in ``contrib``: 
     11 
     12.. _"batteries included" philosophy: http://docs.python.org/tut/node12.html#batteries-included 
    1013 
    1114admin 
  • django/branches/multiple-db-support/docs/db-api.txt

    r3303 r3523  
    579579    c = p.hometown       # Hits the database. 
    580580 
     581Note that ``select_related()`` does not follow foreign keys that have 
     582``null=True``. 
     583 
    581584``extra(select=None, where=None, params=None, tables=None)`` 
    582585~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • django/branches/multiple-db-support/docs/faq.txt

    r3502 r3523  
    621621------------------------------------------------------------- 
    622622 
    623 We don't recommend you create users via the admin interface, because at the 
    624 moment it requires you to edit password hashes manually. (Passwords are hashed 
    625 using one-way hash algorithms for security; there's currently no Web interface 
    626 for changing passwords by entering the actual password rather than the hash.) 
    627  
    628 To create a user, you'll have to use the Python API. See `creating users`_ for 
    629 full info. 
     623If you'd like to use the admin site to create users, upgrade to the Django 
     624development version, where this problem was fixed on Aug. 4, 2006. 
     625 
     626You can also use the Python API. See `creating users`_ for full info. 
    630627 
    631628.. _creating users: http://www.djangoproject.com/documentation/authentication/#creating-users 
  • django/branches/multiple-db-support/docs/url_dispatch.txt

    r2818 r3523  
    264264 
    265265    urlpatterns = patterns('', 
    266         (r'^articles/(\d{4})/$', 'myproject.news.views.year_archive'), 
    267         (r'^articles/(\d{4})/(\d{2})/$', 'myproject.news.views.month_archive'), 
    268         (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'myproject.news.views.article_detail'), 
    269     ) 
    270  
    271 In this example, each view has a common prefix -- ``'myproject.news.views'``. 
     266        (r'^articles/(\d{4})/$', 'mysite.news.views.year_archive'), 
     267        (r'^articles/(\d{4})/(\d{2})/$', 'mysite.news.views.month_archive'), 
     268        (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'mysite.news.views.article_detail'), 
     269    ) 
     270 
     271In this example, each view has a common prefix -- ``'mysite.news.views'``. 
    272272Instead of typing that out for each entry in ``urlpatterns``, you can use the 
    273273first argument to the ``patterns()`` function to specify a prefix to apply to 
     
    278278    from django.conf.urls.defaults import * 
    279279 
    280     urlpatterns = patterns('myproject.news.views', 
     280    urlpatterns = patterns('mysite.news.views', 
    281281        (r'^articles/(\d{4})/$', 'year_archive'), 
    282282        (r'^articles/(\d{4})/(\d{2})/$', 'month_archive'), 
     
    390390.. _generic views: http://www.djangoproject.com/documentation/generic_views/ 
    391391.. _syndication framework: http://www.djangoproject.com/documentation/syndication/ 
     392 
     393Passing extra options to ``include()`` 
     394-------------------------------------- 
     395 
     396**New in the Django development version.** 
     397 
     398Similarly, you can pass extra options to ``include()``. When you pass extra 
     399options to ``include()``, *each* line in the included URLconf will be passed 
     400the extra options. 
     401 
     402For example, these two URLconf sets are functionally identical: 
     403 
     404Set one:: 
     405 
     406    # main.py 
     407    urlpatterns = patterns('', 
     408        (r'^blog/', include('inner'), {'blogid': 3}), 
     409    ) 
     410 
     411    # inner.py 
     412    urlpatterns = patterns('', 
     413        (r'^archive/$', 'mysite.views.archive'), 
     414        (r'^about/$', 'mysite.views.about'), 
     415    ) 
     416 
     417Set two:: 
     418 
     419    # main.py 
     420    urlpatterns = patterns('', 
     421        (r'^blog/', include('inner')), 
     422    ) 
     423 
     424    # inner.py 
     425    urlpatterns = patterns('', 
     426        (r'^archive/$', 'mysite.views.archive', {'blogid': 3}), 
     427        (r'^about/$', 'mysite.views.about', {'blogid': 3}), 
     428    ) 
     429 
     430Note that extra options will *always* be passed to *every* line in the included 
     431URLconf, regardless of whether the line's view actually accepts those options 
     432as valid. For this reason, this technique is only useful if you're certain that 
     433every view in the the included URLconf accepts the extra options you're passing.