<commit_before>from django.shortcuts import render,redirect
from django.contrib.auth import authenticate, login, logout
from django.views.generic import View, RedirectView
from users.forms import UserForm,UserProfileForm,UserExtendedProfileForm
from users.models import User, UserProfile
from game.models import Team, League, TeamPick
from game.forms import LeagueForm, TeamForm
from django.utils.text import slugify
from django import forms
from game.services import get_weekly_record, tally_weekly_results
import os
import requests
import json

# class BaseView(View):
#     def get(self, request):
#         return redirect('interface:index')

class BaseRedirectView(RedirectView):
    def get(self, request, *args, **kwargs):
        self.url = '/index/'
        self.permanent = True
        return super().get(request, *args, **kwargs)

class IndexView(View):
    template = 'interface/index.html'

    def get(self, request):
        all_users = User.objects.all()
        all_leagues = League.objects.all()
        all_teams = Team.objects.all().order_by('-wins')
        week_list = [{'slug':"week-"+str(x),'week':x} for x in range(1,18)]
        week_slug_list = ["week-"+str(x) for x in range(1,18)]
        team_record_list = []
        for team in all_teams:
            team_win_count = len(TeamPick.objects.filter(team=team, correct=True))
            team_record_list.append((team, str(team_win_count) + ' - ' + str(team.losses)))
        if request.user.is_superuser:
            superuser = User.objects.filter(id=request.user.id)[0]
            return render(request, self.template,{'team_record_list':team_record_list,'superuser':superuser,'all_users':all_users,'all_leagues':all_leagues,'week_list':week_list,'week_slug_list':week_slug_list})
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id=request.user.id)[0]
            return render(request, self.template,{'team_record_list':team_record_list,'active_user':active_user,'all_users':all_users,'all_leagues':all_leagues,'all_teams':all_teams, 'week_list':week_list,'week_slug_list':week_slug_list})
        return render(request, self.template)


class LoginView(View):
    template = 'interface/login.html'
    login_form = UserForm()

    def get(self,request):
        if request.user.is_superuser:
            superuser = User.objects.filter(id=request.user.id)[0]
            return render(request, self.template,{'superuser':superuser,'user_form':self.login_form,})
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id = request.user.id)[0]
            return render(request,self.template,{'user_form':self.login_form,'active_user':active_user})
        return render(request,self.template,{'user_form':self.login_form})


    def post(self,request):
        submitted_form = UserForm(request.POST)
        username = submitted_form._raw_value('username')
        password = submitted_form._raw_value('password')
        authenticated_user = authenticate(username=username, password=password)
        if authenticated_user:
            login(request,authenticated_user)
            auth_user = User.objects.filter(username=authenticated_user)[0]
            return redirect('interface:profile', username = auth_user.username)
        return redirect('interface:login')

class RegisterView(View):
    template = 'interface/register.html'
    register_form = UserForm()

    def get(self,request):
        if request.user.is_superuser:
            superuser = User.objects.filter(id=request.user.id)[0]
            return render(request,self.template,{'superuser':superuser,'user_form':self.register_form,'active_user':active_user})
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id = request.user.id)[0]
            return render(request,self.template,{'user_form':self.register_form,'active_user':active_user})
        return render(request,self.template,{'user_form':self.register_form})

    def post(self,request):
        submitted_form = UserForm(request.POST)
        if submitted_form.is_valid():
            submitted_username = submitted_form.cleaned_data.get('username')
            submitted_password = submitted_form.cleaned_data.get('password')
            new_user = User.objects.create_user(username = submitted_username, password = submitted_password)
            if new_user:
                new_user_profile = UserProfile(user=new_user)
                new_user_profile.save()
                authenticated_user = authenticate(username=submitted_username,password=<PASSWORD>)
                login(request,authenticated_user)
                return redirect('interface:profile', username = new_user.username)
        return redirect('interface:register')

class LogoutView(View):
    template = 'interface/logout.html'

    def get(self,request):
        if request.user.is_superuser:
            superuser = User.objects.filter(id=request.user.id)[0]
            return render(request,self.template,{'superuser':superuser})
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id = request.user.id)[0]
            return render(request,self.template,{'active_user':active_user})
        return redirect('interface:index')


    def post(self,request):
        logout(request)
        return redirect('interface:index')


class ProfileView(View):
    template = 'interface/profile.html'

    def get(self,request,username):
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id = request.user.id)[0]
            if User.objects.filter(username=username):
                profiled_user = User.objects.filter(username=username)[0]
                viewed_user_profile = UserProfile.objects.filter(user=profiled_user)[0]
                print(dir(viewed_user_profile.picture))
                print(viewed_user_profile.picture)
                print(viewed_user_profile.picture.name)
                print(viewed_user_profile.picture.path)
                # print(viewed_user_profile.picture.fileno)
                viewed_user_profile.picture = viewed_user_profile.picture.name.replace('game/static/users/','')<commit_msg>removes some print statements from testing<commit_after>from django.shortcuts import render,redirect
