first commit
This commit is contained in:
0
module_cms/__init__.py
Normal file
0
module_cms/__init__.py
Normal file
6
module_cms/admin.py
Normal file
6
module_cms/admin.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.contrib import admin
|
||||
from .models import Faqs, Organization
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Faqs)
|
||||
admin.site.register(Organization)
|
||||
40
module_cms/api/serializers.py
Normal file
40
module_cms/api/serializers.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from rest_framework import serializers
|
||||
from taggit.models import Tag
|
||||
from module_cms.models import Faqs, Organization
|
||||
|
||||
class FaqSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Faqs
|
||||
fields = ["id", "question", "answer"]
|
||||
|
||||
class FaqListSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Faqs
|
||||
fields = "__all__"
|
||||
|
||||
class OrganizationSerializer(serializers.ModelSerializer):
|
||||
about_us = serializers.CharField(source='about_us.html', read_only=True)
|
||||
terms_condition = serializers.CharField(source='terms_condition.html', read_only=True)
|
||||
terms_condition_user = serializers.CharField(source='terms_condition_user.html', read_only=True)
|
||||
terms_condition_merchant = serializers.CharField(source='terms_condition_merchant.html', read_only=True)
|
||||
privacy_policy = serializers.CharField(source='privacy_policy.html', read_only=True)
|
||||
privacy_policy_user = serializers.CharField(source='privacy_policy_user.html', read_only=True)
|
||||
privacy_policy_merchant = serializers.CharField(source='privacy_policy_merchant.html', read_only=True)
|
||||
subscription_agreement = serializers.CharField(source='subscription_agreement.html', read_only=True)
|
||||
license_agreement_user = serializers.CharField(source='license_agreement_user.html', read_only=True)
|
||||
license_agreement_merchant = serializers.CharField(source='license_agreement_merchant.html', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Organization
|
||||
fields = [
|
||||
"about_us",
|
||||
"terms_condition",
|
||||
"terms_condition_user",
|
||||
"terms_condition_merchant",
|
||||
"privacy_policy",
|
||||
"privacy_policy_user",
|
||||
"privacy_policy_merchant",
|
||||
"subscription_agreement",
|
||||
"license_agreement_user",
|
||||
"license_agreement_merchant",
|
||||
]
|
||||
7
module_cms/api/urls.py
Normal file
7
module_cms/api/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("faq/", views.FaqListAPIView.as_view()),
|
||||
path("organization/", views.OrganizationAPIView.as_view())
|
||||
]
|
||||
30
module_cms/api/views.py
Normal file
30
module_cms/api/views.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||
from module_project import constants
|
||||
from module_project.utils import ApiResponse
|
||||
from .serializers import FaqSerializer, OrganizationSerializer
|
||||
from ..models import Faqs, Organization
|
||||
|
||||
|
||||
class FaqListAPIView(APIView):
|
||||
authentication_classes = [JWTAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
serializer_class = FaqSerializer
|
||||
model = Faqs
|
||||
|
||||
def get(self, request):
|
||||
queryset = self.model.objects.filter(active=True)
|
||||
serializer = self.serializer_class(queryset, many=True)
|
||||
return ApiResponse.success(message=constants.SUCCESS, data=serializer.data)
|
||||
|
||||
class OrganizationAPIView(APIView):
|
||||
authentication_classes = [JWTAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
serializer_class = OrganizationSerializer
|
||||
model = Organization
|
||||
|
||||
def get(self, request):
|
||||
queryset = self.model.objects.filter(active=True).last()
|
||||
serializer = self.serializer_class(queryset)
|
||||
return ApiResponse.success(message=constants.SUCCESS, data=serializer.data)
|
||||
6
module_cms/apps.py
Normal file
6
module_cms/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ModuleCmsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'module_cms'
|
||||
83
module_cms/forms.py
Normal file
83
module_cms/forms.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core import validators
|
||||
from .models import (
|
||||
Organization,
|
||||
FaqCategory,
|
||||
Faqs,
|
||||
)
|
||||
|
||||
from module_project import constants
|
||||
|
||||
|
||||
class OrganizationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Organization
|
||||
fields = [
|
||||
"title",
|
||||
"contact_us_email",
|
||||
"instagram_handle",
|
||||
"facebook_handle",
|
||||
"linkedin_handle",
|
||||
"logo_image",
|
||||
"favicon_image",
|
||||
"website_url",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": "Organization Title",
|
||||
"contact_us_email": "Contact Email",
|
||||
"instagram_handle": "Instagram URL",
|
||||
"facebook_handle": "Facebook URL",
|
||||
"linkedin_handle": "LinkedIn URL",
|
||||
"logo_image": "Organization Logo",
|
||||
"favicon_image": "Favicon",
|
||||
"website_url": "Website URL",
|
||||
}
|
||||
|
||||
class AboutUsForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Organization
|
||||
fields = ["about_us"]
|
||||
labels = {"about_us": "Enter information about your organization:"}
|
||||
|
||||
class TermsAndConditionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Organization
|
||||
fields = ["terms_condition"]
|
||||
labels = {"terms_condition": "Enter Terms and Conditions:"}
|
||||
|
||||
class PrivacyPolicyForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Organization
|
||||
fields = ["privacy_policy"]
|
||||
labels = {"privacy_policy": "Enter Privacy Police:"}
|
||||
|
||||
|
||||
class FaqCategoryFrom(forms.ModelForm):
|
||||
class Meta:
|
||||
model = FaqCategory
|
||||
fields = ["name"]
|
||||
labels = {"name": "Category name"}
|
||||
|
||||
|
||||
class FaqsForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Faqs
|
||||
fields = [
|
||||
# "faq_category",
|
||||
"question",
|
||||
"answer",
|
||||
"active",
|
||||
]
|
||||
# labels = {"faq_category": "Category"}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
instance = kwargs.get("instance")
|
||||
super().__init__(*args, **kwargs)
|
||||
# Fetch the choices for the faq_category field from the database
|
||||
# self.fields["faq_category"].queryset = FaqCategory.objects.all()
|
||||
|
||||
if instance is None:
|
||||
# This is an add operation, exclude the 'active' field
|
||||
self.fields.pop("active")
|
||||
81
module_cms/migrations/0001_initial.py
Normal file
81
module_cms/migrations/0001_initial.py
Normal file
@@ -0,0 +1,81 @@
|
||||
# Generated by Django 5.0.2 on 2024-02-14 14:09
|
||||
|
||||
import django.db.models.deletion
|
||||
import django_quill.fields
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='FaqCategory',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('deleted', models.BooleanField(default=False)),
|
||||
('created_on', models.DateTimeField(auto_now_add=True)),
|
||||
('modified_on', models.DateTimeField(auto_now=True)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_created', to=settings.AUTH_USER_MODEL)),
|
||||
('modified_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_modified', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'faq_category',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Faqs',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('deleted', models.BooleanField(default=False)),
|
||||
('created_on', models.DateTimeField(auto_now_add=True)),
|
||||
('modified_on', models.DateTimeField(auto_now=True)),
|
||||
('question', models.TextField(max_length=255)),
|
||||
('answer', models.TextField(blank=True, null=True)),
|
||||
('published', models.BooleanField(default=True)),
|
||||
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_created', to=settings.AUTH_USER_MODEL)),
|
||||
('faq_category', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='faqs_category', to='module_cms.faqcategory')),
|
||||
('modified_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_modified', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'faq',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Organization',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('deleted', models.BooleanField(default=False)),
|
||||
('created_on', models.DateTimeField(auto_now_add=True)),
|
||||
('modified_on', models.DateTimeField(auto_now=True)),
|
||||
('title', models.CharField(max_length=255)),
|
||||
('contact_us_email', models.EmailField(blank=True, max_length=254, null=True, unique=True)),
|
||||
('instagram_handle', models.URLField(blank=True, null=True)),
|
||||
('facebook_handle', models.URLField(blank=True, null=True)),
|
||||
('linkedin_handle', models.URLField(blank=True, null=True)),
|
||||
('logo_image', models.ImageField(blank=True, null=True, upload_to='organization/logo')),
|
||||
('favicon_image', models.ImageField(blank=True, null=True, upload_to='organization/favicon')),
|
||||
('website_url', models.URLField(blank=True, null=True)),
|
||||
('about_us', django_quill.fields.QuillField()),
|
||||
('terms_condition', django_quill.fields.QuillField()),
|
||||
('privacy_policy', django_quill.fields.QuillField()),
|
||||
('subscription_agreement', django_quill.fields.QuillField()),
|
||||
('license_agreement', django_quill.fields.QuillField()),
|
||||
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_created', to=settings.AUTH_USER_MODEL)),
|
||||
('modified_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_modified', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'organization',
|
||||
},
|
||||
),
|
||||
]
|
||||
17
module_cms/migrations/0002_remove_faqs_published.py
Normal file
17
module_cms/migrations/0002_remove_faqs_published.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.0.2 on 2024-02-14 14:11
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('module_cms', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='faqs',
|
||||
name='published',
|
||||
),
|
||||
]
|
||||
19
module_cms/migrations/0003_alter_faqs_faq_category.py
Normal file
19
module_cms/migrations/0003_alter_faqs_faq_category.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0.2 on 2024-02-14 14:13
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('module_cms', '0002_remove_faqs_published'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='faqs',
|
||||
name='faq_category',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='faqs_category', to='module_cms.faqcategory'),
|
||||
),
|
||||
]
|
||||
0
module_cms/migrations/__init__.py
Normal file
0
module_cms/migrations/__init__.py
Normal file
51
module_cms/models.py
Normal file
51
module_cms/models.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from django.db import models
|
||||
from module_iam.models import BaseModel, IAmPrincipal
|
||||
from taggit.managers import TaggableManager
|
||||
from django_quill.fields import QuillField
|
||||
|
||||
# Create your models here.
|
||||
class Organization(BaseModel):
|
||||
title = models.CharField(max_length=255)
|
||||
contact_us_email = models.EmailField(unique=True, blank=True, null=True)
|
||||
instagram_handle = models.URLField(blank=True, null=True)
|
||||
facebook_handle = models.URLField(blank=True, null=True)
|
||||
linkedin_handle = models.URLField(blank=True, null=True)
|
||||
logo_image = models.ImageField(blank=True, null=True, upload_to="organization/logo")
|
||||
favicon_image = models.ImageField(
|
||||
blank=True, null=True, upload_to="organization/favicon"
|
||||
)
|
||||
website_url = models.URLField(blank=True, null=True)
|
||||
about_us = QuillField()
|
||||
terms_condition = QuillField()
|
||||
privacy_policy = QuillField()
|
||||
subscription_agreement = QuillField()
|
||||
license_agreement = QuillField()
|
||||
|
||||
class Meta:
|
||||
db_table = "organization"
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class FaqCategory(BaseModel):
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
class Meta:
|
||||
db_table = "faq_category"
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Faqs(BaseModel):
|
||||
faq_category = models.ForeignKey(
|
||||
FaqCategory, related_name="faqs_category", blank=True, null=True, on_delete=models.SET_NULL
|
||||
)
|
||||
question = models.TextField(max_length=255)
|
||||
answer = models.TextField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "faq"
|
||||
|
||||
def __str__(self):
|
||||
return self.question
|
||||
3
module_cms/tests.py
Normal file
3
module_cms/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
19
module_cms/urls.py
Normal file
19
module_cms/urls.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = "module_cms"
|
||||
|
||||
urlpatterns = [
|
||||
path('faq/', views.FaqView.as_view(), name="faq"),
|
||||
path('faq/list/', views.FaqListJson.as_view(), name="faq_list"),
|
||||
path('faq/add/', views.FaqCreateOrUpdateView.as_view(), name='faq_add'),
|
||||
|
||||
path('about-us/', views.AboutUsView.as_view(), name='about_us'),
|
||||
path('about-us/edit/', views.AboutUsCreateOrUpdateView.as_view(), name='about_us_add'),
|
||||
|
||||
path('terms-condition/', views.TermsConditionView.as_view(), name='terms_and_condition'),
|
||||
path('terms-condition/edit/', views.TermsConditionCreateOrUpdateView.as_view(), name='terms_and_condition_edit'),
|
||||
|
||||
path('privacy-policy/', views.PrivacyPolicyView.as_view(), name='privacy_policy'),
|
||||
path('privacy-policy/edit/', views.PrivacyPolicyCreateOrUpdateView.as_view(), name='privacy_policy_edit'),
|
||||
]
|
||||
331
module_cms/views.py
Normal file
331
module_cms/views.py
Normal file
@@ -0,0 +1,331 @@
|
||||
import logging
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
from django.views import generic
|
||||
from module_iam.models import IAmPrincipal
|
||||
from .forms import AboutUsForm, TermsAndConditionForm, FaqCategoryFrom, PrivacyPolicyForm
|
||||
from .models import Faqs, Organization
|
||||
from .api.serializers import FaqListSerializer
|
||||
from module_project.mixins import DatatablesMixin
|
||||
from django_datatables_view.base_datatable_view import BaseDatatableView
|
||||
|
||||
from module_project import constants
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FaqView(LoginRequiredMixin, generic.TemplateView):
|
||||
page_name = None
|
||||
resource = None
|
||||
action = None
|
||||
template_name = "module_cms/faq.html"
|
||||
model = Faqs
|
||||
context_objext_name = "obj"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_name"] = self.page_name
|
||||
return context
|
||||
|
||||
|
||||
# class FaqDatatableView(DatatablesMixin, LoginRequiredMixin, generic.View):
|
||||
# model = Faqs
|
||||
|
||||
# def get_queryset(self):
|
||||
# return self.model.objects.filter(deleted=False)
|
||||
|
||||
# def get(self, request):
|
||||
# (
|
||||
# draw,
|
||||
# start,
|
||||
# length,
|
||||
# order_columns,
|
||||
# order_directions,
|
||||
# search_value,
|
||||
# ) = self.get_datatables_params(request)
|
||||
# queryset = self.get_queryset()
|
||||
|
||||
# page_obj, total_count, filtered_count = self.get_pagination(
|
||||
# queryset, start, length
|
||||
# )
|
||||
|
||||
# serializer = FaqListSerializer(
|
||||
# page_obj.object_list, many=True
|
||||
# )
|
||||
|
||||
# response = self.prepare_datatables_response(
|
||||
# draw, total_count, filtered_count, serializer.data
|
||||
# )
|
||||
|
||||
# return response
|
||||
|
||||
|
||||
class FaqListJson(BaseDatatableView):
|
||||
model = Faqs
|
||||
columns = ["id", "question", "answer", "active", "deleted"]
|
||||
order_columns = ["id", "question", "answer", "active", "deleted"]
|
||||
|
||||
def filter_queryset(self, qs):
|
||||
# Implement your custom filtering logic here
|
||||
print(f"request is {self.request.GET}")
|
||||
search_value = self.request.GET.get("search[value]", None)
|
||||
if search_value:
|
||||
qs = qs.filter(
|
||||
Q(id__icontains=search_value)
|
||||
| Q(question__icontains=search_value)
|
||||
| Q(answer__icontains=search_value)
|
||||
)
|
||||
|
||||
for column in self.columns:
|
||||
search_value = self.request.GET.get(f'columns[{self.columns.index(column)}][search][value]', None)
|
||||
if search_value:
|
||||
qs = qs.filter(**{f"{column}__icontains": search_value})
|
||||
|
||||
return qs
|
||||
|
||||
|
||||
class FaqCreateOrUpdateView(generic.View):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
class AboutUsView(LoginRequiredMixin, generic.DetailView):
|
||||
page_name = None
|
||||
template_name = "module_cms/about_us_view.html"
|
||||
model = Organization
|
||||
context_object_name = "organization"
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.model.objects.only("about_us").first()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_name"] = self.page_name
|
||||
return context
|
||||
|
||||
|
||||
class AboutUsCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
||||
# Set the page_name and resource
|
||||
page_name = None
|
||||
resource = None
|
||||
|
||||
# Initialize the action as ACTION_CREATE (can change based on logic)
|
||||
action = None # Default action
|
||||
|
||||
template_name = "module_cms/about_us_add.html"
|
||||
model = Organization
|
||||
form_class = AboutUsForm
|
||||
success_url = reverse_lazy("module_cms:about_us")
|
||||
error_message = "An error occurred while saving the data."
|
||||
|
||||
# Determine the success message dynamically based on whether it's an update or create
|
||||
def get_success_message(self):
|
||||
self.success_message = (
|
||||
constants.RECORD_CREATED if not self.object else constants.RECORD_UPDATED
|
||||
)
|
||||
return self.success_message
|
||||
|
||||
# Get the object (if exists) based on URL parameter 'pk'
|
||||
def get_object(self):
|
||||
return self.model.objects.only("about_us").first()
|
||||
|
||||
# Add page_name and operation to the context
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
"page_name": self.page_name,
|
||||
"operation": "Add" if not self.object else "Edit",
|
||||
}
|
||||
context.update(kwargs) # Include any additional context data passed to the view
|
||||
return context
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
# If an object is found, change action to ACTION_UPDATE
|
||||
if self.object is not None:
|
||||
self.action = None
|
||||
|
||||
form = self.form_class(instance=self.object)
|
||||
context = self.get_context_data(form=form)
|
||||
return render(request, self.template_name, context=context)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
# If an object is found, change action to ACTION_UPDATE
|
||||
if self.object is not None:
|
||||
self.action = None
|
||||
|
||||
form = self.form_class(request.POST, instance=self.object)
|
||||
if not form.is_valid():
|
||||
print(form.errors)
|
||||
context = self.get_context_data(form=form)
|
||||
return render(request, self.template_name, context=context)
|
||||
|
||||
form.save()
|
||||
messages.success(self.request, self.get_success_message())
|
||||
return redirect(self.success_url)
|
||||
|
||||
|
||||
class TermsConditionView(LoginRequiredMixin, generic.DetailView):
|
||||
page_name = None
|
||||
resource = None
|
||||
action = None
|
||||
template_name = "module_cms/terms_and_condition_view.html"
|
||||
model = Organization
|
||||
context_object_name = "organization"
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.model.objects.only("terms_condition").first()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_name"] = self.page_name
|
||||
return context
|
||||
|
||||
|
||||
class TermsConditionCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
||||
# Set the page_name and resource
|
||||
page_name = None
|
||||
resource = None
|
||||
|
||||
# Initialize the action as ACTION_CREATE (can change based on logic)
|
||||
action = None # Default action
|
||||
|
||||
template_name = "module_cms/terms_and_condition_edit.html"
|
||||
model = Organization
|
||||
form_class = TermsAndConditionForm
|
||||
success_url = reverse_lazy("module_cms:terms_and_condition")
|
||||
error_message = "An error occurred while saving the data."
|
||||
|
||||
# Determine the success message dynamically based on whether it's an update or create
|
||||
def get_success_message(self):
|
||||
self.success_message = (
|
||||
constants.RECORD_CREATED if not self.object else constants.RECORD_UPDATED
|
||||
)
|
||||
return self.success_message
|
||||
|
||||
# Get the object (if exists) based on URL parameter 'pk'
|
||||
def get_object(self):
|
||||
return self.model.objects.only("terms_condition").first()
|
||||
|
||||
# Add page_name and operation to the context
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
"page_name": self.page_name,
|
||||
"operation": "Add" if not self.object else "Edit",
|
||||
}
|
||||
context.update(kwargs) # Include any additional context data passed to the view
|
||||
return context
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
# If an object is found, change action to ACTION_UPDATE
|
||||
# if self.object is not None:
|
||||
# self.action = resource_action.ACTION_UPDATE
|
||||
|
||||
form = self.form_class(instance=self.object)
|
||||
context = self.get_context_data(form=form)
|
||||
return render(request, self.template_name, context=context)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
# If an object is found, change action to ACTION_UPDATE
|
||||
# if self.object is not None:
|
||||
# self.action = resource_action.ACTION_UPDATE
|
||||
|
||||
form = self.form_class(request.POST, instance=self.object)
|
||||
if not form.is_valid():
|
||||
print(form.errors)
|
||||
context = self.get_context_data(form=form)
|
||||
return render(request, self.template_name, context=context)
|
||||
|
||||
form.save()
|
||||
messages.success(self.request, self.get_success_message())
|
||||
return redirect(self.success_url)
|
||||
|
||||
|
||||
class PrivacyPolicyView(LoginRequiredMixin, generic.DetailView):
|
||||
page_name = None
|
||||
resource = None
|
||||
action = None
|
||||
template_name = "module_cms/privacy_policy_view.html"
|
||||
model = Organization
|
||||
context_object_name = "organization"
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.model.objects.only("privacy_policy").first()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_name"] = self.page_name
|
||||
return context
|
||||
|
||||
|
||||
class PrivacyPolicyCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
||||
# Set the page_name and resource
|
||||
page_name = None
|
||||
resource = None
|
||||
|
||||
# Initialize the action as ACTION_CREATE (can change based on logic)
|
||||
action = None # Default action
|
||||
|
||||
template_name = "module_cms/privacy_policy_edit.html"
|
||||
model = Organization
|
||||
form_class = PrivacyPolicyForm
|
||||
success_url = reverse_lazy("module_cms:privacy_policy")
|
||||
error_message = "An error occurred while saving the data."
|
||||
|
||||
# Determine the success message dynamically based on whether it's an update or create
|
||||
def get_success_message(self):
|
||||
self.success_message = (
|
||||
constants.RECORD_CREATED if not self.object else constants.RECORD_UPDATED
|
||||
)
|
||||
return self.success_message
|
||||
|
||||
# Get the object (if exists) based on URL parameter 'pk'
|
||||
def get_object(self):
|
||||
return self.model.objects.only("privacy_policy").first()
|
||||
|
||||
# Add page_name and operation to the context
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
"page_name": self.page_name,
|
||||
"operation": "Add" if not self.object else "Edit",
|
||||
}
|
||||
context.update(kwargs) # Include any additional context data passed to the view
|
||||
return context
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
# If an object is found, change action to ACTION_UPDATE
|
||||
if self.object is not None:
|
||||
self.action = None
|
||||
|
||||
form = self.form_class(instance=self.object)
|
||||
context = self.get_context_data(form=form)
|
||||
return render(request, self.template_name, context=context)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
# If an object is found, change action to ACTION_UPDATE
|
||||
if self.object is not None:
|
||||
self.action = None
|
||||
|
||||
form = self.form_class(request.POST, instance=self.object)
|
||||
if not form.is_valid():
|
||||
print(form.errors)
|
||||
context = self.get_context_data(form=form)
|
||||
return render(request, self.template_name, context=context)
|
||||
form.save()
|
||||
messages.success(self.request, self.get_success_message())
|
||||
return redirect(self.success_url)
|
||||
Reference in New Issue
Block a user