|
|
|
|
@@ -7,11 +7,12 @@ 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 module_iam import iam_constant
|
|
|
|
|
from .forms import AboutUsForm, TermsAndConditionForm, FaqsForm, 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.mixins import ActionMixin
|
|
|
|
|
|
|
|
|
|
from module_project import constants
|
|
|
|
|
|
|
|
|
|
@@ -19,7 +20,7 @@ logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FaqView(LoginRequiredMixin, generic.TemplateView):
|
|
|
|
|
page_name = None
|
|
|
|
|
page_name = iam_constant.RESOURCE_MANAGE_FAQS
|
|
|
|
|
resource = None
|
|
|
|
|
action = None
|
|
|
|
|
template_name = "module_cms/faq.html"
|
|
|
|
|
@@ -32,43 +33,16 @@ class FaqView(LoginRequiredMixin, generic.TemplateView):
|
|
|
|
|
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 get_initial_queryset(self):
|
|
|
|
|
deleted_flag = self.request.GET.get('deleted_flag', None)
|
|
|
|
|
|
|
|
|
|
return self.model.objects.filter(deleted=deleted_flag)
|
|
|
|
|
|
|
|
|
|
def filter_queryset(self, qs):
|
|
|
|
|
# Implement your custom filtering logic here
|
|
|
|
|
print(f"request is {self.request.GET}")
|
|
|
|
|
@@ -88,14 +62,75 @@ class FaqListJson(BaseDatatableView):
|
|
|
|
|
return qs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FaqCreateOrUpdateView(generic.View):
|
|
|
|
|
pass
|
|
|
|
|
class FaqCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
|
|
|
|
# Set the page_name and resource
|
|
|
|
|
page_name = iam_constant.RESOURCE_MANAGE_FAQS
|
|
|
|
|
resource = iam_constant.RESOURCE_MANAGE_FAQS
|
|
|
|
|
|
|
|
|
|
# Initialize the action as ACTION_CREATE (can change based on logic)
|
|
|
|
|
action = iam_constant.ACTION_CREATE # Default action
|
|
|
|
|
|
|
|
|
|
template_name = "module_cms/faq_add.html"
|
|
|
|
|
model = Faqs
|
|
|
|
|
form_class = FaqsForm
|
|
|
|
|
success_url = reverse_lazy("module_cms:faq")
|
|
|
|
|
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):
|
|
|
|
|
pk = self.kwargs.get("pk")
|
|
|
|
|
return get_object_or_404(self.model, pk=pk) if pk else None
|
|
|
|
|
|
|
|
|
|
# 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 = iam_constant.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):
|
|
|
|
|
print("Request data: ", request.POST)
|
|
|
|
|
self.object = self.get_object()
|
|
|
|
|
|
|
|
|
|
# If an object is found, change action to ACTION_UPDATE
|
|
|
|
|
if self.object is not None:
|
|
|
|
|
self.action = iam_constant.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 FaqActionView(ActionMixin):
|
|
|
|
|
model = Faqs
|
|
|
|
|
|
|
|
|
|
class AboutUsView(LoginRequiredMixin, generic.DetailView):
|
|
|
|
|
page_name = None
|
|
|
|
|
page_name = iam_constant.RESOURCE_MANAGE_CMS
|
|
|
|
|
template_name = "module_cms/about_us_view.html"
|
|
|
|
|
model = Organization
|
|
|
|
|
context_object_name = "organization"
|
|
|
|
|
@@ -111,7 +146,7 @@ class AboutUsView(LoginRequiredMixin, generic.DetailView):
|
|
|
|
|
|
|
|
|
|
class AboutUsCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
|
|
|
|
# Set the page_name and resource
|
|
|
|
|
page_name = None
|
|
|
|
|
page_name = iam_constant.RESOURCE_MANAGE_CMS
|
|
|
|
|
resource = None
|
|
|
|
|
|
|
|
|
|
# Initialize the action as ACTION_CREATE (can change based on logic)
|
|
|
|
|
@@ -173,7 +208,7 @@ class AboutUsCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TermsConditionView(LoginRequiredMixin, generic.DetailView):
|
|
|
|
|
page_name = None
|
|
|
|
|
page_name = iam_constant.RESOURCE_MANAGE_T_C
|
|
|
|
|
resource = None
|
|
|
|
|
action = None
|
|
|
|
|
template_name = "module_cms/terms_and_condition_view.html"
|
|
|
|
|
@@ -191,7 +226,7 @@ class TermsConditionView(LoginRequiredMixin, generic.DetailView):
|
|
|
|
|
|
|
|
|
|
class TermsConditionCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
|
|
|
|
# Set the page_name and resource
|
|
|
|
|
page_name = None
|
|
|
|
|
page_name = iam_constant.RESOURCE_MANAGE_T_C
|
|
|
|
|
resource = None
|
|
|
|
|
|
|
|
|
|
# Initialize the action as ACTION_CREATE (can change based on logic)
|
|
|
|
|
@@ -253,7 +288,7 @@ class TermsConditionCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PrivacyPolicyView(LoginRequiredMixin, generic.DetailView):
|
|
|
|
|
page_name = None
|
|
|
|
|
page_name = iam_constant.RESOURCE_MANAGE_PRIVACYPOLICY
|
|
|
|
|
resource = None
|
|
|
|
|
action = None
|
|
|
|
|
template_name = "module_cms/privacy_policy_view.html"
|
|
|
|
|
@@ -271,7 +306,7 @@ class PrivacyPolicyView(LoginRequiredMixin, generic.DetailView):
|
|
|
|
|
|
|
|
|
|
class PrivacyPolicyCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
|
|
|
|
# Set the page_name and resource
|
|
|
|
|
page_name = None
|
|
|
|
|
page_name = iam_constant.RESOURCE_MANAGE_PRIVACYPOLICY
|
|
|
|
|
resource = None
|
|
|
|
|
|
|
|
|
|
# Initialize the action as ACTION_CREATE (can change based on logic)
|
|
|
|
|
|