<commit_before>from __future__ import absolute_import, unicode_literals

from tracpro.groups.models import Region


class UserRegionsMiddleware(object):
    """
    Middleware to set region
    """
    def process_request(self, request):
        region = None

        if request.org and not request.user.is_anonymous():
            user_regions = request.user.get_direct_regions(request.org).order_by('name')

            if '_region' in request.GET:
                region_id = int(request.GET['_region'])
            elif 'region' in request.session:
                region_id = request.session['region']
            else:
                region_id = None

            # user requested a specific region...
            if region_id:
                region = user_regions.filter(pk=region_id).first()
            else:
                region = None

            # can't choose All Regions unless you're an admin
            if not region and not request.user.is_admin_for(request.org):<commit_msg>user_regions should include sub-regions<commit_after>from __future__ import absolute_import, unicode_literals

from tracpro.groups.models import Region


class UserRegionsMiddleware(object):
    """
    Middleware to set region
    """
    def process_request(self, request):
        region = None

        if request.org and not request.user.is_anonymous():
            user_regions = request.user.get_all_regions(request.org)

            if '_region' in request.GET:
                region_id = int(request.GET['_region'])
            elif 'region' in request.session:
                region_id = request.session['region']
            else:
                region_id = None

            # user requested a specific region...
            if region_id:
                region = user_regions.filter(pk=region_id).first()
            else:
                region = None

            # can't choose All Regions unless you're an admin
            if not region and not request.user.is_admin_for(request.org):
{'fraction_non_alphanumeric': 0.08283433133732535, 'fraction_numerical': 0.0, 'mean_word_length': 2.0564024390243905, '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': '4124620', 'n_tokens_mistral': 542, 'n_tokens_neox': 507, 'n_words': 138}