<commit_before># (c) Crown Owned Copyright, 2016. Dstl.
# apps/users/views.py
from django.http import HttpResponseRedirect
from django.views.generic import DetailView, ListView, UpdateView
from django.core.urlresolvers import reverse
from .models import User
from apps.teams.models import Team
from apps.organisations.models import Organisation


class UserDetail(DetailView):
    model = User


class UserUpdateProfileTeams(UpdateView):
    model = User
    fields = [
                'username',
                'best_way_to_find',
                'best_way_to_contact',
                'phone',
                'email'
            ]
    template_name = 'users/user_details_teams_form.html'

    def get_context_data(self, **kwargs):
        context = super(
            UserUpdateProfileTeams,
            self
        ).get_context_data(**kwargs)

        #   We want to grab all the teams so we can display a bunch of
        #   checkboxes allowing the user to join those teams
        if self.request.user.is_authenticated():
            teams = Team.objects.all()
            for team in teams:
                team.checked = False
                for us in self.request.user.teams.all():
                    if team.id == us.id:
                        team.checked = True

            context['teams'] = teams

        context['organisations'] = Organisation.objects.all()

        return context


class UserUpdateProfile(UpdateView):
    model = User
    fields = [
                'username',
                'best_way_to_find',
                'best_way_to_contact',
                'phone',
                'email'
            ]
    template_name = 'users/user_details_form.html'
<commit_msg>Don't let one user see another user's edit profile page<commit_after># (c) Crown Owned Copyright, 2016. Dstl.
# apps/users/views.py
from django.http import HttpResponseRedirect
from django.views.generic import DetailView, ListView, UpdateView
from django.core.urlresolvers import reverse
from .models import User
from apps.teams.models import Team
from apps.organisations.models import Organisation


class UserDetail(DetailView):
    model = User


class UserUpdateProfileTeams(UpdateView):
    model = User
    fields = [
                'username',
                'best_way_to_find',
                'best_way_to_contact',
                'phone',
                'email'
            ]
    template_name = 'users/user_details_teams_form.html'

    def get_context_data(self, **kwargs):
        context = super(
            UserUpdateProfileTeams,
            self
        ).get_context_data(**kwargs)

        #   We want to grab all the teams so we can display a bunch of
        #   checkboxes allowing the user to join those teams
        if self.request.user.is_authenticated():
            teams = Team.objects.all()
            for team in teams:
                team.checked = False
                for us in self.request.user.teams.all():
                    if team.id == us.id:
                        team.checked = True

            context['teams'] = teams

        context['organisations'] = Organisation.objects.all()

        return context


class UserUpdateProfile(UpdateView):
    model = User
    fields = [
                'username',
                'best_way_to_find',
                'best_way_to_contact',
                'phone',
                'email'
            ]
    template_name = 'users/user_details_form.html'

    # Only show this form if it's for the currently logged in user.
    def get(self, request, *args, **kwargs):
        if (self.request.user.slug != kwargs['slug']):
            return HttpResponseRedirect(
                reverse('user-detail', kwargs={'slug': kwargs['slug']})
            )
        return super(UserUpdateProfile, self).get(request, *args, **kwargs)

{'fraction_non_alphanumeric': 0.08751306165099268, 'fraction_numerical': 0.0020898641588296763, 'mean_word_length': 1.9318529862174578, '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': '2181103', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1002, 'n_words': 273}