import json

from django.http import HttpResponse, Http404, FileResponse
from django.template import loader, RequestContext
from django.contrib.auth.decorators import login_required
from .models import *
from django.conf import settings
from GeneralApp.funcs import get_inter_http_respose


def page_project_request_View(request):
    from .forms import ProjectRequestForm

    project_request_form = ProjectRequestForm()
    Dict = {
        'project_request_form': project_request_form
    }

    # breadcrumbs_Dict = {
    # }
    # Dict.update({'breadcrumbs': breadcrumbs_Dict})

    t = loader.get_template('pages/p_project_request.html')
    return get_inter_http_respose(t, Dict, request)



def section_view(request, url):

    try:
        section = Section.objects.get(url=url)


        # from ArticlesApp.models import ArticleModel
        # arts = ArticleModel.objects.filter(enable=True).order_by('-createDT')[:4]


        Dict = {
            'page': section,
            # 'articles': arts,
        }

        from .funcs import get_section_views_Dict
        Dict.update(get_section_views_Dict(section))

        # breadcrumbs_Dict = {
        # }
        # Dict.update({'breadcrumbs': breadcrumbs_Dict})

        t = loader.get_template('pages/p_section.html')
        return get_inter_http_respose(t, Dict, request)

    except Exception as e:
        msg = f'section_view Error = {str(e)}'
        print(msg)
        return HttpResponse(msg, status=400)
