<commit_before>from django.contrib.auth.decorators import user_passes_test

from adhocracy4.projects.models import Project
from meinberlin.apps.organisations.models import Organisation


def user_is_project_admin(view_func):
    """Projet admin view decorator.

    Checks that the user is an admin, moderator or initiator of any project.
    """
    return user_passes_test(
        _user_is_project_admin,
    )(view_func)


def _user_is_project_admin(user):
    is_moderator = Project.objects.filter(moderators__id=user.id).exists()
    is_initiator = Organisation.objects.filter(initiators__id=user.id).exists()
    return user.is_active and \
        (user.is_superuser or is_initiator or is_moderator)
<commit_msg>Fixing decorators.py in projects<commit_after>from adhocracy4.projects.models import Project
from django.apps import apps
from django.conf import settings
from django.contrib.auth.decorators import user_passes_test

Organisation = apps.get_model(settings.A4_ORGANISATIONS_MODEL)


def user_is_project_admin(view_func):
    """Projet admin view decorator.

    Checks that the user is an admin, moderator or initiator of any project.
    """
    return user_passes_test(
        _user_is_project_admin,
    )(view_func)


def _user_is_project_admin(user):
    is_moderator = Project.objects.filter(moderators__id=user.id).exists()
    is_initiator = Organisation.objects.filter(initiators__id=user.id).exists()
    return user.is_active and \
        (user.is_superuser or is_initiator or is_moderator)

{'fraction_non_alphanumeric': 0.07687253613666228, 'fraction_numerical': 0.0019710906701708277, 'mean_word_length': 4.661710037174721, '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': '4802349', 'n_tokens_mistral': 500, 'n_tokens_neox': 477, 'n_words': 107}