<commit_before>from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import render, redirect, render_to_response
from django.template import RequestContext

from api.models import MaintenanceRecord, MaintenanceNotice


def get_maintenance(request):
    """
    Returns a list of maintenance records along with a boolean to indicate
    whether or not login should be disabled
    """
    records = MaintenanceRecord.active()
    disable_login = MaintenanceRecord.disable_login_access(request)
    in_maintenance = records.count() > 0
    return (records, disable_login, in_maintenance)


def get_notices(request):
    """
    Returns a notice indicating details about a forthcoming maintenance period
    """
    records = MaintenanceNotice.active()
    has_notice = records.count() > 0
    record = records[0] if records.count() > 0 else records
    return (has_notice, record)


def maintenance(request):
    records, disabled, in_maint = get_maintenance(request)

    if not disabled:
        return redirect("/login")

    template_params = {}

    template_params["THEME_URL"] = "/themes/%s" % settings.THEME_NAME
    template_params['ORG_NAME'] = settings.ORG_NAME
    template_params['SITE_TITLE'] = settings.SITE_TITLE
    template_params['SITE_FOOTER'] = settings.SITE_FOOTER
    template_params["records"] = records
    template_params["disable_login"] = disabled
    if hasattr(settings, "BASE_URL"):
        template_params['BASE_URL'] = settings.BASE_URL

    return render_to_response(<commit_msg>Noted required Maintenance Notice refactor<commit_after>from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import render, redirect, render_to_response
from django.template import RequestContext

from api.models import MaintenanceRecord, MaintenanceNotice


def get_maintenance(request):
    """
    Returns a list of maintenance records along with a boolean to indicate
    whether or not login should be disabled
    """
    records = MaintenanceRecord.active()
    disable_login = MaintenanceRecord.disable_login_access(request)
    in_maintenance = records.count() > 0
    return (records, disable_login, in_maintenance)


def get_notices(request):
    """
    Returns a notice indicating details about a forthcoming maintenance period
    """
    # FIXME: this query object was accepted for the PR - but will need
    # to be refactored as a later date (PR 404)
    # NOTE: if you're seeing this message and it is past July 2016, then
    # lenards has dropped the :football: :frown-face:
    records = MaintenanceNotice.active()
    has_notice = records.count() > 0
    record = records[0] if records.count() > 0 else records
    return (has_notice, record)


def maintenance(request):
    records, disabled, in_maint = get_maintenance(request)

    if not disabled:
        return redirect("/login")

    template_params = {}

    template_params["THEME_URL"] = "/themes/%s" % settings.THEME_NAME
    template_params['ORG_NAME'] = settings.ORG_NAME
    template_params['SITE_TITLE'] = settings.SITE_TITLE
    template_params['SITE_FOOTER'] = settings.SITE_FOOTER
    template_params["records"] = records
    template_params["disable_login"] = disabled
    if hasattr(settings, "BASE_URL"):
        template_params['BASE_URL'] = settings.BASE_URL

    return render_to_response(
{'fraction_non_alphanumeric': 0.08479098725170471, 'fraction_numerical': 0.004447079750963534, 'mean_word_length': 4.255451713395638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5504155', 'n_tokens_mistral': 962, 'n_tokens_neox': 907, 'n_words': 271}