<commit_before>from django.urls import reverse
from django.utils.safestring import mark_safe
from django.forms import widgets
from django.conf import settings
from django.utils.translation import ugettext as _




class RelatedFieldWidgetCanAdd(widgets.Select):
    """
    Supplements the standard Select widget behaviour by adding an 'add' button.

    Added related_kwargs for targeted redirection.

    Adapted from:
    http://stackoverflow.com/questions/28068168/django-adding-an-add-new-button-for-a-foreignkey-in-a-modelform
    """


    def __init__(
        self,
        related_model,
        related_url=None,
        related_kwargs=None, *args, **kwargs
    ):

        super(RelatedFieldWidgetCanAdd, self).__init__(*args, **kwargs)

        if not related_url:         # construct a url for the default admin site
            rel_to = related_model
            info = (rel_to._meta.app_label, rel_to._meta.object_name.lower())
            related_url = 'admin:%s_%s_add' % info
            related_kwargs = {}

        # Be careful that here "reverse" is not allowed
        self.related_url = related_url
        self.related_kwargs = related_kwargs


    def render(self, name, value, *args, **kwargs):
        self.related_url = reverse(
            self.related_url,
            kwargs=self.related_kwargs,
        )
        output = [
            super(RelatedFieldWidgetCanAdd, self).render(
                name,
                value,
                *args,
                **kwargs,
            )
        ]
        output.append('<a href="%s" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \
            (self.related_url, name))
        output.append('<img src="%sadmin/img/icon_addlink.svg" width="10" height="10" alt="%s"/></a>' % (settings.STATIC_URL, _('+ New')))
        return mark_safe(''.join(output))<commit_msg>Make sure to use icon hyphen addlink ipo icon uscore addlink...<commit_after>from django.urls import reverse
from django.utils.safestring import mark_safe
from django.forms import widgets
from django.conf import settings
from django.utils.translation import ugettext as _




class RelatedFieldWidgetCanAdd(widgets.Select):
    """
    Supplements the standard Select widget behaviour by adding an 'add' button.

    Added related_kwargs for targeted redirection.

    Adapted from:
    http://stackoverflow.com/questions/28068168/django-adding-an-add-new-button-for-a-foreignkey-in-a-modelform
    """


    def __init__(
        self,
        related_model,
        related_url=None,
        related_kwargs=None, *args, **kwargs
    ):

        super(RelatedFieldWidgetCanAdd, self).__init__(*args, **kwargs)

        if not related_url:         # construct a url for the default admin site
            rel_to = related_model
            info = (rel_to._meta.app_label, rel_to._meta.object_name.lower())
            related_url = 'admin:%s_%s_add' % info
            related_kwargs = {}

        # Be careful that here "reverse" is not allowed
        self.related_url = related_url
        self.related_kwargs = related_kwargs


    def render(self, name, value, *args, **kwargs):
        self.related_url = reverse(
            self.related_url,
            kwargs=self.related_kwargs,
        )
        output = [
            super(RelatedFieldWidgetCanAdd, self).render(
                name,
                value,
                *args,
                **kwargs,
            )
        ]
        output.append('<a href="%s" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \
            (self.related_url, name))
        output.append('<img src="%sadmin/img/icon-addlink.svg" width="14" height="14" alt="%s"/></a>' % (settings.STATIC_URL, _('+ New')))
        return mark_safe(''.join(output))
{'fraction_non_alphanumeric': 0.1099476439790576, 'fraction_numerical': 0.0062827225130890054, 'mean_word_length': 2.4207699194270367, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4845136', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1084, 'n_words': 247}