Added all the functionality of app and admin
This commit is contained in:
0
module_support/forms.py
Normal file
0
module_support/forms.py
Normal file
@@ -1,11 +1,20 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = "manage_support"
|
||||
app_name = "module_support"
|
||||
|
||||
urlpatterns = [
|
||||
# path('contact_us/', views.ContactUsListView.as_view(), name='contact_us_list'),
|
||||
# path('contact_us/reply/', views.ContactUsReplyView.as_view(), name='contact_us_reply'),
|
||||
|
||||
path('contact_us/', views.ContactUsView.as_view(), name="contact_us"),
|
||||
path('contact_us/list/', views.ContactUsListJson.as_view(), name="contact_us_list"),
|
||||
path('contact_us/reply/<int:id>/', views.ContactUsReplyView.as_view(), name='contact_us_reply'),
|
||||
path('contact_us/action/', views.ContactUsActionView.as_view(), name='contact_us_action'),
|
||||
path('contact_us/archive/list/', views.ContactUsArchiveView.as_view(), name='contact_us_archive'),
|
||||
|
||||
path('feedback/', views.FeedbackView.as_view(), name="feedback"),
|
||||
path('feedback/list/', views.FeedbackListJson.as_view(), name="feedback_list"),
|
||||
path('feedback/action/', views.FeedbackActionView.as_view(), name='feedback_action'),
|
||||
|
||||
|
||||
# path('feedback/', views.FeedbackListView.as_view(), name='feedback_list'),
|
||||
# path('feedback/delete/<int:pk>', views.FeedbackDeleteView.as_view(), name='feedback_delete'),
|
||||
|
||||
@@ -1,3 +1,152 @@
|
||||
from django.conf import settings
|
||||
from django.shortcuts import render
|
||||
|
||||
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 module_iam import iam_constant
|
||||
from module_project.service import EmailService
|
||||
from .models import ContactUs, Feedback
|
||||
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
|
||||
from module_project.utils import JsonResponseUtil
|
||||
# Create your views here.
|
||||
|
||||
|
||||
class ContactUsView(LoginRequiredMixin, generic.TemplateView):
|
||||
page_name = iam_constant.RESOURCE_MANAGE_CONTACT_US
|
||||
resource = None
|
||||
action = None
|
||||
template_name = "module_support/contact_us.html"
|
||||
model = ContactUs
|
||||
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 ContactUsListJson(BaseDatatableView):
|
||||
model = ContactUs
|
||||
columns = ["id", "email_address", "subject", "message", "active", "deleted"]
|
||||
order_columns = ["id", "email_address", "subject", "message", "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}")
|
||||
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 ContactUsActionView(ActionMixin):
|
||||
model = ContactUs
|
||||
|
||||
class ContactUsArchiveView(LoginRequiredMixin, generic.TemplateView):
|
||||
page_name = iam_constant.RESOURCE_MANAGE_CONTACT_US
|
||||
resource = None
|
||||
action = None
|
||||
template_name = "module_support/contactus_archive_list.html"
|
||||
model = ContactUs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_name"] = self.page_name
|
||||
return context
|
||||
|
||||
class ContactUsReplyView(LoginRequiredMixin, generic.View):
|
||||
page_name = iam_constant.RESOURCE_MANAGE_CONTACT_US
|
||||
model = ContactUs
|
||||
success_message = constants.DATA_SAVED
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
id = self.kwargs.get("id")
|
||||
message = request.POST.get("message")
|
||||
|
||||
if id or message:
|
||||
try:
|
||||
instance = self.model.objects.get(id=id)
|
||||
instance.reply = message
|
||||
instance.save()
|
||||
|
||||
email_service = EmailService(
|
||||
subject=f"Reply of your inquiry - {instance.subject}",
|
||||
body=message,
|
||||
to=instance.email,
|
||||
from_email=settings.EMAIL_HOST_USER,
|
||||
)
|
||||
email_service.send()
|
||||
JsonResponseUtil.success(message=self.success_message)
|
||||
except self.model.DoesNotExist:
|
||||
JsonResponseUtil.error(message=constants.FAILURE, errors="Invalid contact us ID.")
|
||||
except Exception as e:
|
||||
JsonResponseUtil.error(message=constants.FAILURE, errors=str(e))
|
||||
else:
|
||||
JsonResponseUtil.error(message=constants.FAILURE, errors="Missing 'id' or 'message' in the request")
|
||||
|
||||
# Redirect to the desired URL after form submission
|
||||
return JsonResponseUtil.success(message=constants.SUCCESS)
|
||||
|
||||
|
||||
class FeedbackView(LoginRequiredMixin, generic.TemplateView):
|
||||
page_name = iam_constant.RESOURCE_MANAGE_FEEDBACK
|
||||
resource = iam_constant.RESOURCE_MANAGE_FEEDBACK
|
||||
action = None
|
||||
template_name = "module_support/feedback.html"
|
||||
model = Feedback
|
||||
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 FeedbackListJson(BaseDatatableView):
|
||||
model = Feedback
|
||||
columns = ["id", "principal.email", "feedback_reaction", "comment", "active"]
|
||||
order_columns = ["id", "principal.email", "feedback_reaction", "comment", "active"]
|
||||
|
||||
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}")
|
||||
search_value = self.request.GET.get("search[value]", None)
|
||||
if search_value:
|
||||
qs = qs.filter(
|
||||
Q(id__icontains=search_value)
|
||||
| Q(feedback_reaction__icontains=search_value)
|
||||
| Q(comment__icontains=search_value)
|
||||
)
|
||||
return qs
|
||||
|
||||
|
||||
class FeedbackActionView(ActionMixin):
|
||||
model = Feedback
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user