cms/cmsMain/views.py

49 lines
1.5 KiB
Python
Raw Normal View History

2024-08-11 22:39:47 +03:00
from django.shortcuts import render, get_object_or_404
from django.views import View
2024-08-13 14:41:25 +03:00
from django import template
2024-09-07 18:59:47 +03:00
from .models import Site, Url, Variable, Post, Feedback
2024-08-13 14:41:25 +03:00
from django.http import HttpResponse
2024-10-02 10:31:07 +03:00
from django.conf import settings
from django.middleware.csrf import get_token
context = template.Context({
})
2024-08-11 22:39:47 +03:00
class MainView(View):
def get(self,request):
2024-08-13 17:01:55 +03:00
return PageView.get(self,request,'root')
2024-08-13 14:41:25 +03:00
class PageView(View):
def get(self,request,page):
2024-10-02 10:31:07 +03:00
if settings.DEBUG == True:
s = Site.objects.get(id=1)
else:
s = get_object_or_404(Site,domain=request.META["HTTP_HOST"])
2024-09-01 15:07:03 +03:00
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()
2024-08-13 17:01:55 +03:00
r = get_object_or_404(Url,path=page,site=s)
2024-08-13 14:41:25 +03:00
t = template.Template(r.page.content)
2024-08-13 17:01:55 +03:00
content = t.render(context)
context.update({
"content": content,
2024-09-01 15:07:03 +03:00
"title": r.page.title,
"url": page,
"posts": Post.objects.all(),
2024-10-02 10:31:07 +03:00
"post": post,
"csrf": get_token(request)
2024-08-13 17:01:55 +03:00
})
t = template.Template(s.base_page.content)
2024-09-07 18:59:47 +03:00
return HttpResponse(t.render(context))
2024-10-02 10:31:07 +03:00
class FeedbackView(View):
2024-09-07 18:59:47 +03:00
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("Ваше обращение отправлено успешно")