<commit_before>import itertools

from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext, loader
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

from django import forms

from django.db.models import F

from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib import messages
from django.contrib.sites.models import get_current_site

from django.views.decorators.http import require_POST

# from django.utils.translation import ugettext_lazy as _

# from crispy_forms.helper import FormHelper
# from crispy_forms.layout import Layout, Submit, Field
# from crispy_forms.bootstrap import FormActions

from riskgame.models import *
from riskgame.tasks import change_days, invite_user

def index(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('home'))

    t = loader.get_template('riskgame/index.html')

    c = RequestContext(request, {
    })

    return HttpResponse(t.render(c))


# def pre_launch(request):
#     t = loader.get_template('riskgame/pre_launch.html')

#     c = RequestContext(request, {
#         'game': Game.objects.get_latest_game()
#     })

#     return HttpResponse(t.render(c))


# class CreateTeamform(forms.ModelForm):
#     class Meta:
#         model = Team
#         fields = ('name', )

#     def __init__(self, *args, **kwargs):
#         self.helper = FormHelper()

#         self.helper.form_class = 'form'
#         self.helper.form_action = reverse('team_create')
#         self.helper.form_method = 'post'

#         self.helper.layout = Layout(
#             Field('name', css_class='input-block-level', placeholder='Name'),
#             FormActions(
#                 Submit('submit', _('Send'), css_class='btn')
#             )
#         )

#         super(CreateTeamform, self).__init__(*args, **kwargs)

# @login_required
# def team_create(request):
#     if request.method == "POST":
#         name = request.POST.get('name', '')

#         player = request.user.get_or_create_player()
#         Team.objects.create(name=name, leader=player)

#         return HttpResponseRedirect(reverse('index'))


@login_required
def team_detail(request, pk):
    t = loader.get_template('riskgame/team_detail.html')

    c = RequestContext(request, {
        'team': Team.objects.get(pk=pk),
        'title': "team"
    })

    return HttpResponse(t.render(c))

# @login_required
# @require_POST
# def request_team_join(request, pk):
#     player = request.user.get_or_create_player()
#     team = Team.objects.get(id=pk)

#     TeamJoinRequest.objects.create(team=team, player=player)

#     return HttpResponseRedirect(reverse('team_detail', args=[player.team.id]))

# @login_required
# @require_POST
# def accept_team_join(request, pk):
#     join_request = TeamJoinRequest.objects.get(id=request.POST.get('join_request_id', ''))

#     print join_request

#     print request.user.get_or_create_player()
#     print join_request.team.leader

#     if request.user.get_or_create_player() == join_request.team.leader:
#         player = join_request.player
#         player.team = join_request.team
#         player.save()

#         join_request.delete()

#         return HttpResponseRedirect(reverse('team_detail', args=[player.team.id]))

@login_required
def team_your(request):
    player = request.user.get_or_create_player()
    teamplayer = TeamPlayer.objects.get(player=player)

    return HttpResponseRedirect(reverse('team_detail', args=[teamplayer.team.pk]))


@login_required
def players(request):
    t = loader.get_template('riskgame/players.html')

    c = RequestContext(request, {
        'players': Player.objects.all()
    })

    return HttpResponse(t.render(c))

def player_profile(request, pk):
    player = Player.objects.get(pk=pk)

    t = loader.get_template('riskgame/player_profile.html')

    c = RequestContext(request, {
        'player': player,
        "title": "profile"
    })

    return HttpResponse(t.render(c))

def player_profile_own(request):
    player = request.user.get_or_create_player()

    return HttpResponseRedirect(reverse('player_profile', args=[player.pk]))

class ProfileForm(forms.ModelForm):
    class Meta:
        model = Player
        fields = ('name', 'receive_email')

def player_profile_edit(request):
    t = loader.get_template('riskgame/player_profile_edit.html')

    player = request.user.get_or_create_player()

    if request.method == "POST":
        profileform = ProfileForm(request.POST, instance=player)

        if profileform.is_valid():
            profileform.save()

            messages.add_message(request, messages.INFO, '<div class="form-success text-center">Profile updated successfully.</div>')

            return HttpResponseRedirect(reverse('player_profile_own'))
    else:
        profileform = ProfileForm(instance=player)

    c = RequestContext(request, {
        'profileform': profileform
    })

    return HttpResponse(t.render(c))

class FrontLineForm(forms.Form):
    def __init__(self, teamplayer, *args, **kwargs):
        super(FrontLineForm, self).__init__(*args, **kwargs)

        self.fields['target'] = forms.ModelChoiceField(queryset=teamplayer.team.teamplayer_set.filter(role='office'))

@login_required
def notifications(request):
    player = request.user.get_or_create_player()
    teamplayer = TeamPlayer.objects.get(player=player)

    nots = Notification.objects.filter(team=teamplayer.team).order_by('-datecreated')
    paginator = Paginator(nots, 5)

    page = request.GET.get('page')

    try:
        notifications = paginator.page(page)
    except PageNotAnInteger:
        notifications = paginator.page(1)
    except EmptyPage:
        notifications = paginator.page(paginator.num_pages)
<commit_msg>50 messages per page<commit_after>import itertools

from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext, loader
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

from django import forms

from django.db.models import F

from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib import messages
from django.contrib.sites.models import get_current_site

