Ticket #10061: admin-urls.12.diff

File admin-urls.12.diff, 14.4 KB (added by Alex, 6 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index c87d903..87652e1 100644
    a b class ModelAdmin(BaseModelAdmin): 
    235235            url(r'^add/$',
    236236                wrap(self.add_view),
    237237                name='%sadmin_%s_%s_add' % info),
    238             url(r'^(.+)/history/$',
     238            url(r'^(?P<object_id>.+)/history/$',
    239239                wrap(self.history_view),
    240240                name='%sadmin_%s_%s_history' % info),
    241             url(r'^(.+)/delete/$',
     241            url(r'^(?P<object_id>.+)/delete/$',
    242242                wrap(self.delete_view),
    243243                name='%sadmin_%s_%s_delete' % info),
    244             url(r'^(.+)/$',
     244            url(r'^(?P<object_id>.+)/$',
    245245                wrap(self.change_view),
    246246                name='%sadmin_%s_%s_change' % info),
    247247        )
    class ModelAdmin(BaseModelAdmin): 
    579579            'save_as': self.save_as,
    580580            'save_on_top': self.save_on_top,
    581581            'root_path': self.admin_site.root_path,
     582            'admin_site': self.admin_site.name,
    582583        })
    583584        return render_to_response(self.change_form_template or [
    584585            "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
    class ModelAdmin(BaseModelAdmin): 
    776777            'errors': helpers.AdminErrorList(form, formsets),
    777778            'root_path': self.admin_site.root_path,
    778779            'app_label': opts.app_label,
     780            'admin_site': self.admin_site.name,
    779781        }
    780782        context.update(extra_context or {})
    781783        return self.render_change_form(request, context, add=True)
    class ModelAdmin(BaseModelAdmin): 
    864866            'inline_admin_formsets': inline_admin_formsets,
    865867            'errors': helpers.AdminErrorList(form, formsets),
    866868            'root_path': self.admin_site.root_path,
     869            'admin_site': self.admin_site.name,
    867870            'app_label': opts.app_label,
    868871        }
    869872        context.update(extra_context or {})
    class ModelAdmin(BaseModelAdmin): 
    969972            'media': media,
    970973            'has_add_permission': self.has_add_permission(request),
    971974            'root_path': self.admin_site.root_path,
     975            'admin_site': self.admin_site.name,
    972976            'app_label': app_label,
    973977            'action_form': action_form,
    974978            'actions_on_top': self.actions_on_top,
    class ModelAdmin(BaseModelAdmin): 
    10271031            "perms_lacking": perms_needed,
    10281032            "opts": opts,
    10291033            "root_path": self.admin_site.root_path,
     1034            'admin_site': self.admin_site.name,
    10301035            "app_label": app_label,
    10311036        }
    10321037        context.update(extra_context or {})
    class ModelAdmin(BaseModelAdmin): 
    10541059            'module_name': capfirst(force_unicode(opts.verbose_name_plural)),
    10551060            'object': obj,
    10561061            'root_path': self.admin_site.root_path,
     1062            'admin_site': self.admin_site.name,
    10571063            'app_label': app_label,
    10581064        }
    10591065        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 6e9ef11..1ad86fd 100644
    a b from django.contrib.admin import ModelAdmin 
    44from django.contrib.admin import actions
    55from django.contrib.auth import authenticate, login
    66from django.db.models.base import ModelBase
     7from django.core.urlresolvers import reverse
    78from django.core.exceptions import ImproperlyConfigured
    89from django.shortcuts import render_to_response
    910from django.utils.functional import update_wrapper
    class AdminSite(object): 
    4041
    4142    def __init__(self, name=None):
    4243        self._registry = {} # model_class class -> admin_class instance
    43         # TODO Root path is used to calculate urls under the old root() method
    44         # in order to maintain backwards compatibility we are leaving that in
    45         # so root_path isn't needed, not sure what to do about this.
    46         self.root_path = 'admin/'
     44        self.root_path = None
    4745        if name is None:
    4846            name = ''
    4947        else:
    class AdminSite(object): 
    199197                name='%sadmin_index' % self.name),
    200198            url(r'^logout/$',
    201199                wrap(self.logout),
    202                 name='%sadmin_logout'),
     200                name='%sadmin_logout' % self.name),
    203201            url(r'^password_change/$',
    204202                wrap(self.password_change),
    205203                name='%sadmin_password_change' % self.name),
    class AdminSite(object): 
    233231        Handles the "change password" task -- both form display and validation.
    234232        """
    235233        from django.contrib.auth.views import password_change
    236         return password_change(request,
    237             post_change_redirect='%spassword_change/done/' % self.root_path)
     234        if self.root_path is not None:
     235            url = '%spassword_change/done/' % self.root_path
     236        else:
     237            url = reverse('%sadmin_password_change_done' % self.name)
     238        return password_change(request, post_change_redirect=url)
    238239
    239240    def password_change_done(self, request):
    240241        """
    class AdminSite(object): 
    360361            'title': _('Site administration'),
    361362            'app_list': app_list,
    362363            'root_path': self.root_path,
     364            'admin_site': self.name
    363365        }
    364366        context.update(extra_context or {})
    365367        return render_to_response(self.index_template or 'admin/index.html', context,
    class AdminSite(object): 
    374376            'app_path': request.get_full_path(),
    375377            'error_message': error_message,
    376378            'root_path': self.root_path,
     379            'admin_site': self.name,
    377380        }
    378381        context.update(extra_context or {})
    379382        return render_to_response(self.login_template or 'admin/login.html', context,
    class AdminSite(object): 
    417420            'title': _('%s administration') % capfirst(app_label),
    418421            'app_list': [app_dict],
    419422            'root_path': self.root_path,
     423            'admin_site': self.name,
    420424        }
    421425        context.update(extra_context or {})
    422426        return render_to_response(self.app_index_template or ('admin/%s/app_index.html' % app_label,
  • 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..8b0e784 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>{% firstof user.first_name user.username %}</strong>.
     31            {% block userlinks %}
     32                {% url django-admindocs-docroot as docsroot %}
     33                {% if docsroot %}
     34                    <a href="{{ docsroot }}">
     35                        {% trans 'Documentation' %}
     36                    </a> /
     37                {% endif %}
     38                {% url admin_site:admin_password_change as password_change_url %}
     39                {% if password_change_url %}
     40                    <a href="{{ password_change_url }}">
     41                {% else %}
     42                    <a href="{{ root_path }}password_change/">
     43                {% endif %}
     44                    {% trans 'Change password' %}
     45                </a> /
     46                {% url admin_site:admin_logout as logout_url %}
     47                {% if logout_url %}
     48                    <a href="{{ logout_url }}">
     49                {% else %}
     50                    <a href="{{ root_path }}logout/">
     51                {% endif %}
     52                    {% trans 'Log out' %}
     53                </a>
     54            {% endblock %}
     55        </div>
    2956        {% endif %}
    3057        {% block nav-global %}{% endblock %}
    3158    </div>
  • django/contrib/auth/admin.py

    diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
    index dedeb01..8e48ebd 100644
    a b class UserAdmin(admin.ModelAdmin): 
    9292            'save_as': False,
    9393            'username_help_text': self.model._meta.get_field('username').help_text,
    9494            'root_path': self.admin_site.root_path,
     95            'admin_site': self.admin_site.name,
    9596            'app_label': self.model._meta.app_label,           
    9697        }, context_instance=template.RequestContext(request))
    9798
    class UserAdmin(admin.ModelAdmin): 
    122123            'save_as': False,
    123124            'show_save': True,
    124125            'root_path': self.admin_site.root_path,
     126            'admin_site': self.admin_site.name,
    125127        }, context_instance=RequestContext(request))
    126128
    127129
  • django/contrib/comments/views/moderation.py

    diff --git a/django/contrib/comments/views/moderation.py b/django/contrib/comments/views/moderation.py
    index 3334b09..880c6d7 100644
    a b from django.core.paginator import Paginator, InvalidPage 
    77from django.http import Http404
    88from django.contrib import comments
    99from django.contrib.comments import signals
     10from django.contrib import admin
    1011
    1112#@login_required
    1213def flag(request, comment_id, next=None):
    def moderation_queue(request): 
    185186        'previous': page - 1,
    186187        'pages': paginator.num_pages,
    187188        'hits' : paginator.count,
    188         'page_range' : paginator.page_range
     189        'page_range' : paginator.page_range,
     190        'admin_site': admin.site.name,
    189191    }, context_instance=template.RequestContext(request))
    190192
    191193moderation_queue = permission_required("comments.can_moderate")(moderation_queue)
  • django/core/urlresolvers.py

    diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
    index ac83756..32ba34c 100644
    a b def resolve(path, urlconf=None): 
    257257    return get_resolver(urlconf).resolve(path)
    258258
    259259def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None):
     260    if isinstance(viewname, basestring):
     261        viewname = ''.join(viewname.split(':'))
    260262    args = args or []
    261263    kwargs = kwargs or {}
    262264    if prefix is None:
  • django/template/defaulttags.py

    diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
    index 835b1a9..2b1f151 100644
    a b class URLNode(Node): 
    357357
    358358    def render(self, context):
    359359        from django.core.urlresolvers import reverse, NoReverseMatch
     360        view_name_parts = []
     361        for part in self.view_name[:-1]:
     362            try:
     363                view_name_parts.append(Variable(part).resolve(context))
     364            except VariableDoesNotExist:
     365                view_name_parts.append(part)
     366        view_name_parts.append(self.view_name[-1])
     367        view_name = ':'.join(view_name_parts)
    360368        args = [arg.resolve(context) for arg in self.args]
    361369        kwargs = dict([(smart_str(k,'ascii'), v.resolve(context))
    362370                       for k, v in self.kwargs.items()])
    class URLNode(Node): 
    367375        # {% url ... as var %} construct in which cause return nothing.
    368376        url = ''
    369377        try:
    370             url = reverse(self.view_name, args=args, kwargs=kwargs)
     378            url = reverse(view_name, args=args, kwargs=kwargs)
    371379        except NoReverseMatch, e:
    372380            if settings.SETTINGS_MODULE:
    373381                project_name = settings.SETTINGS_MODULE.split('.')[0]
    374382                try:
    375                     url = reverse(project_name + '.' + self.view_name,
     383                    url = reverse(project_name + '.' + view_name,
    376384                              args=args, kwargs=kwargs)
    377385                except NoReverseMatch:
    378386                    if self.asvar is None:
    379387                        # Re-raise the original exception, not the one with
    380                         # the path relative to the project. This makes a 
     388                        # the path relative to the project. This makes a
    381389                        # better error message.
    382390                        raise e
    383391            else:
    def url(parser, token): 
    11051113        raise TemplateSyntaxError("'%s' takes at least one argument"
    11061114                                  " (path to a view)" % bits[0])
    11071115    viewname = bits[1]
     1116    if ':' in viewname:
     1117        viewname = viewname.split(':')
     1118    else:
     1119        viewname = [viewname]
    11081120    args = []
    11091121    kwargs = {}
    11101122    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 d7bce8f..7749a6e 100644
    a b class AdminViewBasicTest(TestCase): 
    199199        self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
    200200        response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'})
    201201        self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
     202   
     203    def testLogoutAndPasswordChangeURLs(self):
     204        response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit)
     205        self.failIf('<a href="/test_admin/%s/logout/">' % self.urlbit not in response.content)
     206        self.failIf('<a href="/test_admin/%s/password_change/">' % self.urlbit not in response.content)
    202207
    203208    def testNamedGroupFieldChoicesChangeList(self):
    204209        """
  • tests/urls.py

    diff --git a/tests/urls.py b/tests/urls.py
    index 6704829..31faea5 100644
    a b urlpatterns = patterns('', 
    2121    # test urlconf for middleware tests
    2222    (r'^middleware/', include('regressiontests.middleware.urls')),
    2323
     24    # admin widget tests
     25    (r'widget_admin/', include('regressiontests.admin_widgets.urls')),
     26
    2427    # admin view tests
    2528    (r'^test_admin/', include('regressiontests.admin_views.urls')),
    2629    (r'^generic_inline_admin/', include('regressiontests.generic_inline_admin.urls')),
    2730
    28     # admin widget tests
    29     (r'widget_admin/', include('regressiontests.admin_widgets.urls')),
    3031
    3132    (r'^utils/', include('regressiontests.utils.urls')),
    3233
Back to Top