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
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"
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):
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

View file

@ -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('<slug:page>',PageView.as_view()),
path('',MainView.as_view())
]

View file

@ -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"]

View file

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