<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from apps.core.helpers import user_is_group_admin
from apps.core.models import Group
from apps.users.models import Follow

from apps.users.forms import GroupSettingsForm
from apps.event.models import Event
from apps.event.event_list import EventList


def group_list_page(request):
    # TODO: pagination
    groups = Group.objects.all()
    group_ids = Follow.objects.filter(user_id=request.user.id) \
        .values_list('group_id', flat=True)
    user_is_following = [group.id in group_ids for group in groups]

    return {
        'groups': zip(groups, user_is_following)
    }


def group_detail(request):
    events = Event.objects.filter(group_id=request.group.pk, is_private=False)
    user_is_following = Follow.objects.filter(user_id=request.user.id,
                                              group=request.group).exists()
    return {
        'group': request.group,
        'event_list': EventList.simple_context(request, events),
        # TODO: check if user is group admin or census admin
        'user_can_edit_group': True,
        'user_is_following': user_is_following,
        'edit_url': reverse('group_edit', kwargs={
            'group_slug': request.group.slug})
    }


def redirect_to_group_detail(request):
    return HttpResponseRedirect(
        reverse('group_detail', kwargs={
            'group_slug': request.group.slug
        }))


def edit_group(request):
    form = GroupSettingsForm(instance=request.group, label_suffix='')
    context = {
        'group': request.group,
        'form': form,
        'group_slug': request.group.slug,
    }
    return context


def update_group_settings(request):
    form = GroupSettingsForm(request.POST, instance=request.group)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect(request.group.get_absolute_url())<commit_msg>Correctly set group editability context var<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from apps.core.helpers import user_is_group_admin
from apps.core.models import Group
from apps.users.models import Follow

from apps.users.forms import GroupSettingsForm
from apps.event.models import Event
from apps.event.event_list import EventList


def group_list_page(request):
    # TODO: pagination
    groups = Group.objects.all()
    group_ids = Follow.objects.filter(user_id=request.user.id) \
        .values_list('group_id', flat=True)
    user_is_following = [group.id in group_ids for group in groups]

    return {
        'groups': zip(groups, user_is_following)
    }


def group_detail(request):
    events = Event.objects.filter(group_id=request.group.pk, is_private=False)
    user_is_following = Follow.objects.filter(user_id=request.user.id,
                                              group=request.group).exists()
    return {
        'group': request.group,
        'event_list': EventList.simple_context(request, events),
        'user_can_edit_group': user_is_group_admin(request.user,
                                                   request.group),
        'user_is_following': user_is_following,
        'edit_url': reverse('group_edit', kwargs={
            'group_slug': request.group.slug})
    }


def redirect_to_group_detail(request):
    return HttpResponseRedirect(
        reverse('group_detail', kwargs={
            'group_slug': request.group.slug
        }))


def edit_group(request):
    form = GroupSettingsForm(instance=request.group, label_suffix='')
    context = {
        'group': request.group,
        'form': form,
        'group_slug': request.group.slug,
    }
    return context


def update_group_settings(request):
    form = GroupSettingsForm(request.POST, instance=request.group)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect(request.group.get_absolute_url())
{'fraction_non_alphanumeric': 0.09748576850094877, 'fraction_numerical': 0.0004743833017077799, 'mean_word_length': 3.212787212787213, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3818525', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1200, 'n_words': 263}