Django

Code

Changeset 6857

Show
Ignore:
Timestamp:
12/02/07 20:59:56 (1 year ago)
Author:
mtredinnick
Message:

queryset-refactor: Merged from trunk up to [6856].

Files:

Legend:

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

    r6753 r6857  
    9090    Pete Crosier <pete.crosier@gmail.com> 
    9191    Matt Croydon <http://www.postneo.com/> 
     92    Leah Culver <leah@pownce.com> 
    9293    flavio.curella@gmail.com 
    9394    Jure Cuhalev <gandalf@owca.info> 
     
    133134    gandalf@owca.info 
    134135    Marc Garcia <marc.garcia@accopensys.com> 
     136    Andy Gayton <andy-django@thecablelounge.com> 
    135137    Baishampayan Ghose 
    136138    Dimitris Glezos <dimitris@glezos.com> 
     
    172174    Antti Kaihola <http://akaihola.blogspot.com/> 
    173175    Nagy Károly <charlie@rendszergazda.com> 
     176    Erik Karulf <erik@karulf.com> 
    174177    Ben Dean Kawamura <ben.dean.kawamura@gmail.com> 
    175178    Ian G. Kelly <ian.g.kelly@gmail.com> 
     
    191194    konrad@gwu.edu 
    192195    knox <christobzr@gmail.com> 
     196    David Krauth 
    193197    kurtiss@meetro.com 
    194198    lakin.wecker@gmail.com 
     
    205209    limodou 
    206210    Philip Lindborg <philip.lindborg@gmail.com> 
     211    Trey Long <trey@ktrl.com> 
    207212    msaelices <msaelices@gmail.com> 
    208213    Matt McClanahan <http://mmcc.cx/> 
     
    253258    Luke Plant <http://lukeplant.me.uk/> 
    254259    plisk 
     260    Mihai Preda <mihai_preda@yahoo.com> 
    255261    Daniel Poelzleithner <http://poelzi.org/> 
    256262    polpak@yahoo.com 
     
    264270    Brian Ray <http://brianray.chipy.org/> 
    265271    remco@diji.biz 
     272    David Reynolds <david@reynoldsfamily.org.uk> 
    266273    rhettg@gmail.com 
    267274    ricardojbarrios@gmail.com 
     
    283290    jason.sidabras@gmail.com 
    284291    Jozko Skrablin <jozko.skrablin@gmail.com> 
     292    Ben Slavin <benjamin.slavin@gmail.com> 
    285293    SmileyChris <smileychris@gmail.com> 
    286294    smurf@smurf.noris.de 
  • django/branches/queryset-refactor/django/conf/global_settings.py

    r6726 r6857  
    254254URL_VALIDATOR_USER_AGENT = "Django/%s (http://www.djangoproject.com)" % get_version() 
    255255 
     256# The tablespaces to use for each model when not specified otherwise. 
     257DEFAULT_TABLESPACE = '' 
     258DEFAULT_INDEX_TABLESPACE = '' 
     259 
    256260############## 
    257261# MIDDLEWARE # 
     
    290294# The cache backend to use.  See the docstring in django.core.cache for the 
    291295# possible values. 
    292 CACHE_BACKEND = 'simple://' 
     296CACHE_BACKEND = 'locmem://' 
    293297CACHE_MIDDLEWARE_KEY_PREFIX = '' 
    294298CACHE_MIDDLEWARE_SECONDS = 600 
  • django/branches/queryset-refactor/django/conf/__init__.py

    r6597 r6857  
    5353                raise KeyError 
    5454        except KeyError: 
    55             raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE 
     55            raise ImportError, "Environment variable %s is undefined so settings cannot be imported." % ENVIRONMENT_VARIABLE   # NOTE: This is arguably an EnvironmentError, but that causes problems with Python's interactive help 
    5656 
    5757        self._target = Settings(settings_module) 
     
    6464        """ 
    6565        if self._target != None: 
    66             raise EnvironmentError, 'Settings already configured.' 
     66            raise RuntimeError, 'Settings already configured.' 
    6767        holder = UserSettingsHolder(default_settings) 
    6868        for name, value in options.items(): 
     
    8383            mod = __import__(self.SETTINGS_MODULE, {}, {}, ['']) 
    8484        except ImportError, e: 
    85             raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) 
     85            raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) 
    8686 
    8787        # Settings that should be converted into tuples if they're mistakenly entered 
  • django/branches/queryset-refactor/django/conf/locale/ca/LC_MESSAGES/djangojs.po

    r5539 r6857  
     1# translation of djangojs.po to español 
    12# translation of djangojs.po to 
    23# Catalan translation for the django-admin JS files. 
    34# This file is distributed under the same license as the Django package. 
    45# 
     6# Antoni Aloy <antoni.aloy@trespams.com>, 2007. 
    57msgid "" 
    68msgstr "" 
     
    810"Report-Msgid-Bugs-To: \n" 
    911"POT-Creation-Date: 2007-05-20 18:25+0200\n" 
    10 "PO-Revision-Date: 2007-06-25 17:47+0200\n" 
    11 "Last-Translator: Marc Fargas <telenieko@telenieko.com>\n" 
    12 "Language-Team: <es@li.org>\n" 
     12"PO-Revision-Date: 2007-12-01 12:06+0100\n" 
     13"Last-Translator: Antoni Aloy <antoni.aloy@trespams.com>\n" 
     14"Language-Team: español <ca@li.org>\n" 
    1315"MIME-Version: 1.0\n" 
    1416"Content-Type: text/plain; charset=UTF-8\n" 
    1517"Content-Transfer-Encoding: 8bit\n" 
    16 "X-Generator: VIM 7.0\n" 
     18"X-Generator: KBabel 1.11.4\n" 
    1719"Plural-Forms:  nplurals=2; plural=(n != 1);\n" 
    1820 
     
    5254"January February March April May June July August September October November " 
    5355"December" 
    54 msgstr "" 
    55 "Febrer Març Abril Maig Juny Juliol Agost Setembre Octubre Novembre Desembre" 
     56msgstr "Gener Febrer Març Abril Maig Juny Juliol Agost Setembre Octubre Novembre Desembre" 
    5657 
    5758#: contrib/admin/media/js/dateparse.js:33 
     
    118119msgid "Hide" 
    119120msgstr "Ocultar" 
     121 
  • django/branches/queryset-refactor/django/contrib/admin/templates/admin/field_line.html

    r3037 r6857  
    66  {% field_widget bound_field %} 
    77  {% if not bound_field.has_label_first %}{% field_label bound_field %}{% endif %} 
    8   {% if bound_field.field.help_text %}<p class="help">{{ bound_field.field.help_text }}</p>{% endif %} 
     8  {% if bound_field.field.help_text %}<p class="help">{{ bound_field.field.help_text|safe }}</p>{% endif %} 
    99{% endfor %} 
    1010</div> 
  • django/branches/queryset-refactor/django/contrib/localflavor/uk/forms.py

    r5876 r6857  
    33""" 
    44 
    5 from django.newforms.fields import RegexField 
     5from django.newforms.fields import RegexField, Select 
    66from django.utils.translation import ugettext 
    77 
     
    1818            error_message=ugettext(u'Enter a postcode. A space is required between the two postcode parts.'), 
    1919            *args, **kwargs) 
     20 
     21class UKCountySelect(Select): 
     22    """ 
     23    A Select widget that uses a list of UK Counties/Regions as its choices. 
     24    """ 
     25    def __init__(self, attrs=None): 
     26        from uk_regions import UK_REGION_CHOICES 
     27        super(UKCountySelect, self).__init__(attrs, choices=UK_REGION_CHOICES) 
     28 
     29class UKNationSelect(Select): 
     30    """ 
     31    A Select widget that uses a list of UK Nations as its choices. 
     32    """ 
     33    def __init__(self, attrs=None): 
     34        from uk_regions import UK_NATIONS_CHOICES 
     35        super(UKNationSelect, self).__init__(attrs, choices=UK_NATIONS_CHOICES) 
  • django/branches/queryset-refactor/django/contrib/markup/templatetags/markup.py

    r6690 r6857  
    3333textile.is_safe = True 
    3434 
    35 def markdown(value): 
     35def markdown(value, arg=''): 
     36    """ 
     37    Runs Markdown over a given value, optionally using various 
     38    extensions python-markdown supports. 
     39 
     40    Syntax:: 
     41 
     42        {{ value|markdown:"extension1_name,extension2_name..." }} 
     43 
     44    To enable safe mode, which strips raw HTML and only returns HTML 
     45    generated by actual Markdown syntax, pass "safe" as the first 
     46    extension in the list. 
     47 
     48    If the version of Markdown in use does not support extensions, 
     49    they will be silently ignored. 
     50 
     51    """ 
    3652    try: 
    3753        import markdown 
     
    4157        return force_unicode(value) 
    4258    else: 
    43         return mark_safe(force_unicode(markdown.markdown(smart_str(value)))) 
     59        # markdown.version was first added in 1.6b. The only version of markdown 
     60        # to fully support extensions before 1.6b was the shortlived 1.6a. 
     61        if hasattr(markdown, 'version'): 
     62            extensions = [e for e in arg.split(",") if e] 
     63            if len(extensions) > 0 and extensions[0] == "safe": 
     64                extensions = extensions[1:] 
     65                safe_mode = True 
     66            else: 
     67                safe_mode = False 
     68            return mark_safe(force_unicode(markdown.markdown(smart_str(value), extensions, safe_mode=safe_mode))) 
     69        else: 
     70            return mark_safe(force_unicode(markdown.markdown(smart_str(value)))) 
    4471markdown.is_safe = True 
    4572 
  • django/branches/queryset-refactor/django/contrib/markup/tests.py

    r6690 r6857  
    6262        rendered = t.render(Context(locals())).strip() 
    6363        if docutils: 
    64             self.assertEqual(rendered, """<p>Paragraph 1</p> 
     64            # Different versions of docutils return slightly different HTML 
     65            try: 
     66                # Docutils v0.4 and earlier 
     67                self.assertEqual(rendered, """<p>Paragraph 1</p> 
    6568<p>Paragraph 2 with a <a class="reference" href="http://www.example.com/">link</a></p>""") 
     69            except AssertionError, e: 
     70                # Docutils from SVN (which will become 0.5) 
     71                self.assertEqual(rendered, """<p>Paragraph 1</p> 
     72<p>Paragraph 2 with a <a class="reference external" href="http://www.example.com/">link</a></p>""") 
    6673        else: 
    6774            self.assertEqual(rendered, rest_content) 
  • django/branches/queryset-refactor/django/contrib/sessions/backends/base.py

    r6597 r6857  
    5151        self.modified = self.modified or key in self._session 
    5252        return self._session.pop(key, *args) 
     53 
     54    def setdefault(self, key, value): 
     55        if key in self._session: 
     56            return self._session[key] 
     57        else: 
     58            self.modified = True 
     59            self._session[key] = value 
     60            return value 
    5361 
    5462    def set_test_cookie(self): 
  • django/branches/queryset-refactor/django/contrib/sessions/models.py

    r6466 r6857  
    1818        pickled_md5 = md5.new(pickled + settings.SECRET_KEY).hexdigest() 
    1919        return base64.encodestring(pickled + pickled_md5) 
    20  
    21     def get_new_session_key(self): 
    22         "Returns session key that isn't being used." 
    23         # The random module is seeded when this Apache child is created. 
    24         # Use SECRET_KEY as added salt. 
    25         try: 
    26             pid = os.getpid() 
    27         except AttributeError: 
    28             # No getpid() in Jython, for example 
    29             pid = 1 
    30         while 1: 
    31             session_key = md5.new("%s%s%s%s" % (random.randint(0, sys.maxint - 1), pid, time.time(), settings.SECRET_KEY)).hexdigest() 
    32             try: 
    33                 self.get(session_key=session_key) 
    34             except self.model.DoesNotExist: 
    35                 break 
    36         return session_key 
    37  
    38     def get_new_session_object(self): 
    39         """ 
    40         Returns a new session object. 
    41         """ 
    42         # FIXME: There is a *small* chance of collision here, meaning we will 
    43         # return an existing object. That can be fixed when we add a way to 
    44         # validate (and guarantee) that non-auto primary keys are unique. For 
    45         # now, we save immediately in order to reduce the "window of 
    46         # misfortune" as much as possible. 
    47         created = False 
    48         while not created: 
    49             obj, created = self.get_or_create(session_key=self.get_new_session_key(), 
    50                     expire_date = datetime.datetime.now()) 
    51             # Collision in key generation, so re-seed the generator 
    52             random.seed() 
    53         return obj 
    5420 
    5521    def save(self, session_key, session_dict, expire_date): 
  • django/branches/queryset-refactor/django/contrib/sessions/tests.py

    r6597 r6857  
    6767(True, False) 
    6868 
     69>>> s.setdefault('foo', 'bar') 
     70'bar' 
     71>>> s.setdefault('foo', 'baz') 
     72'bar' 
     73 
    6974>>> s.accessed = False  # Reset the accessed flag 
    7075 
  • django/branches/queryset-refactor/django/core/cache/backends/base.py

    r6597 r6857  
    1717    def add(self, key, value, timeout=None): 
    1818        """ 
    19         Set a value in the cache if the key does not already exist. If 
     19        Set a value in the cache if the key does not already exist. If 
    2020        timeout is given, that timeout will be used for the key; otherwise 
    2121        the default cache timeout will be used. 
     
    2525    def get(self, key, default=None): 
    2626        """ 
    27         Fetch a given key from the cache. If the key does not exist, return 
     27        Fetch a given key from the cache. If the key does not exist, return 
    2828        default, which itself defaults to None. 
    2929        """ 
     
    3232    def set(self, key, value, timeout=None): 
    3333        """ 
    34         Set a value in the cache. If timeout is given, that timeout will be 
     34        Set a value in the cache. If timeout is given, that timeout will be 
    3535        used for the key; otherwise the default cache timeout will be used. 
    3636        """ 
     
    4545    def get_many(self, keys): 
    4646        """ 
    47         Fetch a bunch of keys from the cache. For certain backends (memcached, 
     47        Fetch a bunch of keys from the cache. For certain backends (memcached, 
    4848        pgsql) this can be *much* faster when fetching multiple values. 
    4949 
    50         Returns a dict mapping each key in keys to its value. If the given 
     50        Returns a dict mapping each key in keys to its value. If the given 
    5151        key is missing, it will be missing from the response dict. 
    5252        """ 
     
    6565 
    6666    __contains__ = has_key 
    67  
  • django/branches/queryset-refactor/django/core/cache/backends/filebased.py

    r6597 r6857  
    11"File-based cache backend" 
    22 
    3 from django.core.cache.backends.simple import CacheClass as SimpleCacheClass 
    4 from django.utils.http import urlquote_plus 
    53import os, time 
    64try: 
     
    86except ImportError: 
    97    import pickle 
     8from django.core.cache.backends.base import BaseCache 
     9from django.utils.http import urlquote_plus 
    1010 
    11 class CacheClass(SimpleCacheClass): 
     11class CacheClass(BaseCache): 
    1212    def __init__(self, dir, params): 
     13        BaseCache.__init__(self, params) 
     14         
     15        max_entries = params.get('max_entries', 300) 
     16        try: 
     17            self._max_entries = int(max_entries) 
     18        except (ValueError, TypeError): 
     19            self._max_entries = 300 
     20             
     21        cull_frequency = params.get('cull_frequency', 3) 
     22        try: 
     23            self._cull_frequency = int(cull_frequency) 
     24        except (ValueError, TypeError): 
     25            self._cull_frequency = 3 
     26             
    1327        self._dir = dir 
    1428        if not os.path.exists(self._dir): 
    1529            self._createdir() 
    16         SimpleCacheClass.__init__(self, dir, params) 
    17         del self._cache 
    18         del self._expire_info 
    1930 
    2031    def add(self, key, value, timeout=None): 
  • django/branches/queryset-refactor/django/core/cache/backends/locmem.py

    r6726 r6857  
    77    import pickle 
    88 
    9 from django.core.cache.backends.simple import CacheClass as SimpleCacheClass 
     9from django.core.cache.backends.base import BaseCache 
    1010from django.utils.synch import RWLock 
    1111 
    12 class CacheClass(SimpleCacheClass): 
    13     def __init__(self, host, params): 
    14         SimpleCacheClass.__init__(self, host, params) 
     12class CacheClass(BaseCache): 
     13    def __init__(self, _, params): 
     14        BaseCache.__init__(self, params) 
     15        self._cache = {} 
     16        self._expire_info = {} 
     17 
     18        max_entries = params.get('max_entries', 300) 
     19        try: 
     20            self._max_entries = int(max_entries) 
     21        except (ValueError, TypeError): 
     22            self._max_entries = 300 
     23 
     24        cull_frequency = params.get('cull_frequency', 3) 
     25        try: 
     26            self._cull_frequency = int(cull_frequency) 
     27        except (ValueError, TypeError): 
     28            self._cull_frequency = 3 
     29 
    1530        self._lock = RWLock() 
     31 
     32    def _add(self, key, value, timeout=None): 
     33        if len(self._cache) >= self._max_entries: 
     34            self._cull() 
     35        if timeout is None: 
     36            timeout = self.default_timeout 
     37        if key not in self._cache.keys(): 
     38            self._cache[key] = value 
     39            self._expire_info[key] = time.time() + timeout 
    1640 
    1741    def add(self, key, value, timeout=None): 
     
    2044        try: 
    2145            try: 
    22                 super(CacheClass, self).add(key, pickle.dumps(value), timeout) 
     46                self._add(key, pickle.dumps(value), timeout) 
    2347            except pickle.PickleError: 
    2448                pass 
     
    5276                self._lock.writer_leaves() 
    5377 
     78    def _set(self, key, value, timeout=None): 
     79        if len(self._cache) >= self._max_entries: 
     80            self._cull() 
     81        if timeout is None: 
     82            timeout = self.default_timeout 
     83        self._cache[key] = value 
     84        self._expire_info[key] = time.time() + timeout 
     85 
    5486    def set(self, key, value, timeout=None): 
    5587        self._lock.writer_enters() 
     
    5789        try: 
    5890            try: 
    59                 super(CacheClass, self).set(key, pickle.dumps(value), timeout) 
     91                self._set(key, pickle.dumps(value), timeout) 
    6092            except pickle.PickleError: 
    6193                pass 
     
    6395            self._lock.writer_leaves() 
    6496 
     97    def has_key(self, key): 
     98        return key in self._cache 
     99 
     100    def _cull(self): 
     101        if self._cull_frequency == 0: 
     102            self._cache.clear() 
     103            self._expire_info.clear() 
     104        else: 
     105            doomed = [k for (i, k) in enumerate(self._cache) if i % self._cull_frequency == 0] 
     106            for k in doomed: 
     107                self.delete(k) 
     108 
     109    def _delete(self, key): 
     110        try: 
     111            del self._cache[key] 
     112        except KeyError: 
     113            pass 
     114        try: 
     115            del self._expire_info[key] 
     116        except KeyError: 
     117            pass 
     118 
    65119    def delete(self, key): 
    66120        self._lock.writer_enters() 
    67121        try: 
    68             SimpleCacheClass.delete(self, key) 
     122            self._delete(key) 
    69123        finally: 
    70124            self._lock.writer_leaves() 
  • django/branches/queryset-refactor/django/core/cache/__init__.py

    r4486 r6857  
    2323    # name for use in settings file --> name of module in "backends" directory 
    2424    'memcached': 'memcached', 
    25     'simple': 'simple', 
    2625    'locmem': 'locmem', 
    2726    'file': 'filebased', 
    2827    'db': 'db', 
    2928    'dummy': 'dummy', 
     29} 
     30 
     31DEPRECATED_BACKENDS = { 
     32    # deprecated backend --> replacement module 
     33    'simple': 'locmem', 
    3034} 
    3135 
     
    3640    if not rest.startswith('//'): 
    3741        raise InvalidCacheBackendError, "Backend URI must start with scheme://" 
     42    if scheme in DEPRECATED_BACKENDS: 
     43        import warnings 
     44        warnings.warn("'%s' backend is deprecated. Use '%s' instead." %  
     45            (scheme, DEPRECATED_BACKENDS[scheme]), DeprecationWarning) 
     46        scheme = DEPRECATED_BACKENDS[scheme] 
    3847    if scheme not in BACKENDS: 
    3948        raise InvalidCacheBackendError, "%r is not a valid cache backend" % scheme 
  • django/branches/queryset-refactor/django/core/exceptions.py

    r2809 r6857  
    44    "The requested object does not exist" 
    55    silent_variable_failure = True 
     6 
     7class MultipleObjectsReturned(Exception): 
     8    "The query returned multiple objects when only one was expected." 
     9    pass 
    610 
    711class SuspiciousOperation(Exception): 
  • django/branches/queryset-refactor/django/core/handlers/base.py

    r6690 r6857  
     1import sys 
     2 
     3from django import http 
    14from django.core import signals 
    25from django.dispatch import dispatcher 
    3 from django import http 
    4 import sys 
    56 
    67class BaseHandler(object): 
  • django/branches/queryset-refactor/django/core/handlers/modpython.py

    r6690 r6857  
     1import os 
     2from pprint import pformat 
     3 
     4from django import http 
     5from django.core import signals 
    16from django.core.handlers.base import BaseHandler 
    2 from django.core import signals 
    37from django.dispatch import dispatcher 
    48from django.utils import datastructures 
    59from django.utils.encoding import force_unicode 
    6 from django import http 
    7 from pprint import pformat 
    8 import os 
    910 
    1011# NOTE: do *not* import settings (or any module which eventually imports 
  • django/branches/queryset-refactor/django/core/handlers/wsgi.py

    r6690 r6857  
    66    from StringIO import StringIO 
    77 
     8from django import http 
     9from django.core import signals 
    810from django.core.handlers.base import BaseHandler 
    9 from django.core import signals 
    1011from django.dispatch import dispatcher 
    1112from django.utils import datastructures 
    1213from django.utils.encoding import force_unicode 
    13 from django import http 
    1414 
    1515# See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 
  • django/branches/queryset-refactor/django/core/management/base.py

    <
    r6597 r6857  
    173173    Copies either a Django application layout template or a Django project 
    174174    layout template into the specified directory. 
    175  
    176     * style - A color style object (see django.core.management.color). 
    177     * app_or_project - The string 'app' or 'project'. 
    178     * name - The name of the application or project. 
    179     * directory - The directory to copy the layout template to. 
    180