<commit_before>from django.contrib import messages
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.translation import ugettext_lazy as _

from c3nav.editor.models import ChangeSet
from c3nav.editor.views.base import sidebar_view


@sidebar_view
def user_detail(request, pk):
    user = request.user
    if str(pk) != str(user.pk):
        user = get_object_or_404(User, pk=pk)

    if request.method == 'POST':
        if request.user == user and 'changeset' in request.session:
            if request.POST.get('deactivate_changeset') == '1':
                request.session.pop('changeset', None)
                messages.success(request, _('You deactivated your current changeset.'))
                return redirect(request.path)

            if request.changeset.pk is None and ChangeSet.can_direct_edit(request):
                if request.POST.get('direct_editing') == '1':
                    request.session['direct_editing'] = True
                    messages.success(request, _('You activated direct editing.'))
                    return redirect(request.path)
                elif request.POST.get('direct_editing') == '0':
                    request.session.pop('direct_editing', None)
                    messages.success(request, _('You deactivated direct editing.'))
                    return redirect(request.path)

    ctx = {
        'user': user,
        'can_direct_edit': ChangeSet.can_direct_edit(request),
        'recent_changesets': ChangeSet.objects.filter(author=user).order_by('-last_update')[:10],
    }

    return render(request, 'editor/user.html', ctx)<commit_msg>enable direct edit when no changeset is active<commit_after>from django.contrib import messages
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.translation import ugettext_lazy as _

from c3nav.editor.models import ChangeSet
from c3nav.editor.views.base import sidebar_view


@sidebar_view
def user_detail(request, pk):
    user = request.user
    if str(pk) != str(user.pk):
        user = get_object_or_404(User, pk=pk)

    if request.method == 'POST':
        if request.user == user:
            if 'changeset' in request.session and request.POST.get('deactivate_changeset') == '1':
                request.session.pop('changeset', None)
                messages.success(request, _('You deactivated your current changeset.'))
                return redirect(request.path)

            if request.changeset.pk is None and ChangeSet.can_direct_edit(request):
                if request.POST.get('direct_editing') == '1':
                    request.session['direct_editing'] = True
                    messages.success(request, _('You activated direct editing.'))
                    return redirect(request.path)
                elif request.POST.get('direct_editing') == '0':
                    request.session.pop('direct_editing', None)
                    messages.success(request, _('You deactivated direct editing.'))
                    return redirect(request.path)

    ctx = {
        'user': user,
        'can_direct_edit': ChangeSet.can_direct_edit(request),
        'recent_changesets': ChangeSet.objects.filter(author=user).order_by('-last_update')[:10],
    }

    return render(request, 'editor/user.html', ctx)
{'fraction_non_alphanumeric': 0.1091123562370982, 'fraction_numerical': 0.007667354762606901, 'mean_word_length': 2.6789587852494576, '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': '645194', 'n_tokens_mistral': 965, 'n_tokens_neox': 911, 'n_words': 212}