<commit_before>import re
from traceback import print_exc

import requests
from django import template
from django.contrib.admin.templatetags.admin_list import (
    result_list as _result_list,
)
from django.contrib.staticfiles import finders
from django.core.cache import InvalidCacheBackendError, caches
from django.urls import reverse
from django.utils import timezone
from django.utils.formats import date_format
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from lxml.html import fromstring, tostring

from ..conf import settings
from ..forms.schoolyear import SchoolYearForm
from ..utils import (
    comma_separated as _comma_separated, currency as _currency,
    current_url as _current_url, first_upper as _first_upper,
    url_back as _url_back, url_with_back as _url_with_back,
)

register = template.Library()


@register.filter
def currency(value):
    try:
        return _currency(value)
    except (ValueError, TypeError):
        return ''


@register.filter
def comma_separated(value):
    return _comma_separated(value)


@register.filter
def first_upper(value):
    return _first_upper(value)


@register.filter
def filter_current_school_year(value, school_year):
    return value.filter(school_year=school_year)


@register.filter
def lines(value):
    try:
        return value.strip().split('\n')
    except Exception:
        return []


@register.simple_tag
def param_back():
    return settings.LEPRIKON_PARAM_BACK


@register.simple_tag(takes_context=True)
def url_back(context):
    return _url_back(context['request'])


@register.simple_tag(takes_context=True)
def current_url(context):
    return _current_url(context['request'])


@register.inclusion_tag('leprikon/registration_links.html', takes_context=True)
def registration_links(context, subject):
    now = timezone.now()
    context = context.__copy__()
    context['subject'] = subject
    if context['request'].user.is_authenticated():
        context['registrations'] = subject.registrations.filter(user=context['request'].user, canceled=None)
    else:
        context['registrations'] = []

    if hasattr(context['view'], 'registration_link'):
        source = context['view'].registration_link
        context['registration_url'] = _url_with_back(
            reverse('leprikon:registration_link_form', args=(source.slug, subject.id)),
            current_url(context),
        )
    else:
        source = subject
        context['registration_url'] = _url_with_back(subject.get_registration_url(), current_url(context))

    context['registration_allowed'] = source.registration_allowed

    if context['registration_allowed']:
        context['registration_message'] = ''
    else:
        context['registration_message'] = _('Registering is currently not allowed.')

    if subject.price and source.reg_to:
        context['registration_ended_message'] = _('Registering ended on {}').format(
            date_format(source.reg_to, 'SHORT_DATETIME_FORMAT')
        )
        if source.reg_to > now:
            context['registration_end_in'] = (source.reg_to - now).seconds
            context['registration_ends_message'] = _('Registering will end on {}.').format(
                date_format(source.reg_to, 'SHORT_DATETIME_FORMAT')
            )
            context['registration_message'] = context['registration_ends_message']
        else:
            context['registration_message'] = context['registration_ended_message']
    if subject.price and source.reg_from and source.reg_from > now:
        context['registration_start_in'] = (source.reg_from - now).seconds
        context['registration_starts_message'] = _('Registering will start on {}.').format(
            date_format(source.reg_from, 'SHORT_DATETIME_FORMAT')
        )
        context['registration_message'] = context['registration_starts_message']
    return context
<commit_msg>Fix registration start / end timezone and format<commit_after>import re
from traceback import print_exc

import requests
from django import template
from django.contrib.admin.templatetags.admin_list import (
    result_list as _result_list,
)
from django.contrib.staticfiles import finders
from django.core.cache import InvalidCacheBackendError, caches
from django.urls import reverse
from django.utils import timezone
from django.utils.formats import date_format
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from lxml.html import fromstring, tostring

from ..conf import settings
from ..forms.schoolyear import SchoolYearForm
from ..utils import (
    comma_separated as _comma_separated, currency as _currency,
    current_url as _current_url, first_upper as _first_upper,
    url_back as _url_back, url_with_back as _url_with_back,
)

register = template.Library()


@register.filter
def currency(value):
    try:
        return _currency(value)
    except (ValueError, TypeError):
        return ''


@register.filter
def comma_separated(value):
    return _comma_separated(value)


@register.filter
def first_upper(value):
    return _first_upper(value)


@register.filter
def filter_current_school_year(value, school_year):
    return value.filter(school_year=school_year)


@register.filter
def lines(value):
    try:
        return value.strip().split('\n')
    except Exception:
        return []


@register.simple_tag
def param_back():
    return settings.LEPRIKON_PARAM_BACK


@register.simple_tag(takes_context=True)
def url_back(context):
    return _url_back(context['request'])


@register.simple_tag(takes_context=True)
def current_url(context):
    return _current_url(context['request'])


@register.inclusion_tag('leprikon/registration_links.html', takes_context=True)
def registration_links(context, subject):
    now = timezone.now()
    context = context.__copy__()
    context['subject'] = subject
    if context['request'].user.is_authenticated():
        context['registrations'] = subject.registrations.filter(user=context['request'].user, canceled=None)
    else:
        context['registrations'] = []

    if hasattr(context['view'], 'registration_link'):
        source = context['view'].registration_link
        context['registration_url'] = _url_with_back(
            reverse('leprikon:registration_link_form', args=(source.slug, subject.id)),
            current_url(context),
        )
    else:
        source = subject
        context['registration_url'] = _url_with_back(subject.get_registration_url(), current_url(context))

    context['registration_allowed'] = source.registration_allowed

    if context['registration_allowed']:
        context['registration_message'] = ''
    else:
        context['registration_message'] = _('Registering is currently not allowed.')

    if subject.price and source.reg_to:
        context['registration_ended_message'] = _('Registering ended on {}').format(
            date_format(timezone.localtime(source.reg_to), 'DATETIME_FORMAT')
        )
        if source.reg_to > now:
            context['registration_end_in'] = (source.reg_to - now).seconds
            context['registration_ends_message'] = _('Registering will end on {}.').format(
                date_format(timezone.localtime(source.reg_to), 'DATETIME_FORMAT')
            )
            context['registration_message'] = context['registration_ends_message']
        else:
            context['registration_message'] = context['registration_ended_message']
    if subject.price and source.reg_from and source.reg_from > now:
        context['registration_start_in'] = (source.reg_from - now).seconds
        context['registration_starts_message'] = _('Registering will start on {}.').format(
            date_format(timezone.localtime(source.reg_from), 'DATETIME_FORMAT')
        )
        context['registration_message'] = context['registration_starts_message']
    return context

{'fraction_non_alphanumeric': 0.1023951336966164, 'fraction_numerical': 0.0, 'mean_word_length': 4.085051546391752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2962954', 'n_tokens_mistral': 2294, 'n_tokens_neox': 2206, 'n_words': 472}