<commit_before>from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from .models import Team


def determine_team(request):
    hostname = request.META.get('HTTP_HOST')
    team = Team.objects.filter(hostname=hostname).first()

    if team is None:
        if hasattr(settings, 'TALLESSA_DEFAULT_TEAM_SLUG'):
            return Team.objects.get(slug=settings.TALLESSA_DEFAULT_TEAM_SLUG)
        else:
            raise ImproperlyConfigured('Team not found for hostname: {}'.format(hostname))

    return team


class TeamMiddleware(object):
    def process_request(self, request):
        request.team = determine_team(request)<commit_msg>teams/middleware: fix it<commit_after>from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.shortcuts import get_object_or_404

from .models import Team


def determine_team(request):
    hostname = request.META.get('HTTP_HOST')
    if getattr(settings, 'TALLESSA_DEFAULT_TEAM_SLUG'):
        try:
            return Team.objects.get(hostname=hostname)
        except Team.DoesNotExist:
            return get_object_or_404(Team, slug=settings.TALLESSA_DEFAULT_TEAM_SLUG)
    else:
        return get_object_or_404(Team, hostname=hostname)



class TeamMiddleware(object):
    def process_request(self, request):
        request.team = determine_team(request)
{'fraction_non_alphanumeric': 0.08393632416787265, 'fraction_numerical': 0.006512301013024602, 'mean_word_length': 4.084558823529412, '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': '4984362', 'n_tokens_mistral': 425, 'n_tokens_neox': 413, 'n_words': 87}