Django

Code

Changeset 3630

Show
Ignore:
Timestamp:
08/20/06 17:49:48 (2 years ago)
Author:
clong
Message:

[per-object-permissions] Update to trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/per-object-permissions/AUTHORS

    r3583 r3630  
    6969    dne@mayonnaise.net 
    7070    Jeremy Dunck <http://dunck.us/> 
     71    Andy Dustman <farcepest@gmail.com> 
    7172    Clint Ecker 
    7273    gandalf@owca.info 
  • django/branches/per-object-permissions/django/bin/compile-messages.py

    r3583 r3630  
    1212        basedir = os.path.abspath('locale') 
    1313    else: 
    14         print "this script should be run from the django svn tree or your project or app tree
     14        print "This script should be run from the Django SVN tree or your project or app tree.
    1515        sys.exit(1) 
    1616 
     
    2020                sys.stderr.write('processing file %s in %s\n' % (f, dirpath)) 
    2121                pf = os.path.splitext(os.path.join(dirpath, f))[0] 
    22                 cmd = 'msgfmt -o "%s.mo" "%s.po"' % (pf, pf) 
     22                # Store the names of the .mo and .po files in an environment 
     23                # variable, rather than doing a string replacement into the 
     24                # command, so that we can take advantage of shell quoting, to 
     25                # quote any malicious characters/escaping. 
     26                # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html 
     27                os.environ['djangocompilemo'] = pf + '.mo' 
     28                os.environ['djangocompilepo'] = pf + '.po' 
     29                cmd = 'msgfmt -o "$djangocompilemo" "$djangocompilepo"' 
    2330                os.system(cmd) 
    2431 
  • django/branches/per-object-permissions/django/conf/project_template/settings.py

    r3583 r3630  
    2727 
    2828SITE_ID = 1 
     29 
     30# If you set this to False, Django will make some optimizations so as not 
     31# to load the internationalization machinery. 
     32USE_I18N = True 
    2933 
    3034# Absolute path to the directory that holds media. 
  • django/branches/per-object-permissions/django/contrib/admin/templates/admin/base.html

    r3464 r3630  
    77{% block extrastyle %}{% endblock %} 
    88{% block extrahead %}{% endblock %} 
     9{% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE" />{% endblock %} 
    910</head> 
    1011{% load i18n %} 
  • django/branches/per-object-permissions/django/contrib/admin/views/doc.py

    r3583 r3630  
    227227    return render_to_response('admin_doc/model_detail.html', { 
    228228        'name': '%s.%s' % (opts.app_label, opts.object_name), 
    229         'summary': "Fields on %s objects" % opts.object_name, 
     229        'summary': _("Fields on %s objects") % opts.object_name, 
    230230        'description': model.__doc__, 
    231231        'fields': fields, 
  • django/branches/per-object-permissions/django/contrib/admin/views/main.py

    r3629 r3630  
    273273                return HttpResponseRedirect(post_url_continue % pk_value) 
    274274            if request.POST.has_key("_popup"): 
    275                 return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, %r, "%s");</script>' % \ 
     275                if type(pk_value) is str: # Quote if string, so JavaScript doesn't think it's a variable. 
     276                    pk_value = '"%s"' % pk_value.replace('"', '\\"') 
     277                return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, %s, "%s");</script>' % \ 
    276278                    (pk_value, str(new_object).replace('"', '\\"'))) 
    277279            elif request.POST.has_key("_addanother"): 
     
    735737 
    736738        # Apply keyword searches. 
     739        def construct_search(field_name): 
     740            if field_name.startswith('^'): 
     741                return "%s__istartswith" % field_name[1:] 
     742            elif field_name.startswith('='): 
     743                return "%s__iexact" % field_name[1:] 
     744            elif field_name.startswith('@'): 
     745                return "%s__search" % field_name[1:] 
     746            else: 
     747                return "%s__icontains" % field_name 
     748 
    737749        if self.lookup_opts.admin.search_fields and self.query: 
    738750            for bit in self.query.split(): 
    739                 or_queries = [models.Q(**{'%s__icontains' % field_name: bit}) for field_name in self.lookup_opts.admin.search_fields] 
     751                or_queries = [models.Q(**{construct_search(field_name): bit}) for field_name in self.lookup_opts.admin.search_fields] 
    740752                other_qs = QuerySet(self.model) 
    741753                other_qs = other_qs.filter(reduce(operator.or_, or_queries)) 
  • django/branches/per-object-permissions/django/core/cache/backends/memcached.py

    r2378 r3630  
    2121 
    2222    def set(self, key, value, timeout=0): 
    23         self._cache.set(key, value, timeout
     23        self._cache.set(key, value, timeout or self.default_timeout
    2424 
    2525    def delete(self, key): 
  • django/branches/per-object-permissions/django/middleware/cache.py

    r3464 r3630  
    4242    def process_request(self, request): 
    4343        "Checks whether the page is already cached and returns the cached version if available." 
     44        if self.cache_anonymous_only: 
     45            assert hasattr(request, 'user'), "The Django cache middleware with CACHE_MIDDLEWARE_ANONYMOUS_ONLY=True requires authentication middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware' before the CacheMiddleware." 
     46 
    4447        if not request.method in ('GET', 'HEAD') or request.GET: 
    4548            request._cache_update_cache = False 
  • django/branches/per-object-permissions/django/middleware/http.py

    r3171 r3630  
    3636 
    3737        return response 
     38 
     39class SetRemoteAddrFromForwardedFor(object): 
     40    """ 
     41    Middleware that sets REMOTE_ADDR based on HTTP_X_FORWARDED_FOR, if the 
     42    latter is set. This is useful if you're sitting behind a reverse proxy that 
     43    causes each request's REMOTE_ADDR to be set to 127.0.0.1. 
     44 
     45    Note that this does NOT validate HTTP_X_FORWARDED_FOR. If you're not behind 
     46    a reverse proxy that sets HTTP_X_FORWARDED_FOR automatically, do not use 
     47    this middleware. Anybody can spoof the value of HTTP_X_FORWARDED_FOR, and 
     48    because this sets REMOTE_ADDR based on HTTP_X_FORWARDED_FOR, that means 
     49    anybody can "fake" their IP address. Only use this when you can absolutely 
     50    trust the value of HTTP_X_FORWARDED_FOR. 
     51    """ 
     52    def process_request(self, request): 
     53        try: 
     54            real_ip = request.META['HTTP_X_FORWARDED_FOR'] 
     55        except KeyError: 
     56            return None 
     57        else: 
     58            # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs. 
     59            # Take just the first one. 
     60            real_ip = real_ip.split(",")[0] 
     61            request.META['REMOTE_ADDR'] = real_ip 
  • django/branches/per-object-permissions/docs/cache.txt

    r3464 r3630  
    234234``True``, only anonymous requests (i.e., not those made by a logged-in user) 
    235235will be cached. This is a simple and effective way of disabling caching for any 
    236 user-specific pages (include Django's admin interface). 
     236user-specific pages (include Django's admin interface). Note that if you use 
     237``CACHE_MIDDLEWARE_ANONYMOUS_ONLY``, you should make sure you've activated 
     238``AuthenticationMiddleware`` and that ``AuthenticationMiddleware`` appears 
     239before ``CacheMiddleware`` in your ``MIDDLEWARE_CLASSES``. 
    237240 
    238241Additionally, ``CacheMiddleware`` automatically sets a few headers in each 
  • django/branches/per-object-permissions/docs/faq.txt

    r3583 r3630  
    9999 
    100100`Wilson Miner`_ 
    101     Wilson's design-fu makes us all look like rock stars. When not sneaking 
    102     into apartment complex swimming pools, he's the Commercial Development 
    103     Director for World Online, which means he makes the money that pays all our 
    104     paychecks. He lives in Lawrence, Kansas. 
    105  
     101    Wilson's design-fu makes us all look like rock stars. By day, he's an  
     102    interactive designer for `Apple`. Don't ask him what he's working on, or 
     103    he'll have to kill you. He lives in San Francisco. 
     104     
    106105    On IRC, Wilson goes by ``wilsonian``. 
    107106 
     
    114113.. _`Jacob Kaplan-Moss`: http://www.jacobian.org/ 
    115114.. _`Wilson Miner`: http://www.wilsonminer.com/ 
     115.. _`Apple`: http://www.apple.com/ 
    116116 
    117117Which sites use Django? 
  • django/branches/per-object-permissions/docs/i18n.txt

    r3464 r3630  
    4949``USE_I18N = False`` in your settings file. If ``USE_I18N`` is set to 
    5050``False``, then Django will make some optimizations so as not to load the 
    51 internationalization machinery. 
    52  
    53 See the `documentation for USE_I18N`_. 
     51internationalization machinery. See the `documentation for USE_I18N`_. 
     52 
     53You'll probably also want to remove ``'django.core.context_processors.i18n'`` 
     54from your ``TEMPLATE_CONTEXT_PROCESSORS`` setting. 
    5455 
    5556.. _documentation for USE_I18N: http://www.djangoproject.com/documentation/settings/#use-i18n 
  • django/branches/per-object-permissions/docs/middleware.txt

    r2980 r3630  
    6464  redirected to ``foo.com/bar/``, but ``foo.com/bar/file.txt`` is passed 
    6565  through unchanged. 
    66    
     66 
    6767  If ``PREPEND_WWW`` is ``True``, URLs that lack a leading "www." will be 
    6868  redirected to the same URL with a leading "www." 
     
    101101Also removes the content from any response to a HEAD request and sets the 
    102102``Date`` and ``Content-Length`` response-headers. 
     103 
     104django.middleware.http.SetRemoteAddrFromForwardedFor 
     105---------------------------------------------------- 
     106 
     107**New in Django development version** 
     108 
     109Sets ``request['REMOTE_ADDR']`` based on ``request.['HTTP_X_FORWARDED_FOR']``, 
     110if the latter is set. This is useful if you're sitting behind a reverse proxy 
     111that causes each request's ``REMOTE_ADDR`` to be set to ``127.0.0.1``. 
     112 
     113**Important note:** This does NOT validate ``HTTP_X_FORWARDED_FOR``. If you're 
     114not behind a reverse proxy that sets ``HTTP_X_FORWARDED_FOR`` automatically, do 
     115not use this middleware. Anybody can spoof the value of 
     116``HTTP_X_FORWARDED_FOR``, and because this sets ``REMOTE_ADDR`` based on 
     117``HTTP_X_FORWARDED_FOR``, that means anybody can "fake" their IP address. Only 
     118use this when you can absolutely trust the value of ``HTTP_X_FORWARDED_FOR``. 
    103119 
    104120django.contrib.sessions.middleware.SessionMiddleware 
  • django/branches/per-object-permissions/docs/model-api.txt

    r3583 r3630  
    218218 
    219219    3. All that will be stored in your database is a path to the file 
    220        (relative to ``MEDIA_ROOT``). You'll must likely want to use the 
     220       (relative to ``MEDIA_ROOT``). You'll most likely want to use the 
    221221       convenience ``get_<fieldname>_url`` function provided by Django. For 
    222222       example, if your ``ImageField`` is called ``mug_shot``, you can get 
     
    230230upload a file on Jan. 15, 2007, it will be saved in the directory 
    231231``/home/media/photos/2007/01/15``. 
     232 
     233Note that whenever you deal with uploaded files, you should pay close attention 
     234to where you're uploading them and what type of files they are, to avoid 
     235security holes. *Validate all uploaded files* so that you're sure the files are 
     236what you think they are. For example, if you blindly let somebody upload files, 
     237without validation, to a directory that's within your Web server's document 
     238root, then somebody could upload a CGI or PHP script and execute that script by 
     239visiting its URL on your site. Don't allow that. 
    232240 
    233241.. _`strftime formatting`: http://docs.python.org/lib/module-time.html#l2h-1941 
     
    679687        # ... 
    680688 
    681 Note, however, that support for strings around model names in ``ForeignKey`` is 
    682 quite new, and it can be buggy in some cases. 
     689Note, however, that you can only use strings to refer to models in the same 
     690models.py file -- you cannot use a string to reference a model in a different 
     691application, or to reference a model that has been imported from elsewhere. 
    683692 
    684693Behind the scenes, Django appends ``"_id"`` to the field name to create its 
     
    802811As with ``ForeignKey``, a relationship to self can be defined by using the 
    803812string ``'self'`` instead of the model name, and you can refer to as-yet 
    804 undefined models by using a string containing the model name. 
     813undefined models by using a string containing the model name. However, you 
     814can only use strings to refer to models in the same models.py file -- you 
     815cannot use a string to reference a model in a different application, or to 
     816reference a model that has been imported from elsewhere. 
    805817 
    806818It's suggested, but not required, that the name of a ``ManyToManyField`` 
     
    13741386    WHERE (first_name ILIKE '%john%' OR last_name ILIKE '%john%') 
    13751387    AND (first_name ILIKE '%lennon%' OR last_name ILIKE '%lennon%') 
     1388 
     1389**New in Django development version:** For faster and/or more restrictive 
     1390searches, prefix the field name with an operator: 
     1391 
     1392``^`` 
     1393    Matches the beginning of the field. For example, if ``search_fields`` is 
     1394    set to ``['^first_name', '^last_name']`` and a user searches for 
     1395    ``john lennon``, Django will do the equivalent of this SQL ``WHERE`` 
     1396    clause:: 
     1397 
     1398        WHERE (first_name ILIKE 'john%' OR last_name ILIKE 'john%') 
     1399        AND (first_name ILIKE 'lennon%' OR last_name ILIKE 'lennon%') 
     1400 
     1401    This query is more efficient than the normal ``'%john%'`` query, because 
     1402    the database only needs to check the beginning of a column's data, rather 
     1403    than seeking through the entire column's data. Plus, if the column has an 
     1404    index on it, some databases may be able to use the index for this query, 
     1405    even though it's a ``LIKE`` query. 
     1406 
     1407``=`` 
     1408    Matches exactly, case-insensitive. For example, if 
     1409    ``search_fields`` is set to ``['=first_name', '=last_name']`` and 
     1410    a user searches for ``john lennon``, Django will do the equivalent 
     1411    of this SQL ``WHERE`` clause:: 
     1412 
     1413        WHERE (first_name ILIKE 'john' OR last_name ILIKE 'john') 
     1414        AND (first_name ILIKE 'lennon' OR last_name ILIKE 'lennon') 
     1415 
     1416    Note that the query input is split by spaces, so, following this example, 
     1417    it's not currently not possible to search for all records in which 
     1418    ``first_name`` is exactly ``'john winston'`` (containing a space). 
     1419 
     1420``@`` 
     1421    Performs a full-text match. This is like the default search method but uses 
     1422    an index. Currently this is only available for MySQL. 
    13761423 
    13771424Managers 
  • django/branches/per-object-permissions/docs/templates_python.txt

    r3583 r3630  
    260260variables, according to your `TEMPLATE_CONTEXT_PROCESSORS setting`_. 
    261261 
    262 The ``TEMPLATE_CONTEXT_PROCESSORS`` setting is a tuple of callables that take a 
    263 request object as their argument and return a dictionary of items to be merged 
    264 into the context. By default, ``TEMPLATE_CONTEXT_PROCESSORS`` is set to:: 
     262The ``TEMPLATE_CONTEXT_PROCESSORS`` setting is a tuple of callables -- called 
     263**context processors** -- that take a request object as their argument and 
     264return a dictionary of items to be merged into the context. By default, 
     265``TEMPLATE_CONTEXT_PROCESSORS`` is set to:: 
    265266 
    266267    ("django.core.context_processors.auth",