Added all the functionality of app and admin

This commit is contained in:
bobbyvish
2024-03-11 14:48:48 +05:30
parent 69dbc56374
commit fd4aef5a40
92 changed files with 8931 additions and 716 deletions

View File

@@ -7,11 +7,6 @@ class FaqSerializer(serializers.ModelSerializer):
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)

View File

@@ -19,8 +19,8 @@ class FaqListAPIView(APIView):
return ApiResponse.success(message=constants.SUCCESS, data=serializer.data)
class OrganizationAPIView(APIView):
authentication_classes = [JWTAuthentication]
permission_classes = [IsAuthenticated]
authentication_classes = []
permission_classes = []
serializer_class = OrganizationSerializer
model = Organization

View File

@@ -68,16 +68,4 @@ class FaqsForm(forms.ModelForm):
# "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")

View File

@@ -7,6 +7,8 @@ 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('faq/edit/<int:pk>/', views.FaqCreateOrUpdateView.as_view(), name='faq_edit'),
path('faq/action/', views.FaqActionView.as_view(), name='faq_action'),
path('about-us/', views.AboutUsView.as_view(), name='about_us'),
path('about-us/edit/', views.AboutUsCreateOrUpdateView.as_view(), name='about_us_add'),

View File

@@ -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)