feat(contact us): landing page contact support through email

This commit is contained in:
bobbyvish
2024-05-16 17:49:59 +05:30
parent e4ee75c7ee
commit bbc01addda
7 changed files with 193 additions and 3 deletions

View File

@@ -12,12 +12,14 @@ urlpatterns = [
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('contact_us/landing/', views.ContactUsLandingView, name="contact_us_landing"),
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'),
]

View File

@@ -1,3 +1,4 @@
import datetime
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
@@ -127,6 +128,66 @@ class ContactUsReplyView(LoginRequiredMixin, generic.View):
else:
return JsonResponseUtil.error(message=constants.FAILURE, errors="Missing 'id' or 'message' in the request")
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def ContactUsLandingView(request):
name = request.POST.get('full_name')
email = request.POST.get('email')
subject = request.POST.get('subject')
message = request.POST.get('message')
if not all([name, email, subject, message]):
return JsonResponseUtil.error(message=constants.FAILURE, errors='Please fill in all the fields.')
try:
contact_us = ContactUs(
name=name,
email_address=email,
subject=subject,
message=message
)
contact_us.save()
context = {
"name": name,
"email": email,
"subject": subject,
"message": message,
"year": datetime.datetime.year
}
print(context)
# Send the email to support team
support_team_service = EmailService(
subject=f"New contact us - {subject}",
to=email,
from_email=settings.EMAIL_HOST_USER,
)
support_team_service.load_template(
"module_support/contact_us_support.html", context=context
)
support_team_service.send()
# Send the email to support team
thankyou_service = EmailService(
subject=f"New contact us - {subject}",
to=email,
from_email=settings.EMAIL_HOST_USER,
)
thankyou_service.load_template(
"module_support/thank_you_support.html", context=context
)
thankyou_service.send()
except Exception as e:
print(f"Error occur in ContactUsLandingView {str(e)}")
return JsonResponseUtil.error(message=constants.FAILURE, errors=constants.SOMETHING_WRONG)
return JsonResponseUtil.success(message='Thank you for contacting us!')
class FeedbackView(permission.ResourcePermissionRequiredMixin, LoginRequiredMixin, generic.TemplateView):
page_name = iam_constant.RESOURCE_MANAGE_FEEDBACK