from django.contrib.auth import authenticate, login, logout
from django.views.generic import View, RedirectView
from users.forms import UserForm,UserProfileForm,UserExtendedProfileForm
from users.models import User, UserProfile
from game.models import Team, League, TeamPick
from game.forms import LeagueForm, TeamForm
from django.utils.text import slugify
from django import forms
from game.services import get_weekly_record, tally_weekly_results
import os
import requests
import json

# class BaseView(View):
#     def get(self, request):
#         return redirect('interface:index')

class BaseRedirectView(RedirectView):
    def get(self, request, *args, **kwargs):
        self.url = '/index/'
        self.permanent = True
        return super().get(request, *args, **kwargs)

class IndexView(View):
    template = 'interface/index.html'

    def get(self, request):
        all_users = User.objects.all()
        all_leagues = League.objects.all()
        all_teams = Team.objects.all().order_by('-wins')
        week_list = [{'slug':"week-"+str(x),'week':x} for x in range(1,18)]
        week_slug_list = ["week-"+str(x) for x in range(1,18)]
        team_record_list = []
        for team in all_teams:
            team_win_count = len(TeamPick.objects.filter(team=team, correct=True))
            team_record_list.append((team, str(team_win_count) + ' - ' + str(team.losses)))
        if request.user.is_superuser:
            superuser = User.objects.filter(id=request.user.id)[0]
            return render(request, self.template,{'team_record_list':team_record_list,'superuser':superuser,'all_users':all_users,'all_leagues':all_leagues,'week_list':week_list,'week_slug_list':week_slug_list})
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id=request.user.id)[0]
            return render(request, self.template,{'team_record_list':team_record_list,'active_user':active_user,'all_users':all_users,'all_leagues':all_leagues,'all_teams':all_teams, 'week_list':week_list,'week_slug_list':week_slug_list})
        return render(request, self.template)


class LoginView(View):
    template = 'interface/login.html'
    login_form = UserForm()

    def get(self,request):
        if request.user.is_superuser:
            superuser = User.objects.filter(id=request.user.id)[0]
            return render(request, self.template,{'superuser':superuser,'user_form':self.login_form,})
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id = request.user.id)[0]
            return render(request,self.template,{'user_form':self.login_form,'active_user':active_user})
        return render(request,self.template,{'user_form':self.login_form})


    def post(self,request):
        submitted_form = UserForm(request.POST)
        username = submitted_form._raw_value('username')
        password = submitted_form._raw_value('password')
        authenticated_user = authenticate(username=username, password=password)
        if authenticated_user:
            login(request,authenticated_user)
            auth_user = User.objects.filter(username=authenticated_user)[0]
            return redirect('interface:profile', username = auth_user.username)
        return redirect('interface:login')

class RegisterView(View):
    template = 'interface/register.html'
    register_form = UserForm()

    def get(self,request):
        if request.user.is_superuser:
            superuser = User.objects.filter(id=request.user.id)[0]
            return render(request,self.template,{'superuser':superuser,'user_form':self.register_form,'active_user':active_user})
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id = request.user.id)[0]
            return render(request,self.template,{'user_form':self.register_form,'active_user':active_user})
        return render(request,self.template,{'user_form':self.register_form})

    def post(self,request):
        submitted_form = UserForm(request.POST)
        if submitted_form.is_valid():
            submitted_username = submitted_form.cleaned_data.get('username')
            submitted_password = <PASSWORD>_form.cleaned_data.get('password')
            new_user = User.objects.create_user(username = submitted_username, password = <PASSWORD>)
            if new_user:
                new_user_profile = UserProfile(user=new_user)
                new_user_profile.save()
                authenticated_user = authenticate(username=submitted_username,password=<PASSWORD>)
                login(request,authenticated_user)
                return redirect('interface:profile', username = new_user.username)
        return redirect('interface:register')

class LogoutView(View):
    template = 'interface/logout.html'

    def get(self,request):
        if request.user.is_superuser:
            superuser = User.objects.filter(id=request.user.id)[0]
            return render(request,self.template,{'superuser':superuser})
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id = request.user.id)[0]
            return render(request,self.template,{'active_user':active_user})
        return redirect('interface:index')


    def post(self,request):
        logout(request)
        return redirect('interface:index')


class ProfileView(View):
    template = 'interface/profile.html'

    def get(self,request,username):
        if not request.user.is_anonymous():
            active_user = User.objects.filter(id = request.user.id)[0]
            if User.objects.filter(username=username):
                profiled_user = User.objects.filter(username=username)[0]
                viewed_user_profile = UserProfile.objects.filter(user=profiled_user)[0]
                viewed_user_profile.picture = viewed_user_profile.picture.name.replace('game/static/users/','')
{'fraction_non_alphanumeric': 0.11600032838026435, 'fraction_numerical': 0.002955422379115015, 'mean_word_length': 3.5319940476190474, 'pattern_counts': {'":': 0, '<': 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': '5089187', 'n_tokens_mistral': 3536, 'n_tokens_neox': 3478, 'n_words': 565}