Django

Code

Changeset 6382

Show
Ignore:
Timestamp:
09/19/07 20:55:53 (1 year ago)
Author:
adrian
Message:

queryset-refactor: Merged to [6381]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/AUTHORS

    r6341 r6382  
    5050    Fabrice Aneche <akh@nobugware.com> 
    5151    ant9000@netwise.it 
     52    Florian Apolloner  
    5253    David Ascher <http://ascher.ca/> 
    5354    david@kazserve.org 
     
    8485    colin@owlfish.com 
    8586    crankycoder@gmail.com 
     87    Paul Collier <paul@paul-collier.com> 
    8688    Pete Crosier <pete.crosier@gmail.com> 
    8789    Matt Croydon <http://www.postneo.com/> 
     
    122124    Matthew Flanagan <http://wadofstuff.blogspot.com> 
    123125    Eric Floehr <eric@intellovations.com> 
     126    Vincent Foley <vfoleybourgon@yahoo.ca> 
    124127    Jorge Gajon <gajon@gajon.org> 
    125128    gandalf@owca.info 
     
    195198    limodou 
    196199    Philip Lindborg <philip.lindborg@gmail.com> 
     200    msaelices <msaelices@gmail.com> 
    197201    Matt McClanahan <http://mmcc.cx/> 
    198202    Martin Maney <http://www.chipy.org/Martin_Maney> 
     
    258262    Oliver Rutherfurd <http://rutherfurd.net/> 
    259263    ryankanno 
     264    Manuel Saelices <msaelices@yaco.es>  
    260265    Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/> 
    261266    Vinay Sajip <vinay_sajip@yahoo.co.uk> 
     
    272277    Leo Soto <leo.soto@gmail.com> 
    273278    Wiliam Alves de Souza <wiliamsouza83@gmail.com> 
     279    Don Spaulding <donspauldingii@gmail.com> 
    274280    Bjørn Stabell <bjorn@exoweb.net> 
    275281    Georgi Stanojevski <glisha@gmail.com> 
  • django/branches/queryset-refactor/django/bin/compile-messages.py

    r4934 r6382  
    55import sys 
    66 
     7try: 
     8    set 
     9except NameError: 
     10    from sets import Set as set     # For Python 2.3 
     11 
     12 
    713def compile_messages(locale=None): 
    8     basedir = None 
     14    basedirs = [os.path.join('conf', 'locale'), 'locale'] 
     15    if os.environ.get('DJANGO_SETTINGS_MODULE'): 
     16        from django.conf import settings 
     17        basedirs += settings.LOCALE_PATHS 
    918 
    10     if os.path.isdir(os.path.join('conf', 'locale')): 
    11         basedir = os.path.abspath(os.path.join('conf', 'locale')) 
    12     elif os.path.isdir('locale'): 
    13         basedir = os.path.abspath('locale') 
    14     else: 
    15         print "This script should be run from the Django SVN tree or your project or app tree." 
     19    # Gather existing directories. 
     20    basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs))) 
     21 
     22    if not basedirs: 
     23        print "This script should be run from the Django SVN tree or your project or app tree, or with the settings module specified." 
    1624        sys.exit(1) 
    1725 
    18     if locale is not None: 
    19         basedir = os.path.join(basedir, locale, 'LC_MESSAGES') 
     26    for basedir in basedirs: 
     27        if locale: 
     28            basedir = os.path.join(basedir, locale, 'LC_MESSAGES') 
     29        compile_messages_in_dir(basedir) 
    2030 
     31def compile_messages_in_dir(basedir): 
    2132    for dirpath, dirnames, filenames in os.walk(basedir): 
    2233        for f in filenames: 
     
    4152    parser.add_option('-l', '--locale', dest='locale', 
    4253            help="The locale to process. Default is to process all.") 
     54    parser.add_option('--settings', 
     55        help='Python path to settings module, e.g. "myproject.settings". If provided, all LOCALE_PATHS will be processed. If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be checked as well.') 
    4356    options, args = parser.parse_args() 
    4457    if len(args): 
    4558        parser.error("This program takes no arguments") 
     59    if options.settings: 
     60        os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 
    4661    compile_messages(options.locale) 
    4762 
  • django/branches/queryset-refactor/django/contrib/admin/views/main.py

    r5799 r6382  
    141141    def original_value(self): 
    142142        if self.original: 
    143             return self.original.__dict__[self.field.column
     143            return self.original.__dict__[self.field.attname
    144144 
    145145    def existing_display(self): 
  • django/branches/queryset-refactor/django/contrib/auth/backends.py

    r4265 r6382  
     1from django.db import connection 
    12from django.contrib.auth.models import User 
    23 
     
    1516            return None 
    1617 
     18    def get_group_permissions(self, user_obj): 
     19        "Returns a list of permission strings that this user has through his/her groups." 
     20        if not hasattr(user_obj, '_group_perm_cache'): 
     21            cursor = connection.cursor() 
     22            # The SQL below works out to the following, after DB quoting: 
     23            # cursor.execute(""" 
     24            #     SELECT ct."app_label", p."codename" 
     25            #     FROM "auth_permission" p, "auth_group_permissions" gp, "auth_user_groups" ug, "django_content_type" ct 
     26            #     WHERE p."id" = gp."permission_id" 
     27            #         AND gp."group_id" = ug."group_id" 
     28            #         AND ct."id" = p."content_type_id" 
     29            #         AND ug."user_id" = %s, [self.id]) 
     30            qn = connection.ops.quote_name 
     31            sql = """ 
     32                SELECT ct.%s, p.%s 
     33                FROM %s p, %s gp, %s ug, %s ct 
     34                WHERE p.%s = gp.%s 
     35                    AND gp.%s = ug.%s 
     36                    AND ct.%s = p.%s 
     37                    AND ug.%s = %%s""" % ( 
     38                qn('app_label'), qn('codename'), 
     39                qn('auth_permission'), qn('auth_group_permissions'), 
     40                qn('auth_user_groups'), qn('django_content_type'), 
     41                qn('id'), qn('permission_id'), 
     42                qn('group_id'), qn('group_id'), 
     43                qn('id'), qn('content_type_id'), 
     44                qn('user_id'),) 
     45            cursor.execute(sql, [user_obj.id]) 
     46            user_obj._group_perm_cache = set(["%s.%s" % (row[0], row[1]) for row in cursor.fetchall()]) 
     47        return user_obj._group_perm_cache 
     48     
     49    def get_all_permissions(self, user_obj): 
     50        if not hasattr(user_obj, '_perm_cache'): 
     51            user_obj._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()]) 
     52            user_obj._perm_cache.update(self.get_group_permissions(user_obj)) 
     53        return user_obj._perm_cache 
     54 
     55    def has_perm(self, user_obj, perm): 
     56        return perm in self.get_all_permissions(user_obj) 
     57 
     58    def has_module_perms(self, user_obj, app_label): 
     59        return bool(len([p for p in self.get_all_permissions(user_obj) if p[:p.index('.')] == app_label])) 
     60 
    1761    def get_user(self, user_id): 
    1862        try: 
  • django/branches/queryset-refactor/django/contrib/auth/models.py

    r6341 r6382  
     1from django.contrib import auth 
    12from django.core import validators 
    23from django.core.exceptions import ImproperlyConfigured 
    3 from django.db import connection, models 
     4from django.db import models 
    45from django.db.models.manager import EmptyManager 
    56from django.contrib.contenttypes.models import ContentType 
     
    211212 
    212213    def get_group_permissions(self): 
    213         "Returns a list of permission strings that this user has through his/her groups." 
    214         if not hasattr(self, '_group_perm_cache'): 
    215             cursor = connection.cursor() 
    216             # The SQL below works out to the following, after DB quoting: 
    217             # cursor.execute(""" 
    218             #     SELECT ct."app_label", p."codename" 
    219             #     FROM "auth_permission" p, "auth_group_permissions" gp, "auth_user_groups" ug, "django_content_type" ct 
    220             #     WHERE p."id" = gp."permission_id" 
    221             #         AND gp."group_id" = ug."group_id" 
    222             #         AND ct."id" = p."content_type_id" 
    223             #         AND ug."user_id" = %s, [self.id]) 
    224             qn = connection.ops.quote_name 
    225             sql = """ 
    226                 SELECT ct.%s, p.%s 
    227                 FROM %s p, %s gp, %s ug, %s ct 
    228                 WHERE p.%s = gp.%s 
    229                     AND gp.%s = ug.%s 
    230                     AND ct.%s = p.%s 
    231                     AND ug.%s = %%s""" % ( 
    232                 qn('app_label'), qn('codename'), 
    233                 qn('auth_permission'), qn('auth_group_permissions'), 
    234                 qn('auth_user_groups'), qn('django_content_type'), 
    235                 qn('id'), qn('permission_id'), 
    236                 qn('group_id'), qn('group_id'), 
    237                 qn('id'), qn('content_type_id'), 
    238                 qn('user_id'),) 
    239             cursor.execute(sql, [self.id]) 
    240             self._group_perm_cache = set(["%s.%s" % (row[0], row[1]) for row in cursor.fetchall()]) 
    241         return self._group_perm_cache 
     214        """ 
     215        Returns a list of permission strings that this user has through 
     216        his/her groups. This method queries all available auth backends. 
     217        """ 
     218        permissions = set() 
     219        for backend in auth.get_backends(): 
     220            if hasattr(backend, "get_group_permissions"): 
     221                permissions.update(backend.get_group_permissions(self)) 
     222        return permissions 
    242223 
    243224    def get_all_permissions(self): 
    244         if not hasattr(self, '_perm_cache'): 
    245             self._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in self.user_permissions.select_related()]) 
    246             self._perm_cache.update(self.get_group_permissions()) 
    247         return self._perm_cache 
     225        permissions = set() 
     226        for backend in auth.get_backends(): 
     227            if hasattr(backend, "get_all_permissions"): 
     228                permissions.update(backend.get_all_permissions(self)) 
     229        return permissions  
    248230 
    249231    def has_perm(self, perm): 
    250         "Returns True if the user has the specified permission." 
     232        """ 
     233        Returns True if the user has the specified permission. This method 
     234        queries all available auth backends, but returns immediately if any 
     235        backend returns True. Thus, a user who has permission from a single 
     236        auth backend is assumed to have permission in general. 
     237        """ 
     238        # Inactive users have no permissions. 
    251239        if not self.is_active: 
    252240            return False 
     241         
     242        # Superusers have all permissions. 
    253243        if self.is_superuser: 
    254244            return True 
    255         return perm in self.get_all_permissions() 
     245             
     246        # Otherwise we need to check the backends. 
     247        for backend in auth.get_backends(): 
     248            if hasattr(backend, "has_perm"): 
     249                if backend.has_perm(self, perm): 
     250                    return True 
     251        return False 
    256252 
    257253    def has_perms(self, perm_list): 
    258         "Returns True if the user has each of the specified permissions.
     254        """Returns True if the user has each of the specified permissions.""
    259255        for perm in perm_list: 
    260256            if not self.has_perm(perm): 
     
    263259 
    264260    def has_module_perms(self, app_label): 
    265         "Returns True if the user has any permissions in the given app label." 
     261        """ 
     262        Returns True if the user has any permissions in the given app 
     263        label. Uses pretty much the same logic as has_perm, above. 
     264        """ 
    266265        if not self.is_active: 
    267266            return False 
     267 
    268268        if self.is_superuser: 
    269269            return True 
    270         return bool(len([p for p in self.get_all_permissions() if p[:p.index('.')] == app_label])) 
     270 
     271        for backend in auth.get_backends(): 
     272            if hasattr(backend, "has_module_perms"): 
     273                if backend.has_module_perms(self, app_label): 
     274                    return True 
     275        return False 
    271276 
    272277    def get_and_delete_messages(self): 
     
    301306class Message(models.Model): 
    302307    """ 
    303     The message system is a lightweight way to queue messages for given users. A message is associated with a User instance (so it is only applicable for registered users). There's no concept of expiration or timestamps. Messages are created by the Django admin after successful actions. For example, "The poll Foo was created successfully." is a message. 
     308    The message system is a lightweight way to queue messages for given 
     309    users. A message is associated with a User instance (so it is only 
     310    applicable for registered users). There's no concept of expiration or 
     311    timestamps. Messages are created by the Django admin after successful 
     312    actions. For example, "The poll Foo was created successfully." is a 
     313    message. 
    304314    """ 
    305315    user = models.ForeignKey(User) 
  • django/branches/queryset-refactor/django/contrib/sessions/backends/base.py

    r6341 r6382  
    108108            return self._session_cache 
    109109        except AttributeError: 
    110             if self.session_key is None: 
     110            if self._session_key is None: 
    111111                self._session_cache = {} 
    112112            else: 
  • django/branches/queryset-refactor/django/contrib/sessions/backends/file.py

    r6341 r6382  
    3232            session_file = open(self._key_to_file(), "rb") 
    3333            try: 
    34                 session_data = self.decode(session_file.read()) 
    35             except(EOFError, SuspiciousOperation): 
    36                 self._session_key = self._get_new_session_key() 
    37                 self._session_cache = {} 
    38                 self.save() 
     34                try: 
     35                    session_data = self.decode(session_file.read()) 
     36                except(EOFError, SuspiciousOperation): 
     37                    self._session_key = self._get_new_session_key() 
     38                    self._session_cache = {} 
     39                    self.save() 
    3940            finally: 
    4041                session_file.close() 
  • django/branches/queryset-refactor/django/core/context_processors.py

    r5379 r6382  
    1414    Returns context variables required by apps that use Django's authentication 
    1515    system. 
     16 
     17    If there is no 'user' attribute in the request, uses AnonymousUser (from 
     18    django.contrib.auth). 
    1619    """ 
     20    if hasattr(request, 'user'): 
     21        user = request.user 
     22    else: 
     23        from django.contrib.auth.models import AnonymousUser 
     24        user = AnonymousUser() 
    1725    return { 
    18         'user': request.user, 
    19         'messages': request.user.get_and_delete_messages(), 
    20         'perms': PermWrapper(request.user), 
     26        'user': user, 
     27        'messages': user.get_and_delete_messages(), 
     28        'perms': PermWrapper(user), 
    2129    } 
    2230 
  • django/branches/queryset-refactor/django/core/handlers/modpython.py

    r6339 r6382  
    4343 
    4444    def is_secure(self): 
    45         # Note: modpython 3.2.10+ has req.is_https(), but we need to support previous versions 
    46         return 'HTTPS' in self._req.subprocess_env and self._req.subprocess_env['HTTPS'] == 'on' 
     45        try: 
     46            return self._req.is_https() 
     47        except AttributeError: 
     48            # mod_python < 3.2.10 doesn't have req.is_https(). 
     49            return self._req.subprocess_env.get('HTTPS', '').lower() in ('on', '1') 
    4750 
    4851    def _load_post_and_files(self): 
  • django/branches/queryset-refactor/django/db/backends/ado_mssql/creation.py

    r5803 r6382  
    77    'DateTimeField':     'smalldatetime', 
    88    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)', 
    9     'FileField':         'varchar(100)', 
    10     'FilePathField':     'varchar(100)', 
     9    'FileField':         'varchar(%(max_length)s)', 
     10    'FilePathField':     'varchar(%(max_length)s)', 
    1111    'FloatField':        'double precision', 
    12     'ImageField':        'varchar(100)', 
     12    'ImageField':        'varchar(%(max_length)s)', 
    1313    'IntegerField':      'int', 
    1414    'IPAddressField':    'char(15)', 
  • django/branches/queryset-refactor/django/db/backends/mysql/creation.py

    r5803 r6382  
    1111    'DateTimeField':     'datetime', 
    1212    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)', 
    13     'FileField':         'varchar(100)', 
    14     'FilePathField':     'varchar(100)', 
     13    'FileField':         'varchar(%(max_length)s)', 
     14    'FilePathField':     'varchar(%(max_length)s)', 
    1515    'FloatField':        'double precision', 
    16     'ImageField':        'varchar(100)', 
     16    'ImageField':        'varchar(%(max_length)s)', 
    1717    'IntegerField':      'integer', 
    1818    'IPAddressField':    'char(15)', 
  • django/branches/queryset-refactor/django/db/backends/mysql_old/creation.py

    r5876 r6382  
    1111    'DateTimeField':     'datetime', 
    1212    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)', 
    13     'FileField':         'varchar(100)', 
    14     'FilePathField':     'varchar(100)', 
     13    'FileField':         'varchar(%(max_length)s)', 
     14    'FilePathField':     'varchar(%(max_length)s)', 
    1515    'FloatField':        'double precision', 
    16     'ImageField':        'varchar(100)', 
     16    'ImageField':        'varchar(%(max_length)s)', 
    1717    'IntegerField':      'integer', 
    1818    'IPAddressField':    'char(15)', 
  • django/branches/queryset-refactor/django/db/backends/oracle/creation.py

    r5981 r6382  
    1414    'DateTimeField':                'TIMESTAMP', 
    1515    'DecimalField':                 'NUMBER(%(max_digits)s, %(decimal_places)s)', 
    16     'FileField':                    'NVARCHAR2(100)', 
    17     'FilePathField':                'NVARCHAR2(100)', 
     16    'FileField':                    'NVARCHAR2(%(max_length)s)', 
     17    'FilePathField':                'NVARCHAR2(%(max_length)s)', 
    1818    'FloatField':                   'DOUBLE PRECISION', 
    19     'ImageField':                   'NVARCHAR2(100)', 
     19    'ImageField':                   'NVARCHAR2(%(max_length)s)', 
    2020    'IntegerField':                 'NUMBER(11)', 
    2121    'IPAddressField':               'VARCHAR2(15)', 
     
    2929    'TextField':                    'NCLOB', 
    3030    'TimeField':                    'TIMESTAMP', 
    31     'URLField':                     'VARCHAR2(200)', 
     31    'URLField':                     'VARCHAR2(%(max_length)s)', 
    3232    'USStateField':                 'CHAR(2)', 
    3333} 
  • django/branches/queryset-refactor/django/db/backends/postgresql/creation.py

    r5803 r6382  
    1111    'DateTimeField':     'timestamp with time zone', 
    1212    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)', 
    13     'FileField':         'varchar(100)', 
    14     'FilePathField':     'varchar(100)', 
     13    'FileField':         'varchar(%(max_length)s)', 
     14    'FilePathField':     'varchar(%(max_length)s)', 
    1515    'FloatField':        'double precision', 
    16     'ImageField':        'varchar(100)', 
     16    'ImageField':        'varchar(%(max_length)s)', 
    1717    'IntegerField':      'integer', 
    1818    'IPAddressField':    'inet', 
  • django/branches/queryset-refactor/django/db/backends/sqlite3/creation.py

    r5803 r6382  
    1010    'DateTimeField':                'datetime', 
    1111    'DecimalField':                 'decimal', 
    12     'FileField':                    'varchar(100)', 
    13     'FilePathField':                'varchar(100)', 
     12    'FileField':                    'varchar(%(max_length)s)', 
     13    'FilePathField':                'varchar(%(max_length)s)',