<commit_before>from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core import mail
from django.core.mail.backends.smtp import EmailBackend
from django.shortcuts import render

import kombu
import ldap

from registration.views.utils import nopermission

from ..models import HTMLSetting, TextSetting


@login_required
def check(request):
    # must be superuser
    if not request.user.is_superuser:
        return nopermission(request)

    # templates
    templates_ok = True

    for html_setting in ('about', 'privacy', 'privacy_newsletter', 'login', 'add_user'):
        try:
            HTMLSetting.objects.get(key=html_setting)
        except HTMLSetting.DoesNotExist:
            templates_ok = False

    for text_setting in ('privacy', ):
        try:
            TextSetting.objects.get(key=text_setting)
        except TextSetting.DoesNotExist:
            templates_ok = False

    # mail
    mail_ok = True
    try:
        mail_conn = mail.get_connection()
        if isinstance(mail_conn, EmailBackend):
            mail_conn.open()
    except ConnectionRefusedError:
        mail_ok = False

    # celery
    celery_broker_ok = True
    try:
        celery_conn = kombu.Connection(settings.CELERY_BROKER_URL)
        celery_conn.ensure_connection(max_retries=1)
    except kombu.exceptions.OperationalError:
        celery_broker_ok = False

    # ldap
    if 'django_auth_ldap.backend.LDAPBackend' in settings.AUTHENTICATION_BACKENDS:
        ldap_configured = True
        ldap_ok = False<commit_msg>fixed ldap connection check<commit_after>from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core import mail
from django.core.mail.backends.smtp import EmailBackend
from django.shortcuts import render

import kombu
import ldap

from registration.views.utils import nopermission

from ..models import HTMLSetting, TextSetting


@login_required
def check(request):
    # must be superuser
    if not request.user.is_superuser:
        return nopermission(request)

    # templates
    templates_ok = True

    for html_setting in ('about', 'privacy', 'privacy_newsletter', 'login', 'add_user'):
        try:
            HTMLSetting.objects.get(key=html_setting)
        except HTMLSetting.DoesNotExist:
            templates_ok = False

    for text_setting in ('privacy', ):
        try:
            TextSetting.objects.get(key=text_setting)
        except TextSetting.DoesNotExist:
            templates_ok = False

    # mail
    mail_ok = True
    try:
        mail_conn = mail.get_connection()
        if isinstance(mail_conn, EmailBackend):
            mail_conn.open()
    except ConnectionRefusedError:
        mail_ok = False

    # celery
    celery_broker_ok = True
    try:
        celery_conn = kombu.Connection(settings.CELERY_BROKER_URL)
        celery_conn.ensure_connection(max_retries=1)
    except kombu.exceptions.OperationalError:
        celery_broker_ok = False

    # ldap
    if 'django_auth_ldap.backend.LDAPBackend' in settings.AUTHENTICATION_BACKENDS:
        ldap_configured = True
        ldap_ok = True
{'fraction_non_alphanumeric': 0.07104345068189026, 'fraction_numerical': 0.0006343165239454488, 'mean_word_length': 3.00253807106599, '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': '948942', 'n_tokens_mistral': 947, 'n_tokens_neox': 930, 'n_words': 212}