from django.http import HttpResponse, Http404, FileResponse
from admin_interface.templatetags.admin_interface_tags import get_admin_interface_theme

def get_logo_url():
    theme = get_admin_interface_theme()
    return theme.logo.url


def get_footer_contacts():
    from .models import Option
    options = Option.objects.filter(enable=True, opt_type__in=['footer_email', 'footer_phone']).order_by('order')
    return options


def get_inter_Dict(user, context_Dict):
    form_name = None

    Dict = {}

    from ServicesApp.funcs import get_sections
    sections = get_sections()

    page = None
    page_scheme = None
    hide_form_field_description = False
    if 'page' in context_Dict and context_Dict['page']:
        page = context_Dict['page']
        page_scheme = getattr(page, 'page_scheme', None)

        fb_block = page.get_feedback_block()
        if fb_block:
            form_name = fb_block.name

    if form_name:
        kwargs_form = {}
        from .forms import FeedbackForm
        if page_scheme and page_scheme == 'plugin':
            kwargs_form.update({'del_descr': True})
        feedback_form = FeedbackForm(**kwargs_form)
        feedback_form.initial = {'form_name': form_name}
        Dict.update({'feedback_form': feedback_form})

    Dict.update({
        'sections': sections,
        'logo': get_logo_url(),
        'hide_form_field_description': hide_form_field_description,
        'footer_contacts': get_footer_contacts(),
    })
    # from SubscribesApp.funcs import get_cur_user_subscribe
    # user_subscribe = get_cur_user_subscribe(user)

    # Dict.update({'user_subscribe': user_subscribe})

    return Dict

def get_inter_http_respose(template_obj, context_Dict, request):

    context_Dict.update(get_inter_Dict(request.user, context_Dict))

    return HttpResponse(template_obj.render(context_Dict, request))