initial
This commit is contained in:
0
custompage/__init__.py
Normal file
0
custompage/__init__.py
Normal file
4
custompage/admin.py
Normal file
4
custompage/admin.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from django.contrib import admin
|
||||
from custompage.models import *
|
||||
|
||||
admin.site.register(customPage)
|
||||
6
custompage/apps.py
Normal file
6
custompage/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CustompageConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'custompage'
|
||||
12
custompage/forms.py
Normal file
12
custompage/forms.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from django import forms
|
||||
from custompage.models import customPage
|
||||
|
||||
class customPageForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = customPage
|
||||
fields = '__all__'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
for field in self.fields.values():
|
||||
field.widget.attrs['class'] = 'form-control'
|
||||
24
custompage/migrations/0001_initial.py
Normal file
24
custompage/migrations/0001_initial.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 4.2.6 on 2023-10-27 20:59
|
||||
|
||||
import ckeditor.fields
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='customPage',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=100)),
|
||||
('slug', models.SlugField(blank=True, null=True, unique=True)),
|
||||
('content', ckeditor.fields.RichTextField()),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
custompage/migrations/__init__.py
Normal file
0
custompage/migrations/__init__.py
Normal file
16
custompage/models.py
Normal file
16
custompage/models.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from django.db import models
|
||||
from ckeditor.fields import RichTextField
|
||||
from django.utils.text import slugify
|
||||
|
||||
class customPage(models.Model):
|
||||
title = models.CharField(max_length=100)
|
||||
slug = models.SlugField(unique=True, blank=True, null=True)
|
||||
content = RichTextField()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.slug = slugify(self.title)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
3
custompage/tests.py
Normal file
3
custompage/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
11
custompage/urls.py
Normal file
11
custompage/urls.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from django.urls import path
|
||||
from custompage.views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/custom-pages/', adminCustomPage.as_view(), name='adminCustomPage'),
|
||||
path('admin/create/custom-page/', adminCustomPageCreate.as_view(), name='adminCustomPageCreate'),
|
||||
path('admin/custom-pages/edit/<str:slug>', adminCustomPageEdit.as_view(), name='adminCustomPageEdit'),
|
||||
path('admin/custom-pages/<int:id>', adminCustomPageDelete, name='adminCustomPageDelete'),
|
||||
|
||||
path('<str:slug>/', customPageFront, name='customPageFront')
|
||||
]
|
||||
59
custompage/views.py
Normal file
59
custompage/views.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from custompage.models import customPage
|
||||
from custompage.forms import customPageForm
|
||||
from django.views.generic import CreateView, UpdateView, ListView
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib import messages
|
||||
from django.urls import reverse_lazy
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
# Admin Custom Page Views
|
||||
class adminCustomPage(LoginRequiredMixin,ListView):
|
||||
model = customPage
|
||||
template_name = 'dashboard/main/custompage/index.html'
|
||||
context_object_name = 'pages'
|
||||
extra_context = {'title': 'All Custom Pages'}
|
||||
login_url = reverse_lazy('logIn')
|
||||
|
||||
class adminCustomPageCreate(LoginRequiredMixin,CreateView):
|
||||
model = customPage
|
||||
form_class = customPageForm
|
||||
template_name = 'dashboard/main/custompage/create.html'
|
||||
success_url = reverse_lazy('adminCustomPage')
|
||||
extra_context = {'title': 'Create Page'}
|
||||
login_url = reverse_lazy('logIn')
|
||||
|
||||
def form_valid(self, form):
|
||||
messages.success(self.request, 'Page created successfully!')
|
||||
return super().form_valid(form)
|
||||
|
||||
class adminCustomPageEdit(LoginRequiredMixin,UpdateView):
|
||||
model = customPage
|
||||
form_class = customPageForm
|
||||
template_name = 'dashboard/main/custompage/edit.html'
|
||||
success_url = reverse_lazy('adminCustomPage')
|
||||
extra_context = {'title': 'Edit Page'}
|
||||
login_url = reverse_lazy('logIn')
|
||||
|
||||
def form_valid(self, form):
|
||||
messages.success(self.request, 'Page updated successfully!')
|
||||
return super().form_valid(form)
|
||||
|
||||
@login_required(login_url='logIn')
|
||||
def adminCustomPageDelete(request,id):
|
||||
page = get_object_or_404(customPage, id=id)
|
||||
messages.warning(request, 'Page deleted successfully!')
|
||||
page.delete()
|
||||
return redirect('adminCustomPage')
|
||||
|
||||
# Custom Page Front
|
||||
def customPageFront(request, slug):
|
||||
page = get_object_or_404(customPage, slug=slug)
|
||||
return render(request, 'front/main/partial/custom_page.html', {'page': page})
|
||||
|
||||
# Error Page
|
||||
def error_404(request, exception):
|
||||
return render(request, 'error/404.html', status=404)
|
||||
|
||||
def error_500(request):
|
||||
return render(request, 'error/500.html', status=500)
|
||||
Reference in New Issue
Block a user