<commit_before>from __future__ import unicode_literals

from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import NoReverseMatch
from django.template.defaultfilters import date
from django.utils import six
from django.utils.html import (conditional_escape, escape, format_html,
                               format_html_join)
from django.utils.six.moves import reduce
from django.utils.translation import ugettext_lazy as _, ugettext
from djblets.datagrid.grids import CheckboxColumn, Column, DateTimeColumn
from djblets.gravatars import get_gravatar_url
from djblets.siteconfig.models import SiteConfiguration

from reviewboard.accounts.models import Profile, ReviewRequestVisit
from reviewboard.reviews.models import ReviewRequest
from reviewboard.reviews.templatetags.reviewtags import render_star
from reviewboard.site.urlresolvers import local_site_reverse


class BaseStarColumn(Column):
    """Indicates if an item is starred.

    This is the base class for all columns that deal with starring items.

    The star is interactive, allowing the user to star or unstar the item.
    """

    def __init__(self, *args, **kwargs):
        """Initialize the column."""
        super(BaseStarColumn, self).__init__(
            image_class='rb-icon rb-icon-star-on',
            image_alt=_('Starred'),
            detailed_label=_('Starred'),
            shrink=True,
            *args, **kwargs)

    def setup_state(self, state):
        """Set up the state for this column."""
        state.all_starred = set()

    def render_data(self, state, obj):
        """Return the rendered contents of the column."""
        obj.starred = obj.pk in state.all_starred
        return render_star(state.datagrid.request.user, obj)


class BaseSubmitterColumn(Column):
    """Base class for the Submitter column.

    We have two versions of this column: One for review request datagrids,
    and one for review datagrids. This columns contains all the common
    rendering logic between the two.
    """

    GRAVATAR_SIZE = 24

    def __init__(self, *args, **kwargs):
        """Initialize the column."""
        super(BaseSubmitterColumn, self).__init__(
            label=_('Submitter'),
            field_name='review_request',
            css_class='submitter-column',
            shrink=True,
            sortable=True,
            link=True,
            *args, **kwargs)

    def render_user(self, state, user):
        """Render the user's name and gravatar as HTML."""
        siteconfig = SiteConfiguration.objects.get_current()

        if siteconfig.get('integration_gravatars'):
            gravatar_url = get_gravatar_url(state.datagrid.request, user,
                                            self.GRAVATAR_SIZE)
        else:
            gravatar_url = None

        if gravatar_url:
            gravatar_html = format_html(
                '<img src="{0}" width="{1}" height="{1}" alt="{2}" '
                'class="gravatar" /> ',
                gravatar_url, self.GRAVATAR_SIZE, user.username)
        else:
            gravatar_html = ''

        return format_html(
            '<a class="user" href="{0}">{1}{2}</a>',
            user.get_absolute_url(), gravatar_html, user.username)

<commit_msg>SubmitterColumn now links to local site user view when appropriate<commit_after>from __future__ import unicode_literals

from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import NoReverseMatch
from django.template.defaultfilters import date
from django.utils import six
from django.utils.html import (conditional_escape, escape, format_html,
                               format_html_join)
from django.utils.six.moves import reduce
from django.utils.translation import ugettext_lazy as _, ugettext
from djblets.datagrid.grids import CheckboxColumn, Column, DateTimeColumn
from djblets.gravatars import get_gravatar_url
from djblets.siteconfig.models import SiteConfiguration

from reviewboard.accounts.models import Profile, ReviewRequestVisit
from reviewboard.reviews.models import ReviewRequest
from reviewboard.reviews.templatetags.reviewtags import render_star
from reviewboard.site.urlresolvers import local_site_reverse


class BaseStarColumn(Column):
    """Indicates if an item is starred.

    This is the base class for all columns that deal with starring items.

    The star is interactive, allowing the user to star or unstar the item.
    """

    def __init__(self, *args, **kwargs):
        """Initialize the column."""
        super(BaseStarColumn, self).__init__(
            image_class='rb-icon rb-icon-star-on',
            image_alt=_('Starred'),
            detailed_label=_('Starred'),
            shrink=True,
            *args, **kwargs)

    def setup_state(self, state):
        """Set up the state for this column."""
        state.all_starred = set()

    def render_data(self, state, obj):
        """Return the rendered contents of the column."""
        obj.starred = obj.pk in state.all_starred
        return render_star(state.datagrid.request.user, obj)


class BaseSubmitterColumn(Column):
    """Base class for the Submitter column.

    We have two versions of this column: One for review request datagrids,
    and one for review datagrids. This columns contains all the common
    rendering logic between the two.
    """

    GRAVATAR_SIZE = 24

    def __init__(self, *args, **kwargs):
        """Initialize the column."""
        super(BaseSubmitterColumn, self).__init__(
            label=_('Submitter'),
            field_name='review_request',
            css_class='submitter-column',
            shrink=True,
            sortable=True,
            link=True,
            *args, **kwargs)

    def render_user(self, state, user):
        """Render the user's name and gravatar as HTML."""
        siteconfig = SiteConfiguration.objects.get_current()

        if siteconfig.get('integration_gravatars'):
            gravatar_url = get_gravatar_url(state.datagrid.request, user,
                                            self.GRAVATAR_SIZE)
        else:
            gravatar_url = None

        if gravatar_url:
            gravatar_html = format_html(
                '<img src="{0}" width="{1}" height="{1}" alt="{2}" '
                'class="gravatar" /> ',
                gravatar_url, self.GRAVATAR_SIZE, user.username)
        else:
            gravatar_html = ''

        request = state.datagrid.request

        user_url = local_site_reverse('user', request=request, kwargs={
            'username': user.username,
        })

        return format_html(
            '<a class="user" href="{0}">{1}{2}</a>',
            user_url, gravatar_html, user.username)


{'fraction_non_alphanumeric': 0.09268365370287587, 'fraction_numerical': 0.002682163611980331, 'mean_word_length': 2.7062396466040863, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7637658', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1832, 'n_words': 515}