Get the base name of the admin route for a model or model instance.

    For use with :func:`django.urls.reverse`, although it still needs the specific route suffix
    appended, for example ``_changelist``.
328231
def _get_admin_route_name(model_or_instance):
    
    model = model_or_instance if isinstance(model_or_instance, type) else type(model_or_instance)
    return 'admin:{meta.app_label}_{meta.model_name}'.format(meta=model._meta)
1085919
def get_route(self, name):
        '''
        '''
        for route in self.routes:
            if route.name == name:
                return route
        for child in self.routes:
            route = child.get_route(name)
            if route:
                return route
265455
def basename(self, suffix=''):
		''' '''
		return os.path.basename(self._file, suffix) if self._file else None
971195
def comment_admin_urlname(action):
    
    comment = get_comment_model()
    return 'admin:%s_%s_%s' % (
        comment._meta.app_label, comment._meta.model_name,
        action)
113538
def get_admin_url(obj, page=None):
    """"""
    if obj is None:
        return None

    if page is None:
        page = "change"
    if page not in ADMIN_ALL_PAGES:
        raise ValueError("Invalid page name '{}'. Available pages are: {}.".format(page, ADMIN_ALL_PAGES))

    app_label = obj.__class__._meta.app_label
    object_name = obj.__class__._meta.object_name.lower()

    if page in ADMIN_GLOBAL_PAGES:
        url_name = page
    else:
        url_name = "{}_{}_{}".format(app_label, object_name, page)

    if page == "app_list":
        url_args = (app_label,)
    elif page == "view_on_site":
        content_type = ContentType.objects.get_for_model(obj.__class__)
        url_args = (content_type, obj._get_pk_val())
    elif page in ADMIN_DETAIL_PAGES:
        url_args = (obj._get_pk_val(),)
    else:
        url_args = None

    return reverse("admin:{}".format(url_name), args=url_args)
489877
def find_route_by_view_name(self, view_name, name=None):
        
        if not view_name:
            return (None, None)

        if view_name == "static" or view_name.endswith(".static"):
            return self.routes_static_files.get(name, (None, None))

        return self.routes_names.get(view_name, (None, None))
995885
def get_urls(self):
        
        urls = super(FormSubmissionAdmin, self).get_urls()
        from django.conf.urls import url

        def wrap(view):
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            return update_wrapper(wrapper, view)

        info = self.model._meta.app_label, self.model._meta.model_name

        extra_urls = [
            url(r'^export/$', wrap(self.export_view), name='%s_%s_export' % info),
        ]
        return extra_urls + urls
1342283
def url_reverse(request):
    
    if request.method in ('GET', 'POST'): 
        data = getattr(request, request.method) 
        url_name = data.get('url_name') 
        try: 
            path = urls.reverse(url_name, args=data.getlist('args')) 
            (view_func, args, kwargs) = urls.resolve(path)
            return http.HttpResponse(path, content_type='text/plain')
        except urls.NoReverseMatch: 
            return http.HttpResponse('Error', content_type='text/plain')
    return http.HttpResponseNotAllowed(('GET', 'POST'))
225672
def get_url(self, url):
        
        if url.startswith('/'):
            url = '%s%s' % (self.base_url, url)
        return url
28410
def name(self):
        
        if self._meta and self._meta.get('name'):
            # get it from the meta file
            return self._meta.get('name')
        # infer it from the basename
        return self.basename.replace('_', ' ').title()
1208743
def get_forum_perms_base_context(self, request, obj=None):
        
        context = {
            'adminform': {'model_admin': self},
            'media': self.media,
            'object': obj,
            'app_label': self.model._meta.app_label,
            'opts': self.model._meta,
            'has_change_permission': self.has_change_permission(request, obj),
        }
        try:
            context.update(self.admin_site.each_context(request))
        except TypeError:  # pragma: no cover
            # Django 1.7 compatibility
            context.update(self.admin_site.each_context())
        except AttributeError:  # pragma: no cover
            pass
        return context
590511
def BasenamePath(self, path):
    
    if path.endswith(self.PATH_SEPARATOR):
      path = path[:-1]
    _, _, basename = path.rpartition(self.PATH_SEPARATOR)
    return basename
460736
def admin_view_reverse_fk_links(modeladmin: ModelAdmin,
                                obj,
                                reverse_fk_set_field: str,
                                missing: str = "(None)",
                                use_str: bool = True,
                                separator: str = "<br>",
                                view_type: str = "change",
                                current_app: str = None) -> str:
    
    if not hasattr(obj, reverse_fk_set_field):
        return missing
    linked_objs = getattr(obj, reverse_fk_set_field).all()
    if not linked_objs:
        return missing
    first = linked_objs[0]
    app_name = first._meta.app_label.lower()
    model_name = first._meta.object_name.lower()
    viewname = "admin:{}_{}_{}".format(app_name, model_name, view_type)
    if current_app is None:
        current_app = modeladmin.admin_site.name
    links = []
    for linked_obj in linked_objs:
        # log.debug("linked_obj: {}", linked_obj)
        url = reverse(viewname, args=[linked_obj.pk], current_app=current_app)

        if use_str:
            label = escape(str(linked_obj))
        else:
            label = "{} {}".format(escape(linked_obj._meta.object_name),
                                   linked_obj.pk)
        links.append('<a href="{}">{}</a>'.format(url, label))
    # log.debug("links: {}", links)
    return separator.join(links)
618243
def admin_view_url(admin_site: AdminSite,
                   obj,
                   view_type: str = "change",
                   current_app: str = None) -> str:
    
    app_name = obj._meta.app_label.lower()
    model_name = obj._meta.object_name.lower()
    pk = obj.pk
    viewname = "admin:{}_{}_{}".format(app_name, model_name, view_type)
    if current_app is None:
        current_app = admin_site.name
    url = reverse(viewname, args=[pk], current_app=current_app)
    return url
270748
def reverse(self, url, args=None, kwargs=None):
        '''  '''
        return reverse("%s:%s" % (self.instance_name, url,),
                        args=args,
                        kwargs=kwargs,
                        current_app = self.app_name)
599068
function getBaseName(fullPath) {
        var lastSlash = fullPath.lastIndexOf("/");
        if (lastSlash === fullPath.length - 1) {  // directory: exclude trailing "/" too
            return fullPath.slice(fullPath.lastIndexOf("/", fullPath.length - 2) + 1, -1);
        } else {
            return fullPath.slice(lastSlash + 1);
        }
    }
1217521
def get_urls(self):
        
        urls = super(AccountAdmin, self).get_urls()
        from django.conf.urls import url

        def wrap(view):
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            return update_wrapper(wrapper, view)

        info = self.opts.app_label, self.opts.model_name

        extra_urls = [
            url(r'^login/(?P<provider>(\w|-)+)/$',
                wrap(OAuthRedirect.as_view()), name='%s_%s_login' % info),
            url(r'^callback/(?P<provider>(\w|-)+)/$',
                wrap(OAuthCallback.as_view()), name='%s_%s_callback' % info),
            url(r'^(.+)/json/$', wrap(self.json_view), name='%s_%s_json' % info),
        ]
        return extra_urls + urls