from django.template import Library
from django.urls import resolve, reverse
from django.utils.translation import activate, get_language
from datetime import datetime

import re

import logging
logger = logging.getLogger(__name__)

register = Library()

@register.simple_tag
def format_time(timestamp: datetime, format: str = "%F %H:%M:%S %Z") -> str:
    return timestamp.strftime(format)

@register.simple_tag(takes_context=True)
def query_transform(context, **kwargs):
    """
    Modify the GET parameters of a request from templates
    """
    query = context['request'].GET.copy()
    for k, v in kwargs.items():
        query[k] = v
    return query.urlencode()
