<commit_before>from django.views.generic import DetailView, UpdateView
from django.contrib.auth.views import redirect_to_login
from django.core.urlresolvers import reverse
from django.shortcuts import redirect

from braces.views import LoginRequiredMixin

from .models import User


class ProfileDetailView(DetailView):
    '''
    Displays the user profile information
    '''
    model = User
    slug_field = 'username'
    slug_url_kwarg = 'username'

    def get(self, request, *args, **kwargs):
        user = request.user
        username = self.kwargs.get(self.slug_url_kwarg)

        if user.is_authenticated() and not username:
            return redirect('profile_detail', username=user.username)
        elif not user.is_authenticated() and not username:
            return redirect_to_login(reverse('profile_detail_me'))

        return super(ProfileDetailView, self).get(request, *args, **kwargs)


class ProfileUpdateView(LoginRequiredMixin, UpdateView):
    model = User
    slug_field = 'username'
    slug_url_kwarg = 'username'<commit_msg>Use select_related in user profile detail view<commit_after>from django.views.generic import DetailView, UpdateView
from django.contrib.auth.views import redirect_to_login
from django.core.urlresolvers import reverse
from django.shortcuts import redirect

from braces.views import LoginRequiredMixin

from .models import User


class ProfileDetailView(DetailView):
    '''
    Displays the user profile information
    '''
    queryset = User.objects.select_related('location', 'location__country')
    slug_field = 'username'
    slug_url_kwarg = 'username'

    def get(self, request, *args, **kwargs):
        user = request.user
        username = self.kwargs.get(self.slug_url_kwarg)

        if user.is_authenticated() and not username:
            return redirect('profile_detail', username=user.username)
        elif not user.is_authenticated() and not username:
            return redirect_to_login(reverse('profile_detail_me'))

        return super(ProfileDetailView, self).get(request, *args, **kwargs)


class ProfileUpdateView(LoginRequiredMixin, UpdateView):
    model = User
    slug_field = 'username'
    slug_url_kwarg = 'username'
{'fraction_non_alphanumeric': 0.08552036199095023, 'fraction_numerical': 0.0, 'mean_word_length': 3.97972972972973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4474203', 'n_tokens_mistral': 628, 'n_tokens_neox': 611, 'n_words': 160}