Esempio n. 1
0
def maketing_pref_update_receiver(sender, instance, *args, **kwargs):
    if instance.subscribed != instance.mailchimp_subscribed:
        if instance.subscribed:
            response_data = Mailchimp().subscribe(instance.user.email)
        else:
            response_data = Mailchimp().unsubscribe(instance.user.email)

        if response_data:
            if response_data['status'] == 'subscribed':
                instance.subscribed = True
                instance.mailchimp_subscribed = True
                instance.mailchimp_msg = response_data
            else:
                instance.subscribed = False
                instance.mailchimp_subscribed = False
                instance.mailchimp_msg = response_data
def info(request):
    info = Contact_Info.objects.all()
    if 'submit_footer_subscribe' in request.POST:
        subscribe_email = request.POST.get('eamil_subscribe', None)
        if len(subscribe_email) != 0:
            email = Marketing.objects.filter(
                user__email=subscribe_email).first()
            if email is not None:
                if subscribe_email != email.user.email:
                    guest_email, guset_created = GuestMarketing.objects.get_or_create(
                        guest_email=subscribe_email)
                    if guset_created:
                        Mailchimp().add_email(subscribe_email)
                        messages.success(request, 'ایمیل شما با موفقیت ثبت شد')
                else:
                    messages.error(request, 'ایمیل شما قبلا ثبت شده است')
            else:
                guest_email, guset_created = GuestMarketing.objects.get_or_create(
                    guest_email=subscribe_email)
                if guset_created:
                    Mailchimp().add_email(subscribe_email)
                    messages.success(request, 'ایمیل شما با موفقیت ثبت شد')
                else:
                    messages.error(request, 'ایمیل شما قبلا ثبت شده است')

    context = {
        'info': info.first(),
    }

    all_users = User.objects.all()
    for user in all_users:
        active_registers, expired_registers = Register.objects.get_user_registers(
            user)
        for i in expired_registers:
            i.is_expired = True
            i.save()

    if request.user.is_authenticated:
        cart_obj, new_obj = Cart.objects.new_or_get(request.user)
        cart_count = cart_obj.selected_class.count(
        ) + cart_obj.online_selected_class.count()
        context.update({'cart_count': cart_count})

    return (context)
Esempio n. 3
0
 def post(self, request, *args, **kwargs):
     data = request.POST
     list_id = data.get('data[list_id]')
     if str(list_id) == str(MAILCHIMP_EMAIL_LIST_ID):
         hook_type = data.get('type')
         email = data.get('data[email]')
         response = sub_status = Mailchimp.check_subscription_status(email)
         sub_status = response['status']
         is_subbed = None
         mailchimp_subbed = None
         if sub_status == 'subscribed':
             is_subbed, mailchimp_subbed = (True, True)
         elif sub_status == 'unsubscribed':
             is_subbed, mailchimp_subbed = (False, False)
         if is_subbed is not None and mailchimp_subbed is not None:
             qs = MarketingPreference.objects.filter(
                 user__email__iexact=email)
             if qs.exists:
                 qs.update(subscribed=False,
                           mailchimp_subscribed=False,
                           mailchimp_msg=str(data))
     return HttpResponse("Thank you", status=200)
Esempio n. 4
0
def marketing_pref_create_receiver(sender, instance, created, *args, **kwargs):
    if created:
        status_code, response_data = Mailchimp().subscribe(instance.user.email)
        print(status_code, response_data)