コード例 #1
0
    def get_link_context(self, context, obj, fieldname, admin_site, querystring):
        """
        Adds a `link` and `verbose_name` to the context, if
        :meth:`~adminlinks.templatetags.adminlinks_buttons.BaseAdminLink.is_valid`

        :param context: Hopefully, a :class:`~django.template.RequestContext`
                        otherwise :meth:`~adminlinks.templatetags.adminlinks_buttons.BaseAdminLink.is_valid`
                        is unlikely to be :data:`True`
        :param obj: the :class:`~django.db.models.Model` instance to link to.
                    Must have a primary key, and
                    :class:`~django.db.models.Options` from which we can
                    retrieve a :attr:`~django.db.models.Field.verbose_name`
        :param fieldname: the specific model field to render a link for.
        :param admin_site: name of the admin site to use; defaults to **"admin"**
        :param querystring: a querystring to include in the link output.
                            Defaults to "_popup=1"
        :return: the link values.
        :rtype: dictionary.
        """
        ctx = {}
        ctx.update(_add_custom_link_to_context(admin_site, context['request'],
                                               obj._meta, 'change',
                                               'change_field',
                                               [obj.pk, fieldname],
                                               query=querystring))
        # successfully loaded link, add the fieldname.
        if 'link' in ctx:
            field = obj._meta.get_field(fieldname)
            value = getattr(obj, fieldname, None)
            if field.get_internal_type() in ('BooleanField', 'NullBooleanField'):
                icon = 'admin/img/icon-%s.gif' % yesno(value, "yes,no,unknown")
                ctx.update(maybe_boolean=True, img=icon)
            ctx.update(verbose_name=field.verbose_name,
                       existing_value=value)
        return ctx
コード例 #2
0
    def get_link_context(self, context, obj, admin_site, querystring):
        """
        Adds a `link` and `verbose_name` to the context, if
        :meth:`~adminlinks.templatetags.adminlinks_buttons.BaseAdminLink.is_valid`

        :param context: Hopefully, a :class:`~django.template.RequestContext`
                        otherwise :meth:`~adminlinks.templatetags.adminlinks_buttons.BaseAdminLink.is_valid`
                        is unlikely to be :data:`True`
        :param obj: the :class:`~django.db.models.Model` class to link to.
                    Must have :class:`~django.db.models.Options`
                    from which we can retrieve a
                    :attr:`~django.db.models.Field.verbose_name`
        :param admin_site: name of the admin site to use; defaults to **"admin"**
        :param querystring: a querystring to include in the link output.
                            Defaults to "pop=1" unless Django > 1.6, when it
                            changes to "_popup=1"
        :return: the link values.
        :rtype: dictionary.
        """
        ctx = _add_custom_link_to_context(admin_site, context['request'],
                                          opts=obj._meta, permname='change',
                                          viewname='changelist', url_params=None,
                                          query=querystring)
        if ctx['link']:
            logger.debug('link created successfully, swapping out the '
                         '`verbose_name` available to the context')
            ctx['verbose_name'] = obj._meta.verbose_name_plural
        return ctx
コード例 #3
0
    def get_link_context(self, context, obj, admin_site, querystring):
        """
        ..todo:: document

        Always returns the existing context.
        """
        site = get_admin_site(admin_site)
        if site is None:
            logger.debug('Invalid admin site')
            return {}

        content_type = get_content_type(obj)
        new_querystring = QueryDict(querystring, mutable=True)
        new_querystring.update({'content_type': content_type.pk,
                                'content_id': obj.pk})
        link = _add_custom_link_to_context(admin_site, context['request'],
                                           opts=EditRegionChunk._meta,
                                           permname='change',
                                           viewname='changelist',
                                           url_params=None,
                                           query=new_querystring.urlencode())

        if link['verbose_name']:
            logger.debug('link created successfully, swapping out the '
                         '`verbose_name` available to the context')
            link['verbose_name'] = EditRegionChunk._meta.verbose_name_plural
            link['obj_name'] = obj._meta.verbose_name
        return link