From 9896bbde6a990746ea18575d0d5ff3d9c2234dae Mon Sep 17 00:00:00 2001 From: doesnm Date: Wed, 2 Oct 2024 10:31:07 +0300 Subject: [PATCH] some changes --- cms/settings.py | 10 +++++++--- cmsMain/admin.py | 10 +++++----- cmsMain/urls.py | 3 ++- cmsMain/views.py | 16 +++++++++++----- requirements.txt | 1 + 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/cms/settings.py b/cms/settings.py index 664e406..94ab1e5 100644 --- a/cms/settings.py +++ b/cms/settings.py @@ -2,7 +2,7 @@ from pathlib import Path BASE_DIR = Path(__file__).resolve().parent.parent SECRET_KEY = 'django-insecure-b9md6nzc0(62ui4+6(=n9gw**rr5_lnq%f7-s675d&f0&8qf(+' DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["*"] INSTALLED_APPS = [ 'unfold', 'unfold.contrib.forms', @@ -12,9 +12,11 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'cmsMain' + 'cmsMain', + 'corsheaders', ] MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -67,4 +69,6 @@ USE_TZ = True STATIC_URL = 'static/' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' MEDIA_URL = "/media/" -MEDIA_ROOT = BASE_DIR / "uploads" \ No newline at end of file +MEDIA_ROOT = BASE_DIR / "uploads" +CORS_ORIGIN_ALLOW_ALL = DEBUG +CSRF_TRUSTED_ORIGINS = ['http://localhost:8000','https://nn2bcsjezqausiclsiw6xe5drm.srv.us'] \ No newline at end of file diff --git a/cmsMain/admin.py b/cmsMain/admin.py index 5abc470..b3cbd11 100644 --- a/cmsMain/admin.py +++ b/cmsMain/admin.py @@ -18,15 +18,15 @@ class GroupAdmin(GroupAdmin, ModelAdmin): pass class UrlInline(TabularInline): model = Url extra = 0 -class PostInline(TabularInline): - model = Post - extra = 0 + +@admin.register(Post) +class PostAdmin(ModelAdmin): formfield_overrides = { models.TextField: { "widget": WysiwygWidget } } - def save_form(self,request,obj,form,change): + def save_model(self,request,obj,form,change): obj.author = request.user obj.save() @@ -34,7 +34,7 @@ class PostInline(TabularInline): class SiteAdmin(ModelAdmin): list_display = ["domain","base_page"] list_editable = ["base_page"] - inlines = [UrlInline,PostInline] + inlines = [UrlInline] @admin.register(Page) class PageAdmin(ModelAdmin): pass diff --git a/cmsMain/urls.py b/cmsMain/urls.py index aecc6e5..a05cdfe 100644 --- a/cmsMain/urls.py +++ b/cmsMain/urls.py @@ -1,9 +1,10 @@ from django.urls import path, include -from .views import MainView, PageView +from .views import MainView, PageView, FeedbackView from django.conf.urls.static import static from django.conf import settings urlpatterns = [ *static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT), +path('api/feedback',FeedbackView.as_view()), path('',PageView.as_view()), path('',MainView.as_view()) ] diff --git a/cmsMain/views.py b/cmsMain/views.py index 49790f1..04b56ea 100644 --- a/cmsMain/views.py +++ b/cmsMain/views.py @@ -3,15 +3,20 @@ from django.views import View from django import template from .models import Site, Url, Variable, Post, Feedback from django.http import HttpResponse - -context = template.Context({}) +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): - s = get_object_or_404(Site,domain=request.META["HTTP_HOST"]) + 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: @@ -25,12 +30,13 @@ class PageView(View): "title": r.page.title, "url": page, "posts": Post.objects.all(), - "post": post + "post": post, + "csrf": get_token(request) }) t = template.Template(s.base_page.content) return HttpResponse(t.render(context)) -class FeedpackView(View): +class FeedbackView(View): def post(self,request): name = request.POST["name"] email = request.POST["email"] diff --git a/requirements.txt b/requirements.txt index 2f32c45..08bf60c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Django==5.1 tzdata==2024.1 django-unfold==0.34.0 +django-cors-headers==4.4.0