From bec8f9d6082e855ae44eb1ab6c17f982070c6b6d Mon Sep 17 00:00:00 2001 From: bobbyvish Date: Wed, 8 Jan 2025 12:37:07 +0530 Subject: [PATCH] Update(Customer): added profile photo field --- accounts/forms.py | 2 + accounts/views.py | 24 +- goodtimes/urls.py | 10 +- manage_events/api/serializers.py | 1 + manage_events/forms.py | 1 + templates/accounts/customer/customer_add.html | 389 +++++++++++------- .../accounts/customer/customer_edit.html | 83 +++- .../accounts/customer/customer_list.html | 12 +- templates/manage_events/event_add.html | 23 +- 9 files changed, 370 insertions(+), 175 deletions(-) diff --git a/accounts/forms.py b/accounts/forms.py index 001fed5..9f07e76 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -362,6 +362,7 @@ class IAmPrincipalResourceLinkForm(IAmPrincipalForm): class CreateCustomerForm(forms.Form): + profile_photo = forms.ImageField(label="Profile Image", widget=forms.ClearableFileInput(attrs={'class': 'filepond'}),) first_name = forms.CharField(max_length=255, required=True, label='First Name') last_name = forms.CharField(max_length=255, required=True, label='Last Name') business_name = forms.CharField(max_length=200, required=True, label="Business Name") @@ -402,6 +403,7 @@ class CreateCustomerForm(forms.Form): self.fields['preferences'].queryset = EventCategory.objects.all() class UpdateCustomerForm(forms.Form): + profile_photo = forms.ImageField(label="Profile Image") first_name = forms.CharField(max_length=255, required=True, label='First Name') last_name = forms.CharField(max_length=255, required=True, label='Last Name') business_name = forms.CharField(max_length=200, required=True, label="Business Name") diff --git a/accounts/views.py b/accounts/views.py index 3463ec2..c4052f2 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -608,7 +608,7 @@ class CustomerCreateView(LoginRequiredMixin, generic.View): def post(self, request, *args, **kwargs): print(request.POST) # return redirect(self.success_url) - form = self.form_class(request.POST) + form = self.form_class(request.POST, request.FILES) context = self.get_context_data(form=form) if not form.is_valid(): return render(request, self.template_name, context=context) @@ -629,6 +629,7 @@ class CustomerCreateView(LoginRequiredMixin, generic.View): # save principal data principal_obj = IAmPrincipal.objects.create( + profile_photo = form.cleaned_data.get("profile_photo"), email=form.cleaned_data.get('email'), first_name=form.cleaned_data.get('first_name'), last_name=form.cleaned_data.get('last_name'), @@ -710,6 +711,7 @@ class CustomerUpdateView(LoginRequiredMixin, generic.View): print(f"principal address is {principal_obj.address_line1}") initial_data = { + "profile_photo": principal_obj.profile_photo, "first_name": principal_obj.first_name, "last_name": principal_obj.last_name, "email": principal_obj.email, @@ -752,13 +754,15 @@ class CustomerUpdateView(LoginRequiredMixin, generic.View): except Exception as e: messages.error(request, f"No Record of customer id {principal_id} is found") return redirect(self.success_url) - form = self.form_class(request.POST) + form = self.form_class(request.POST, request.FILES) + print(request.POST) if not form.is_valid(): context = self.get_context_data(form=form) return render(request, self.template_name, context=context) try: with transaction.atomic(): # update principal data + principal_obj.profile_photo = form.cleaned_data.get('profile_photo') principal_obj.first_name = form.cleaned_data.get('first_name') principal_obj.last_name = form.cleaned_data.get('last_name') principal_obj.business_name = form.cleaned_data.get("business_name") @@ -1049,17 +1053,23 @@ class CustomerTransferView(LoginRequiredMixin, generic.View): # Send the email try: - temp_password = "GoodTimes@2025" + principal_preference = IAmPrincipalExtendedData.objects.get(principal=principal_obj) + + # Use Encryptor to decrypt the password + encryptor = Encryptor() + temp_password = encryptor.decrypt(principal_preference.encrypted_pass) + + # updating password principal_obj.password = make_password(temp_password) principal_obj.save() + + principal_preference.is_transferred = True + principal_preference.save() + email_service.load_template( "accounts/customer/account_transfer_email_template.html", locals() ) email_service.send() - - principal_preference = IAmPrincipalExtendedData.objects.get(principal=principal_obj) - principal_preference.is_transferred = True - principal_preference.save() messages.success(request, "Account Transfer mail send successfully") except Exception as e: messages.error(request, f"{str(e)}") diff --git a/goodtimes/urls.py b/goodtimes/urls.py index c31e7f0..f1cc9b8 100644 --- a/goodtimes/urls.py +++ b/goodtimes/urls.py @@ -63,9 +63,9 @@ urlpatterns = [ # path('api/', include("accounts.api.urls")), ] -# if settings.DEBUG: -# import debug_toolbar +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +if settings.DEBUG: + import debug_toolbar -# urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -# urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) -# urlpatterns += [path("__debug__/", include(debug_toolbar.urls))] + urlpatterns += [path("__debug__/", include(debug_toolbar.urls))] diff --git a/manage_events/api/serializers.py b/manage_events/api/serializers.py index d16492b..f6c15ea 100644 --- a/manage_events/api/serializers.py +++ b/manage_events/api/serializers.py @@ -99,6 +99,7 @@ class EventListSerializer(serializers.ModelSerializer): "entry_fee", "key_guest", "age_group", + "link", # "images", # "is_favorited", # "reviews", diff --git a/manage_events/forms.py b/manage_events/forms.py index c17ecfd..070f1cd 100644 --- a/manage_events/forms.py +++ b/manage_events/forms.py @@ -46,6 +46,7 @@ class EventForm(forms.ModelForm): "title", # "event_master", "description", + "link", "image", "event_images", # "status", diff --git a/templates/accounts/customer/customer_add.html b/templates/accounts/customer/customer_add.html index 4c30dc8..d147cf1 100644 --- a/templates/accounts/customer/customer_add.html +++ b/templates/accounts/customer/customer_add.html @@ -1,9 +1,30 @@ {% extends 'layout/base_template.html' %} {% load static %} {% block stylesheet %} - - - {% include "cdn_through_html/flatpicker_cdn_css.html" %} + + +{% include "cdn_through_html/flatpicker_cdn_css.html" %} +{% include "cdn_through_html/filepond_cdn_css.html" %} + + + {% endblock %} {% block content %} @@ -12,10 +33,12 @@
@@ -24,14 +47,15 @@
-
+ {% csrf_token %} {% include 'includes/dynamic_template_form.html' with form=form %}
-
+
- +
@@ -43,155 +67,216 @@ {% endblock content %} {% block javascript %} - - {% include "cdn_through_html/flatpicker_cdn_js.html" %} - {% include "cdn_through_html/jquery_validate_cdn_js.html" %} - - +{% include "cdn_through_html/filepond_cdn_js.html" %} +{% include "cdn_through_html/flatpicker_cdn_js.html" %} +{% include "cdn_through_html/jquery_validate_cdn_js.html" %} + + - + // Trigger validation for flatpickr fields on change + $('#id_free_start_date').on('change', function () { + $(this).valid(); + }); + $('#id_free_end_date').on('change', function () { + $(this).valid(); + }); + }) + {% endblock %} \ No newline at end of file diff --git a/templates/accounts/customer/customer_edit.html b/templates/accounts/customer/customer_edit.html index 7a45364..a764f5e 100644 --- a/templates/accounts/customer/customer_edit.html +++ b/templates/accounts/customer/customer_edit.html @@ -4,6 +4,26 @@ {% include "cdn_through_html/flatpicker_cdn_css.html" %} + {% include "cdn_through_html/filepond_cdn_css.html" %} + + {% endblock %} {% block content %} @@ -33,7 +53,7 @@
-
+ {% csrf_token %} {% include 'includes/dynamic_template_form.html' with form=form %}
@@ -53,12 +73,73 @@ {% block javascript %} + {% include "cdn_through_html/filepond_cdn_js.html" %} {% include "cdn_through_html/flatpicker_cdn_js.html" %} {% include "cdn_through_html/jquery_validate_cdn_js.html" %}