from django.views.decorators.http import require_POST

# from django.utils.translation import ugettext_lazy as _

# from crispy_forms.helper import FormHelper
# from crispy_forms.layout import Layout, Submit, Field
# from crispy_forms.bootstrap import FormActions

from riskgame.models import *
from riskgame.tasks import change_days, invite_user

def index(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('home'))

    t = loader.get_template('riskgame/index.html')

    c = RequestContext(request, {
    })

    return HttpResponse(t.render(c))


# def pre_launch(request):
#     t = loader.get_template('riskgame/pre_launch.html')

#     c = RequestContext(request, {
#         'game': Game.objects.get_latest_game()
#     })

#     return HttpResponse(t.render(c))


# class CreateTeamform(forms.ModelForm):
#     class Meta:
#         model = Team
#         fields = ('name', )

#     def __init__(self, *args, **kwargs):
#         self.helper = FormHelper()

#         self.helper.form_class = 'form'
#         self.helper.form_action = reverse('team_create')
#         self.helper.form_method = 'post'

#         self.helper.layout = Layout(
#             Field('name', css_class='input-block-level', placeholder='Name'),
#             FormActions(
#                 Submit('submit', _('Send'), css_class='btn')
#             )
#         )

#         super(CreateTeamform, self).__init__(*args, **kwargs)

# @login_required
# def team_create(request):
#     if request.method == "POST":
#         name = request.POST.get('name', '')

#         player = request.user.get_or_create_player()
#         Team.objects.create(name=name, leader=player)

#         return HttpResponseRedirect(reverse('index'))


@login_required
def team_detail(request, pk):
    t = loader.get_template('riskgame/team_detail.html')

    c = RequestContext(request, {
        'team': Team.objects.get(pk=pk),
        'title': "team"
    })

    return HttpResponse(t.render(c))

# @login_required
# @require_POST
# def request_team_join(request, pk):
#     player = request.user.get_or_create_player()
#     team = Team.objects.get(id=pk)

#     TeamJoinRequest.objects.create(team=team, player=player)

#     return HttpResponseRedirect(reverse('team_detail', args=[player.team.id]))

# @login_required
# @require_POST
# def accept_team_join(request, pk):
#     join_request = TeamJoinRequest.objects.get(id=request.POST.get('join_request_id', ''))

#     print join_request

#     print request.user.get_or_create_player()
#     print join_request.team.leader

#     if request.user.get_or_create_player() == join_request.team.leader:
#         player = join_request.player
#         player.team = join_request.team
#         player.save()

#         join_request.delete()

#         return HttpResponseRedirect(reverse('team_detail', args=[player.team.id]))

@login_required
def team_your(request):
    player = request.user.get_or_create_player()
    teamplayer = TeamPlayer.objects.get(player=player)

    return HttpResponseRedirect(reverse('team_detail', args=[teamplayer.team.pk]))


@login_required
def players(request):
    t = loader.get_template('riskgame/players.html')

    c = RequestContext(request, {
        'players': Player.objects.all()
    })

    return HttpResponse(t.render(c))

def player_profile(request, pk):
    player = Player.objects.get(pk=pk)

    t = loader.get_template('riskgame/player_profile.html')

    c = RequestContext(request, {
        'player': player,
        "title": "profile"
    })

    return HttpResponse(t.render(c))

def player_profile_own(request):
    player = request.user.get_or_create_player()

    return HttpResponseRedirect(reverse('player_profile', args=[player.pk]))

class ProfileForm(forms.ModelForm):
    class Meta:
        model = Player
        fields = ('name', 'receive_email')

def player_profile_edit(request):
    t = loader.get_template('riskgame/player_profile_edit.html')

    player = request.user.get_or_create_player()

    if request.method == "POST":
        profileform = ProfileForm(request.POST, instance=player)

        if profileform.is_valid():
            profileform.save()

            messages.add_message(request, messages.INFO, '<div class="form-success text-center">Profile updated successfully.</div>')

            return HttpResponseRedirect(reverse('player_profile_own'))
    else:
        profileform = ProfileForm(instance=player)

    c = RequestContext(request, {
        'profileform': profileform
    })

    return HttpResponse(t.render(c))

class FrontLineForm(forms.Form):
    def __init__(self, teamplayer, *args, **kwargs):
        super(FrontLineForm, self).__init__(*args, **kwargs)

        self.fields['target'] = forms.ModelChoiceField(queryset=teamplayer.team.teamplayer_set.filter(role='office'))

@login_required
def notifications(request):
    player = request.user.get_or_create_player()
    teamplayer = TeamPlayer.objects.get(player=player)

    nots = Notification.objects.filter(team=teamplayer.team).order_by('-datecreated')
    paginator = Paginator(nots, 50)

    page = request.GET.get('page')

    try:
        notifications = paginator.page(page)
    except PageNotAnInteger:
        notifications = paginator.page(1)
    except EmptyPage:
        notifications = paginator.page(paginator.num_pages)

{'fraction_non_alphanumeric': 0.12095544638319498, 'fraction_numerical': 0.0005929188548195833, 'mean_word_length': 3.6890389197776012, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, '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': '2594340', 'n_tokens_mistral': 3604, 'n_tokens_neox': 3507, 'n_words': 645}