Django

Code

Changeset 3669

Show
Ignore:
Timestamp:
08/28/06 08:06:03 (2 years ago)
Author:
clong
Message:

[per-object-permissions] Merged to trunk 3666

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/per-object-permissions/django/conf/global_settings.py

    r3583 r3669  
    297297 
    298298AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',) 
     299 
     300########### 
     301# TESTING # 
     302########### 
     303 
     304TEST_RUNNER='django.test.simple.run_tests' 
  • django/branches/per-object-permissions/django/contrib/admin/media/css/global.css

    r3615 r3669  
    1 body { margin:0; padding:0; font-size:12px; font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif; color:#333; background:#fff; } 
     1body { margin:0; padding:0; font-size:12px; font-family:"Lucida Grande","DejaVu Sans","Bitstream Vera Sans",Verdana,Arial,sans-serif; color:#333; background:#fff; } 
    22 
    33/* LINKS */ 
  • django/branches/per-object-permissions/django/contrib/admin/templates/admin_doc/model_detail.html

    r3464 r3669  
    3636    <td>{{ field.name }}</td> 
    3737    <td>{{ field.data_type }}</td> 
    38     <td>{% if field.verbose %}{{ field.verbose|escape }}{% endif %}{% if field.help_text %} - {{ field.help_text|escape }}{% endif %}</td> 
     38    <td>{% if field.verbose %}{{ field.verbose }}{% endif %}{% if field.help_text %} - {{ field.help_text }}{% endif %}</td> 
    3939</tr> 
    4040{% endfor %} 
  • django/branches/per-object-permissions/django/contrib/admin/templatetags/admin_modify.py

    r3629 r3669  
    196196    if f.rel and isinstance(f.rel, models.ManyToManyRel) and f.rel.filter_interface: 
    197197        return '<script type="text/javascript">addEvent(window, "load", function(e) {' \ 
    198               ' SelectFilter.init("id_%s", "%s", %s, "%s"); });</script>\n' % ( 
     198              ' SelectFilter.init("id_%s", %r, %s, "%s"); });</script>\n' % ( 
    199199              f.name, f.verbose_name, f.rel.filter_interface-1, settings.ADMIN_MEDIA_PREFIX) 
    200200    else: 
  • django/branches/per-object-permissions/django/contrib/admin/views/main.py

    r3630 r3669  
    424424        return # Avoid recursing too deep. 
    425425    opts_seen = [] 
    426     for related in opts.related_objects(): 
     426    for related in opts.get_all_related_objects(): 
    427427        if related.opts in opts_seen: 
    428428            continue 
  • django/branches/per-object-permissions/django/contrib/auth/management.py

    r3172 r3669  
    1717    return perms + list(opts.permissions) 
    1818 
    19 def create_permissions(app, created_models): 
     19def create_permissions(app, created_models, verbosity): 
    2020    from django.contrib.contenttypes.models import ContentType 
    2121    from django.contrib.auth.models import Permission 
     
    2828            p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id, 
    2929                defaults={'name': name, 'content_type': ctype}) 
    30             if created
     30            if created and verbosity >= 2
    3131                print "Adding permission '%s'" % p 
    3232 
    33 def create_superuser(app, created_models): 
     33def create_superuser(app, created_models, verbosity, **kwargs): 
    3434    from django.contrib.auth.models import User 
    3535    from django.contrib.auth.create_superuser import createsuperuser as do_create 
    36     if User in created_models
     36    if User in created_models and kwargs.get('interactive', True)
    3737        msg = "\nYou just installed Django's auth system, which means you don't have " \ 
    3838                "any superusers defined.\nWould you like to create one now? (yes/no): " 
  • django/branches/per-object-permissions/django/contrib/contenttypes/management.py

    r3148 r3669  
    66from django.db.models import get_models, signals 
    77 
    8 def create_contenttypes(app, created_models): 
     8def create_contenttypes(app, created_models, verbosity): 
    99    from django.contrib.contenttypes.models import ContentType 
    1010    app_models = get_models(app) 
     
    2020                app_label=opts.app_label, model=opts.object_name.lower()) 
    2121            ct.save() 
    22             print "Adding content type '%s | %s'" % (ct.app_label, ct.model) 
     22            if verbosity >= 2: 
     23                print "Adding content type '%s | %s'" % (ct.app_label, ct.model) 
    2324 
    2425dispatcher.connect(create_contenttypes, signal=signals.post_syncdb) 
  • django/branches/per-object-permissions/django/contrib/flatpages/views.py

    r3464 r3669  
    44from django.http import HttpResponse 
    55from django.conf import settings 
     6from django.core.xheaders import populate_xheaders 
    67 
    78DEFAULT_TEMPLATE = 'flatpages/default.html' 
     
    3334        'flatpage': f, 
    3435    }) 
    35     return HttpResponse(t.render(c)) 
     36    response = HttpResponse(t.render(c)) 
     37    populate_xheaders(request, response, FlatPage, f.id) 
     38    return response 
  • django/branches/per-object-permissions/django/contrib/sites/management.py

    r2809 r3669  
    88from django.contrib.sites import models as site_app 
    99 
    10 def create_default_site(app, created_models): 
     10def create_default_site(app, created_models, verbosity): 
    1111    if Site in created_models: 
    12         print "Creating example.com Site object" 
     12        if verbosity >= 2: 
     13            print "Creating example.com Site object" 
    1314        s = Site(domain="example.com", name="example.com") 
    1415        s.save() 
  • django/branches/per-object-permissions/django/core/management.py

    r3583 r3669  
    424424get_sql_all.args = APP_ARGS 
    425425 
    426 def syncdb(): 
     426def syncdb(verbosity=2, interactive=True): 
    427427    "Creates the database tables for all apps in INSTALLED_APPS whose tables haven't already been created." 
    428428    from django.db import connection, transaction, models, get_creation_module 
     
    472472                    pending_references[refto] = refs 
    473473            sql.extend(_get_sql_for_pending_references(model, pending_references)) 
    474             print "Creating table %s" % model._meta.db_table 
     474            if verbosity >= 2: 
     475                print "Creating table %s" % model._meta.db_table 
    475476            for statement in sql: 
    476477                cursor.execute(statement) 
     
    481482                sql = _get_many_to_many_sql_for_model(model) 
    482483                if sql: 
    483                     print "Creating many-to-many tables for %s model" % model.__name__ 
     484                    if verbosity >= 2: 
     485                        print "Creating many-to-many tables for %s model" % model.__name__ 
    484486                    for statement in sql: 
    485487                        cursor.execute(statement) 
     
    491493    for app in models.get_apps(): 
    492494        dispatcher.send(signal=signals.post_syncdb, sender=app, 
    493             app=app, created_models=created_models) 
     495            app=app, created_models=created_models,  
     496            verbosity=verbosity, interactive=interactive) 
    494497 
    495498        # Install initial data for the app (but only if this is a model we've 
     
    11551158runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]' 
    11561159 
     1160def test(verbosity, app_labels): 
     1161    "Runs the test suite for the specified applications" 
     1162    from django.conf import settings 
     1163    from django.db.models import get_app, get_apps 
     1164 
     1165    if len(app_labels) == 0: 
     1166        app_list = get_apps() 
     1167    else: 
     1168        app_list = [get_app(app_label) for app_label in app_labels] 
     1169     
     1170    test_path = settings.TEST_RUNNER.split('.') 
     1171    # Allow for Python 2.5 relative paths 
     1172    if len(test_path) > 1: 
     1173        test_module_name = '.'.join(test_path[:-1]) 
     1174    else: 
     1175        test_module_name = '.' 
     1176    test_module = __import__(test_module_name, [],[],test_path[-1]) 
     1177    test_runner = getattr(test_module, test_path[-1]) 
     1178     
     1179    test_runner(app_list, verbosity) 
     1180test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified' 
     1181test.args = '[--verbosity] ' + APP_ARGS 
     1182 
    11571183# Utilities for command-line script 
    11581184 
     
    11791205    'syncdb': syncdb, 
    11801206    'validate': validate, 
     1207    'test':test, 
    11811208} 
    11821209 
     
    12291256    parser.add_option('--plain', action='store_true', dest='plain', 
    12301257        help='Tells Django to use plain Python, not IPython, for "shell" command.') 
     1258    parser.add_option('--noinput', action='store_false', dest='interactive', default=True, 
     1259        help='Tells Django to NOT prompt the user for input of any kind.') 
    12311260    parser.add_option('--noreload', action='store_false', dest='use_reloader', default=True, 
    12321261        help='Tells Django to NOT use the auto-reloader when running the development server.') 
     1262    parser.add_option('--verbosity', action='store', dest='verbosity', default='2', 
     1263        type='choice', choices=['0', '1', '2'], 
     1264        help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') 
     1265 
    12331266    options, args = parser.parse_args(argv[1:]) 
    12341267 
     
    12571290    if action == 'shell': 
    12581291        action_mapping[action](options.plain is True) 
    1259     elif action in ('syncdb', 'validate', 'diffsettings', 'dbshell'): 
     1292    elif action in ('validate', 'diffsettings', 'dbshell'): 
    12601293        action_mapping[action]() 
     1294    elif action == 'syncdb': 
     1295        action_mapping[action](int(options.verbosity), options.interactive) 
    12611296    elif action == 'inspectdb': 
    12621297        try: 
     
    12691304        try: 
    12701305            action_mapping[action](args[1]) 
     1306        except IndexError: 
     1307            parser.print_usage_and_exit() 
     1308    elif action == 'test': 
     1309        try: 
     1310            action_mapping[action](int(options.verbosity), args[1:]) 
    12711311        except IndexError: 
    12721312            parser.print_usage_and_exit() 
  • django/branches/per-object-permissions/django/core/validators.py

    r3305 r3669  
    6969def isSlug(field_data, all_data): 
    7070    if not slug_re.search(field_data): 
    71         raise ValidationError, "This value must contain only letters, numbers, underscores or hyphens." 
     71        raise ValidationError, gettext("This value must contain only letters, numbers, underscores or hyphens.") 
    7272 
    7373def isLowerCase(field_data, all_data): 
  • django/branches/per-object-permissions/django/views/generic/date_based.py

    r3464 r3669  
    22from django.core.exceptions import ObjectDoesNotExist 
    33from django.core.xheaders import populate_xheaders 
     4from django.db.models.fields import DateTimeField 
    45from django.http import Http404, HttpResponse 
    56import datetime, time 
     
    236237    now = datetime.datetime.now() 
    237238 
    238     lookup_kwargs = { 
    239         '%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)), 
    240     } 
     239    if isinstance(model._meta.get_field(date_field), DateTimeField): 
     240        lookup_kwargs = {'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))} 
     241    else: 
     242        lookup_kwargs = {date_field: date} 
    241243 
    242244    # Only bother to check current date if the date isn't in the past and future objects aren't requested. 
     
    305307    now = datetime.datetime.now() 
    306308 
    307     lookup_kwargs = { 
    308         '%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)), 
    309     } 
     309    if isinstance(model._meta.get_field(date_field), DateTimeField): 
     310        lookup_kwargs = {'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))} 
     311    else: 
     312        lookup_kwargs = {date_field: date} 
    310313 
    311314    # Only bother to check current date if the date isn't in the past and future objects aren't requested. 
  • django/branches/per-object-permissions/docs/faq.txt

    r3630 r3669  
    1717perfectionists when it comes to following best practices of Web development. 
    1818 
    19 Thus, Django was designed not only to allow fast Web development, but 
    20 *best-practice* Web development. 
    21  
    22 Django would not be possible without a whole host of open-source projects -- 
    23 `Apache`_, `Python`_, and `PostgreSQL`_ to name a few -- and we're thrilled to 
    24 be able to give something back to the open-source community. 
     19In fall 2003, the World Online developers (Adrian Holovaty and Simon Willison) 
     20ditched PHP and began using Python to develop its Web sites. As they built 
     21intensive, richly interactive sites such as Lawrence.com, they began to extract 
     22a generic Web development framework that let them build Web applications more 
     23and more quickly. They tweaked this framework constantly, adding improvements 
     24over two years. 
     25 
     26In summer 2005, World Online decided to open-source the resulting software, 
     27Django. Django would not be possible without a whole host of open-source 
     28projects -- `Apache`_, `Python`_, and `PostgreSQL`_ to name a few -- and we're 
     29thrilled to be able to give something back to the open-source community. 
    2530 
    2631.. _Apache: http://httpd.apache.org/ 
     
    4348----------------- 
    4449 
    45 Yes. World Online has been using Django for more than two years. Sites built on 
    46 Django have weathered traffic spikes of over one million hits an hour and a 
     50Yes. World Online has been using Django for more than three years. Sites built 
     51on Django have weathered traffic spikes of over one million hits an hour and a 
    4752number of Slashdottings. Yes, it's quite stable. 
    4853 
     
    631636================= 
    632637 
     638How can I get started contributing code to Django? 
     639-------------------------------------------------- 
     640 
     641Thanks for asking! We've written an entire document devoted to this question. 
     642It's titled `Contributing to Django`_. 
     643 
     644.. _Contributing do Django: http://www.djangoproject.com/documentation/contributing/ 
     645 
    633646I submitted a bug fix in the ticket system several weeks ago. Why are you ignoring my patch? 
    634647-------------------------------------------------------------------------------------------- 
  • django/branches/per-object-permissions/docs/model-api.txt

    r3630 r3669  
    12231223 
    12241224    * ``ManyToManyField`` fields aren't supported, because that would entail 
    1225         executing a separate SQL statement for each row in the table. 
    1226  
    1227     * If the field is a ``BooleanField``, Django will display a pretty "on" or 
    1228       "off" icon instead of ``True`` or ``False``. 
     1225      executing a separate SQL statement for each row in the table. If you 
     1226      want to do this nonetheless, give your model a custom method, and add 
     1227      that method's name to ``list_display``. (See below for more on custom 
     1228      methods in ``list_display``.) 
     1229 
     1230    * If the field is a ``BooleanField`` or ``NullBooleanField``, Django will 
     1231      display a pretty "on" or "off" icon instead of ``True`` or ``False``. 
    12291232 
    12301233    * If the string given is a method of the model, Django will call it and 
     
    12621265                  return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name) 
    12631266              colored_name.allow_tags = True 
     1267 
     1268    * The ``__str__()`` method is just as valid in ``list_display`` as any 
     1269      other model method, so it's perfectly OK to do this:: 
     1270 
     1271          list_display = ('__str__', 'some_other_field') 
     1272 
     1273    * For any element of ``list_display`` that is not a field on the model, the 
     1274      change list page will not allow ordering by that column. This is because 
     1275      ordering is done at the database level, and Django has no way of knowing 
     1276      how to order the result of a custom method at the SQL level. 
    12641277 
    12651278``list_display_links`` 
  • django/branches/per-object-permissions/docs/overview.txt

    r2871 r3669  
    160160code. 
    161161 
    162 Here's what a URLconf might look like for the above ``Reporter``/``Article`` 
     162Here's what a URLconf might look like for the ``Reporter``/``Article`` 
    163163example above:: 
    164164 
  • django/branches/per-object-permissions/docs/settings.txt

    r3583 r3669  
    474474 
    475475    LANGUAGES = ( 
     476        ('ar', _('Arabic')), 
    476477        ('bn', _('Bengali')), 
    477478        ('cs', _('Czech')), 
     
    479480        ('da', _('Danish')), 
    480481        ('de', _('German')), 
     482        ('el', _('Greek')), 
    481483        ('en', _('English')), 
    482484        ('es', _('Spanish')), 
     485        ('es_AR', _('Argentinean Spanish')), 
    483486        ('fr', _('French')), 
    484487        ('gl', _('Galician')), 
     488        ('hu', _('Hungarian')), 
     489        ('he', _('Hebrew')), 
    485490        ('is', _('Icelandic')), 
    486491        ('it', _('Italian')), 
     492        ('ja', _('Japanese')), 
     493        ('nl', _('Dutch')), 
    487494        ('no', _('Norwegian')), 
    488495        ('pt-br', _('Brazilian')), 
     
    490497        ('ru', _('Russian')), 
    491498        ('sk', _('Slovak')), 
     499        ('sl', _('Slovenian')), 
    492500        ('sr', _('Serbian')), 
    493501        ('sv', _('Swedish')), 
     502        ('ta', _('Tamil')), 
     503        ('uk', _('Ukrainian')), 
    494504        ('zh-cn', _('Simplified Chinese')), 
     505        ('zh-tw', _('Traditional Chinese')), 
    495506    ) 
    496507 
  • django/branches/per-object-permissions/docs/templates.txt

    r3583 r3669  
    142142        </div> 
    143143    </body> 
     144    </html> 
    144145 
    145146This template, which we'll call ``base.html``, defines a simple HTML skeleton 
     
    197198        </div> 
    198199    </body> 
     200    </html> 
    199201 
    200202Note that since the child template didn't define the ``sidebar`` block, the 
     
    364366Signal that this template extends a parent template. 
    365367 
    366 This tag can be used in two ways:  
     368This tag can be used in two ways: 
    367369 
    368370   * ``{% extends "base.html" %}`` (with quotes) uses the literal value 
     
    962964~~~~~~~~~ 
    963965 
    964 Returns a plural suffix if the value is not 1. By default, this suffix is ``'s'``.  
     966Returns a plural suffix if the value is not 1. By default, this suffix is ``'s'``. 
    965967 
    966968Example:: 
     
    968970    You have {{ num_messages }} message{{ num_messages|pluralize }}. 
    969971 
    970 For words that require a suffix other than ``'s'``, you can provide an alternate  
     972For words that require a suffix other than ``'s'``, you can provide an alternate 
    971973suffix as a parameter to the filter. 
    972974 
  • django/branches/per-object-permissions/tests/modeltests/basic/models.py

    r3217 r3669  
    1414        return self.headline 
    1515 
    16 API_TESTS = """ 
    17  
     16__test__ = {'API_TESTS': """ 
    1817# No articles are in the system yet. 
    1918>>> Article.objects.all() 
     
    315314[<Article: Article 6>, <Article: Default headline>, <Article: Article 7>, <Article: Updated article 8>] 
    316315 
    317 """ 
     316"""} 
    318317 
    319318from django.conf import settings 
     
    322321 
    323322if building_docs or settings.DATABASE_ENGINE == 'postgresql': 
    324     API_TESTS += """ 
     323    __test__['API_TESTS'] += """ 
    325324# In PostgreSQL, microsecond-level precision is available. 
    326325>>> a9 = Article(headline='Article 9', pub_date=datetime(2005, 7, 31, 12, 30, 45, 180)) 
     
    331330 
    332331if building_docs or settings.DATABASE_ENGINE == 'mysql': 
    333     API_TESTS += """ 
     332    __test__['API_TESTS'] += """ 
    334333# In MySQL, microsecond-level precision isn't available. You'll lose 
    335334# microsecond-level precision once the data is saved. 
     
    340339""" 
    341340 
    342 API_TESTS += """ 
     341__test__['API_TESTS'] += """ 
    343342 
    344343# You can manually specify the primary key when creating a new object. 
  • django/branches/per-object-permissions/tests/modeltests/choices/models.py

    r3075 r3669  
    2424        return self.name 
    2525 
    26 API_TESTS = """ 
     26__test__ = {'API_TESTS':""" 
    2727>>> a = Person(name='Adrian', gender='M') 
    2828>>> a.save() 
     
    3737>>> s.get_gender_display() 
    3838'Female' 
    39 """ 
     39"""} 
  • django/branches/per-object-permissions/tests/modeltests/custom_columns/models.py

    r3075 r3669  
    1616        return '%s %s' % (self.first_name, self.last_name) 
    1717 
    18 API_TESTS = """ 
     18__test__ = {'API_TESTS':""" 
    1919# Create a Person. 
    2020>>> p = Person(first_name='John', last_name='Smith') 
     
    5151    ... 
    5252AttributeError: 'Person' object has no attribute 'last' 
    53 """ 
     53"""} 
  • django/branches/per-object-permissions/tests/modeltests/custom_managers/models.py

    r3075 r3669  
    5959        return self.name 
    6060 
    61 API_TESTS = """ 
     61__test__ = {'API_TESTS':""" 
    6262>>> p1 = Person(first_name='Bugs', last_name='Bunny', fun=True) 
    6363>>> p1.save() 
     
    105105>>> Car._default_manager.order_by('name') 
    106106[<Car: Corvette>, <Car: Neon>] 
    107 """ 
     107"""} 
  • django/branches/per-object-permissions/tests/modeltests/custom_methods/models.py

    r3075 r3669  
    3737        return [self.__class__(*row) for row