some changes

This commit is contained in:
doesnm 2024-10-02 10:31:07 +03:00
parent def52230a9
commit 9896bbde6a
Signed by: doesnm
SSH key fingerprint: SHA256:fSXBOeK0SXxGqmbQ2pKhSvH3TF0kCijXZfzh3gHfQYM
5 changed files with 26 additions and 14 deletions

View file

@ -2,7 +2,7 @@ from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = 'django-insecure-b9md6nzc0(62ui4+6(=n9gw**rr5_lnq%f7-s675d&f0&8qf(+' SECRET_KEY = 'django-insecure-b9md6nzc0(62ui4+6(=n9gw**rr5_lnq%f7-s675d&f0&8qf(+'
DEBUG = True DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [ INSTALLED_APPS = [
'unfold', 'unfold',
'unfold.contrib.forms', 'unfold.contrib.forms',
@ -12,9 +12,11 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'cmsMain' 'cmsMain',
'corsheaders',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
@ -68,3 +70,5 @@ STATIC_URL = 'static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_URL = "/media/" MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "uploads" MEDIA_ROOT = BASE_DIR / "uploads"
CORS_ORIGIN_ALLOW_ALL = DEBUG
CSRF_TRUSTED_ORIGINS = ['http://localhost:8000','https://nn2bcsjezqausiclsiw6xe5drm.srv.us']

View file

@ -18,15 +18,15 @@ class GroupAdmin(GroupAdmin, ModelAdmin): pass
class UrlInline(TabularInline): class UrlInline(TabularInline):
model = Url model = Url
extra = 0 extra = 0
class PostInline(TabularInline):
model = Post @admin.register(Post)
extra = 0 class PostAdmin(ModelAdmin):
formfield_overrides = { formfield_overrides = {
models.TextField: { models.TextField: {
"widget": WysiwygWidget "widget": WysiwygWidget
} }
} }
def save_form(self,request,obj,form,change): def save_model(self,request,obj,form,change):
obj.author = request.user obj.author = request.user
obj.save() obj.save()
@ -34,7 +34,7 @@ class PostInline(TabularInline):
class SiteAdmin(ModelAdmin): class SiteAdmin(ModelAdmin):
list_display = ["domain","base_page"] list_display = ["domain","base_page"]
list_editable = ["base_page"] list_editable = ["base_page"]
inlines = [UrlInline,PostInline] inlines = [UrlInline]
@admin.register(Page) @admin.register(Page)
class PageAdmin(ModelAdmin): pass class PageAdmin(ModelAdmin): pass

View file

@ -1,9 +1,10 @@
from django.urls import path, include 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.urls.static import static
from django.conf import settings from django.conf import settings
urlpatterns = [ urlpatterns = [
*static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT), *static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT),
path('api/feedback',FeedbackView.as_view()),
path('<slug:page>',PageView.as_view()), path('<slug:page>',PageView.as_view()),
path('',MainView.as_view()) path('',MainView.as_view())
] ]

View file

@ -3,15 +3,20 @@ from django.views import View
from django import template from django import template
from .models import Site, Url, Variable, Post, Feedback from .models import Site, Url, Variable, Post, Feedback
from django.http import HttpResponse from django.http import HttpResponse
from django.conf import settings
context = template.Context({}) from django.middleware.csrf import get_token
context = template.Context({
})
class MainView(View): class MainView(View):
def get(self,request): def get(self,request):
return PageView.get(self,request,'root') return PageView.get(self,request,'root')
class PageView(View): class PageView(View):
def get(self,request,page): 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) r = Url.objects.filter(path=page,site=s)
post = None post = None
if "post" in request.GET: if "post" in request.GET:
@ -25,12 +30,13 @@ class PageView(View):
"title": r.page.title, "title": r.page.title,
"url": page, "url": page,
"posts": Post.objects.all(), "posts": Post.objects.all(),
"post": post "post": post,
"csrf": get_token(request)
}) })
t = template.Template(s.base_page.content) t = template.Template(s.base_page.content)
return HttpResponse(t.render(context)) return HttpResponse(t.render(context))
class FeedpackView(View): class FeedbackView(View):
def post(self,request): def post(self,request):
name = request.POST["name"] name = request.POST["name"]
email = request.POST["email"] email = request.POST["email"]

View file

@ -1,3 +1,4 @@
Django==5.1 Django==5.1
tzdata==2024.1 tzdata==2024.1
django-unfold==0.34.0 django-unfold==0.34.0
django-cors-headers==4.4.0