cms/cmsMain/views.py
2024-10-02 10:31:07 +03:00

49 lines
No EOL
1.5 KiB
Python

from django.shortcuts import render, get_object_or_404
from django.views import View
from django import template
from .models import Site, Url, Variable, Post, Feedback
from django.http import HttpResponse
from django.conf import settings
from django.middleware.csrf import get_token
context = template.Context({
})
class MainView(View):
def get(self,request):
return PageView.get(self,request,'root')
class PageView(View):
def get(self,request,page):
if settings.DEBUG == True:
s = Site.objects.get(id=1)
else:
s = get_object_or_404(Site,domain=request.META["HTTP_HOST"])
r = Url.objects.filter(path=page,site=s)
post = None
if "post" in request.GET:
post = Post.objects.filter(url=request.GET["post"])
if post: post = post.first()
r = get_object_or_404(Url,path=page,site=s)
t = template.Template(r.page.content)
content = t.render(context)
context.update({
"content": content,
"title": r.page.title,
"url": page,
"posts": Post.objects.all(),
"post": post,
"csrf": get_token(request)
})
t = template.Template(s.base_page.content)
return HttpResponse(t.render(context))
class FeedbackView(View):
def post(self,request):
name = request.POST["name"]
email = request.POST["email"]
message = request.POST["message"]
Feedback.objects.create(
name=name,
email=email,
message=message
)
return HttpResponse("Ваше обращение отправлено успешно")