<commit_before>from __future__ import print_function
from __future__ import absolute_import
import random, datetime
import logging
import os
from django import forms
from django.forms.fields import Field
from django.forms.models import BaseModelFormSet
from django.forms.formsets import BaseFormSet
from django.forms.util import ErrorDict
from django.template import add_to_builtins
from django.contrib.admin.util import NestedObjects
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth import get_user_model
from django.conf import settings
from django.core.signals import request_started
from django.core.exceptions import ImproperlyConfigured
from django.dispatch import receiver
from django.utils.importlib import import_module
from django.utils.six import add_metaclass

logger = logging.getLogger(__name__)

# set the default place to send logs, and a CA cert file. Since logs.rc.pdx.edu
# has a cert signed by signed by PSUCA, that's the CA we're going to use
LOGSTASH_ADDRESS = getattr(settings, "LOGSTASH_ADDRESS", 'logs.rc.pdx.edu:5043')
LOGSTASH_CA_CERTS = getattr(settings, "LOGSTASH_CA_CERTS", os.path.normpath(os.path.join(os.path.dirname(__file__), "PSUCA.crt")))

CLEAR_EXPIRED_SESSIONS_AFTER_N_REQUESTS = getattr(settings, 'CLEAR_EXPIRED_SESSIONS_AFTER_N_REQUESTS', 100)

forms.Form.required_css_class = "required"
forms.ModelForm.required_css_class = "required"
Field.required_css_class = "required"

add_to_builtins('django.contrib.staticfiles.templatetags.staticfiles')
# add the arc template tags to the builtin tags, and the bootstrap tag
add_to_builtins('arcutils.templatetags.arc')
add_to_builtins('arcutils.templatetags.bootstrap')


# add some helpful methods to the formset
class FormSetMixin(object):
    def iter_with_empty_form_first(self):
        """
        Iterates over the forms in this formset, but the first form yielded
        is the empty one. This simplifies the logic in templates, since the
        empty_form is no longer a special case
        """
        yield self.empty_form
        for form in iter(self):
            yield form

    def clean(self):
        """
        When cleaning, if the form is being deleted, any errors on it should be
        ignored<commit_msg>Use pkg_resources.resource_filename when setting LOGSTASH_CA_CERTS<commit_after>from __future__ import print_function
from __future__ import absolute_import
import random, datetime
import logging
import os
import pkg_resources
from django import forms
from django.forms.fields import Field
from django.forms.models import BaseModelFormSet
from django.forms.formsets import BaseFormSet
from django.forms.util import ErrorDict
from django.template import add_to_builtins
from django.contrib.admin.util import NestedObjects
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth import get_user_model
from django.conf import settings
from django.core.signals import request_started
from django.core.exceptions import ImproperlyConfigured
from django.dispatch import receiver
from django.utils.importlib import import_module
from django.utils.six import add_metaclass

logger = logging.getLogger(__name__)

# set the default place to send logs, and a CA cert file. Since logs.rc.pdx.edu
# has a cert signed by signed by PSUCA, that's the CA we're going to use
LOGSTASH_ADDRESS = getattr(settings, "LOGSTASH_ADDRESS", 'logs.rc.pdx.edu:5043')
LOGSTASH_CA_CERTS = getattr(settings, "LOGSTASH_CA_CERTS", pkg_resources.resource_filename('arcutils', "PSUCA.crt"))

CLEAR_EXPIRED_SESSIONS_AFTER_N_REQUESTS = getattr(settings, 'CLEAR_EXPIRED_SESSIONS_AFTER_N_REQUESTS', 100)

forms.Form.required_css_class = "required"
forms.ModelForm.required_css_class = "required"
Field.required_css_class = "required"

add_to_builtins('django.contrib.staticfiles.templatetags.staticfiles')
# add the arc template tags to the builtin tags, and the bootstrap tag
add_to_builtins('arcutils.templatetags.arc')
add_to_builtins('arcutils.templatetags.bootstrap')


# add some helpful methods to the formset
class FormSetMixin(object):
    def iter_with_empty_form_first(self):
        """
        Iterates over the forms in this formset, but the first form yielded
        is the empty one. This simplifies the logic in templates, since the
        empty_form is no longer a special case
        """
        yield self.empty_form
        for form in iter(self):
            yield form

    def clean(self):
        """
        When cleaning, if the form is being deleted, any errors on it should be
        ignored
{'fraction_non_alphanumeric': 0.06537955243527863, 'fraction_numerical': 0.00307152259763054, 'mean_word_length': 4.8825806451612905, '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': '469774', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1323, 'n_words': 421}