Ticket #10061: admin-urls.3.diff

File admin-urls.3.diff, 9.5 KB (added by Alex Gaynor, 16 years ago)

added tests

  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index ed41c7f..6f063f0 100644
    a b class ModelAdmin(BaseModelAdmin):  
    437437            'save_as': self.save_as,
    438438            'save_on_top': self.save_on_top,
    439439            'root_path': self.admin_site.root_path,
     440            'admin_site': self.admin_site.name,
    440441        })
    441442        return render_to_response(self.change_form_template or [
    442443            "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
    class ModelAdmin(BaseModelAdmin):  
    571572            'errors': helpers.AdminErrorList(form, formsets),
    572573            'root_path': self.admin_site.root_path,
    573574            'app_label': opts.app_label,
     575            'admin_site': self.admin_site.name,
    574576        }
    575577        context.update(extra_context or {})
    576578        return self.render_change_form(request, context, add=True)
    class ModelAdmin(BaseModelAdmin):  
    649651            'inline_admin_formsets': inline_admin_formsets,
    650652            'errors': helpers.AdminErrorList(form, formsets),
    651653            'root_path': self.admin_site.root_path,
     654            'admin_site': self.admin_site.name,
    652655            'app_label': opts.app_label,
    653656        }
    654657        context.update(extra_context or {})
    class ModelAdmin(BaseModelAdmin):  
    681684            'cl': cl,
    682685            'has_add_permission': self.has_add_permission(request),
    683686            'root_path': self.admin_site.root_path,
     687            'admin_site': self.admin_site.name,
    684688            'app_label': app_label,
    685689        }
    686690        context.update(extra_context or {})
    class ModelAdmin(BaseModelAdmin):  
    736740            "perms_lacking": perms_needed,
    737741            "opts": opts,
    738742            "root_path": self.admin_site.root_path,
     743            'admin_site': self.admin_site.name,
    739744            "app_label": app_label,
    740745        }
    741746        context.update(extra_context or {})
    class ModelAdmin(BaseModelAdmin):  
    763768            'module_name': capfirst(force_unicode(opts.verbose_name_plural)),
    764769            'object': obj,
    765770            'root_path': self.admin_site.root_path,
     771            'admin_site': self.admin_site.name,
    766772            'app_label': app_label,
    767773        }
    768774        context.update(extra_context or {})
  • django/contrib/admin/sites.py

    diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
    index 42ce296..d77eebd 100644
    a b from django import http, template  
    33from django.contrib.admin import ModelAdmin
    44from django.contrib.auth import authenticate, login
    55from django.db.models.base import ModelBase
     6from django.core.urlresolvers import reverse
    67from django.core.exceptions import ImproperlyConfigured
    78from django.shortcuts import render_to_response
    89from django.utils.functional import update_wrapper
    class AdminSite(object):  
    3536   
    3637    def __init__(self, name=None):
    3738        self._registry = {} # model_class class -> admin_class instance
    38         # TODO Root path is used to calculate urls under the old root() method
    39         # in order to maintain backwards compatibility we are leaving that in
    40         # so root_path isn't needed, not sure what to do about this.
    41         self.root_path = 'admin/'
     39        self.root_path = None
    4240        if name is None:
    4341            name = ''
    4442        else:
    class AdminSite(object):  
    163161                name='%sadmin_index' % self.name),
    164162            url(r'^logout/$',
    165163                wrap(self.logout),
    166                 name='%sadmin_logout'),
     164                name='%sadmin_logout' % self.name),
    167165            url(r'^password_change/$',
    168166                wrap(self.password_change),
    169167                name='%sadmin_password_change' % self.name),
    class AdminSite(object):  
    197195        Handles the "change password" task -- both form display and validation.
    198196        """
    199197        from django.contrib.auth.views import password_change
     198        if self.root_path is not None:
     199            url = '%spassword_change/done/' % self.root_path
     200        else:
     201            url = reverse('%sadmin_password_change_done' % self.name)
    200202        return password_change(request,
    201             post_change_redirect='%spassword_change/done/' % self.root_path)
     203            post_change_redirect=url)
    202204   
    203205    def password_change_done(self, request):
    204206        """
    class AdminSite(object):  
    328330            'title': _('Site administration'),
    329331            'app_list': app_list,
    330332            'root_path': self.root_path,
     333            'admin_site': self.name
    331334        }
    332335        context.update(extra_context or {})
    333336        return render_to_response(self.index_template or 'admin/index.html', context,
    class AdminSite(object):  
    342345            'app_path': request.get_full_path(),
    343346            'error_message': error_message,
    344347            'root_path': self.root_path,
     348            'admin_site': self.name,
    345349        }
    346350        context.update(extra_context or {})
    347351        return render_to_response(self.login_template or 'admin/login.html', context,
    class AdminSite(object):  
    388392            'title': _('%s administration') % capfirst(app_label),
    389393            'app_list': [app_dict],
    390394            'root_path': self.root_path,
     395            'admin_site': self.name,
    391396        }
    392397        context.update(extra_context or {})
    393398        return render_to_response(self.app_index_template or 'admin/app_index.html', context,
  • django/contrib/admin/templates/admin/base.html

    diff --git a/django/contrib/admin/templates/admin/base.html b/django/contrib/admin/templates/admin/base.html
    index e969d1b..623d769 100644
    a b  
    2525        {% block branding %}{% endblock %}
    2626        </div>
    2727        {% if user.is_authenticated and user.is_staff %}
    28         <div id="user-tools">{% trans 'Welcome,' %} <strong>{% firstof user.first_name user.username %}</strong>. {% block userlinks %}{% url django-admindocs-docroot as docsroot %}{% if docsroot %}<a href="{{ docsroot }}">{% trans 'Documentation' %}</a> / {% endif %}<a href="{{ root_path }}password_change/">{% trans 'Change password' %}</a> / <a href="{{ root_path }}logout/">{% trans 'Log out' %}</a>{% endblock %}</div>
     28        <div id="user-tools">
     29            {% trans 'Welcome,' %}
     30            <strong>
     31                {% firstof user.first_name user.username %}
     32            </strong>.
     33            {% block userlinks %}
     34                {% url django-admindocs-docroot as docsroot %}
     35                {% if docsroot %}
     36                    <a href="{{ docsroot }}">
     37                        {% trans 'Documentation' %}
     38                    </a> /
     39                {% endif %}
     40                {% url admin_site:admin_password_change as password_change_url %}
     41                {% if password_change_url %}
     42                    <a href="{{ password_change_url }}">
     43                {% else %}
     44                    <a href="{{ root_path }}password_change/">
     45                {% endif %}
     46                    {% trans 'Change password' %}
     47                </a> /
     48                {% url admin_site:admin_logout as logout_url %}
     49                {% if logout_url %}
     50                    <a href="{{ logout_url }}">
     51                {% else %}
     52                    <a href="{{ root_path }}logout/">
     53                {% endif %}
     54                    {% trans 'Log out' %}
     55                </a>
     56            {% endblock %}
     57        </div>
    2958        {% endif %}
    3059        {% block nav-global %}{% endblock %}
    3160    </div>
  • django/template/defaulttags.py

    diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
    index 0911309..cc3cdd1 100644
    a b class URLNode(Node):  
    368368
    369369    def render(self, context):
    370370        from django.core.urlresolvers import reverse, NoReverseMatch
     371        if len(self.view_name) > 1:
     372            self.view_name = Variable(self.view_name[0]).resolve(context) + self.view_name[1]
     373        else:
     374            self.view_name = self.view_name[0]
    371375        args = [arg.resolve(context) for arg in self.args]
    372376        kwargs = dict([(smart_str(k,'ascii'), v.resolve(context))
    373377                       for k, v in self.kwargs.items()])
    def url(parser, token):  
    11021106        raise TemplateSyntaxError("'%s' takes at least one argument"
    11031107                                  " (path to a view)" % bits[0])
    11041108    viewname = bits[1]
     1109    if ':' in viewname:
     1110        viewname = viewname.split(':')
     1111    else:
     1112        viewname = [viewname]
    11051113    args = []
    11061114    kwargs = {}
    11071115    asvar = None
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 39daf11..7a4f09c 100644
    a b class AdminViewBasicTest(TestCase):  
    172172        self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)       
    173173        response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'})
    174174        self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
     175   
     176    def testLogoutAndPasswordChangeURLs(self):
     177        response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit)
     178        self.failIf('%s/logout/">' % self.urlbit not in response.content)
     179        self.failIf('%s/password_change/">' % self.urlbit not in response.content)
    175180
    176181class CustomModelAdminTest(AdminViewBasicTest):
    177182    urlbit = "admin2"
Back to Top