Exemplo n.º 1
0
Arquivo: fb.py Projeto: daasara/riba
def subscription_phone_verification(request):
    if request.method == "POST":
        data = request.GET
        verification_code = data.get('transaction_token', None)
        if verification_code:
            try:
                subscription = Subscription.objects.get(verification_code=verification_code, verified_on=None)
                phone = subscription.contact
                subscription.verified_on = datetime.now()
                subscription.save()
                # Send deal subscription confirmation sms
                utils.subscribe_send_sms(phone)
                log.info("phone number %s verified by zip dial" % phone)
            except Subscription.DoesNotExist:
                log.info("===ZIP DIAL VERIFICATION=== subscription does not exist")
        else:
            log.info("===ZIP DIAL VERIFICATION== zip dial url has no transaction_token")
    return HttpResponse('')
Exemplo n.º 2
0
def subscription_phone_verification(request):
    if request.method == "POST":
        data = request.GET
        verification_code = data.get("transaction_token", None)
        if verification_code:
            try:
                subscription = Subscription.objects.get(verification_code=verification_code, verified_on=None)
                phone = subscription.contact
                subscription.verified_on = datetime.now()
                subscription.save()
                # Send deal subscription confirmation sms
                utils.subscribe_send_sms(phone)
                log.info("phone number %s verified by zip dial" % phone)
            except Subscription.DoesNotExist:
                log.info("===ZIP DIAL VERIFICATION=== subscription does not exist")
        else:
            log.info("===ZIP DIAL VERIFICATION== zip dial url has no transaction_token")
    return HttpResponse("")
Exemplo n.º 3
0
def register_for_deals(request):
    form = FBRegisterForm()
    if request.method == "POST":
        form = FBRegisterForm(request.POST)
        error = ""
        if form.is_valid():
            f = form.cleaned_data
            email_id = f["email"]
            mobile_no = f["mobile"]

            user_info = get_user_by_email_or_mobile(email_id, mobile_no)
            email_user, phone_user, email_alert_on, sms_alert_on = user_info

            if not email_user and not phone_user:
                # new user
                user = User.objects.create_user(email_id, email_id, None)
                user.first_name = f["name"]
                user.save()

                profile = Profile(user=user, full_name=user.first_name)
                profile.save()

                email = UserEmail(user=profile, type="primary", email=email_id)
                email.save()
                email_alert_on = email
                phone = Phone(user=profile, type="primary", phone=mobile_no)
                phone.save()
                sms_alert_on = phone

            if not email_user and phone_user:
                # user with phone number already exist, update his email address only
                email = UserEmail(user=phone_user, type="primary", email=email_id)
                email.save()
                email_alert_on = email

            if not phone_user and email_user:
                # user with email already exist, update his phone number only
                phone = Phone(user=email_user, type="primary", phone=mobile_no)
                phone.save()
                sms_alert_on = phone
            if f["name"]:
                u_name = f["name"][0].upper() + f["name"][1:]
            else:
                u_name = None
            utils.subscribe_send_email(request, email_id, u_name)
            utils.subscribe_send_sms(mobile_no)
            try:
                newsletter = NewsLetter.objects.get(newsletter="DailyDeals", client=request.client.client)
                existing_subscription = DailySubscription.objects.filter(
                    newsletter=newsletter, sms_alert_on=sms_alert_on, email_alert_on=email_alert_on
                )
                if existing_subscription:
                    return HttpResponse(simplejson.dumps(dict(status="ok", msg="subscribed")))
                else:
                    subscribe = DailySubscription()
                    subscribe.newsletter = newsletter
                    subscribe.sms_alert_on = sms_alert_on
                    subscribe.email_alert_on = email_alert_on
                    subscribe.save()
                    return HttpResponse(simplejson.dumps(dict(status="ok", msg="subscribed")))
            except NewsLetter.DoesNotExist:
                return HttpResponse(simplejson.dumps(dict(status="ok", msg="newsletter does not exists")))

        else:
            errors = []
            # we are restricting to on error per field.
            for e in form["email"].errors[:1]:
                errors.append(e)
            for e in form["mobile"].errors[:1]:
                errors.append(e)
            return HttpResponse(simplejson.dumps(dict(status="failed", error=errors)))

    return render_to_response("fb/popup.html", {"form": form}, context_instance=RequestContext(request))
Exemplo n.º 4
0
def daily_deals_registration(request):
    form = FBRegisterForm()
    valid = False
    if request.method == "POST":
        form = FBRegisterForm(request.POST)
        error = ""
        if form.is_valid():
            valid = True
            f = form.cleaned_data
            email_id = f["email"]
            mobile_no = f["mobile"]

            user_info = get_user_by_email_or_mobile(email_id, mobile_no)
            email_user, phone_user, email_alert_on, sms_alert_on = user_info

            if not email_user and not phone_user:
                # new user
                user = User.objects.create_user(email_id, email_id, None)
                user.first_name = f["name"]
                user.save()

                profile = Profile(user=user, full_name=user.first_name)
                profile.save()

                email = UserEmail(user=profile, type="primary", email=email_id)
                email.save()
                email_alert_on = email
                phone = Phone(user=profile, type="primary", phone=mobile_no)
                phone.save()
                sms_alert_on = phone

            if not email_user and phone_user:
                # user with phone number already exist, update his email address only
                email = UserEmail(user=phone_user, type="primary", email=email_id)
                email.save()
                email_alert_on = email

            if not phone_user and email_user:
                # user with email already exist, update his phone number only
                phone = Phone(user=email_user, type="primary", phone=mobile_no)
                phone.save()
                sms_alert_on = phone
            if f["name"]:
                u_name = f["name"][0].upper() + f["name"][1:]
            else:
                u_name = None
            utils.subscribe_send_email(request, email_id, u_name)
            utils.subscribe_send_sms(mobile_no)
            try:
                newsletter = NewsLetter.objects.get(newsletter="DailyDeals", client=request.client.client)
                existing_subscription = DailySubscription.objects.filter(
                    newsletter=newsletter, sms_alert_on=sms_alert_on, email_alert_on=email_alert_on
                )
                if existing_subscription:
                    return render_to_response(
                        "fb/subscription_thankyou.html",
                        {"form": form, "valid": valid},
                        context_instance=RequestContext(request),
                    )
                else:
                    subscribe = DailySubscription()
                    subscribe.newsletter = newsletter
                    subscribe.sms_alert_on = sms_alert_on
                    subscribe.email_alert_on = email_alert_on
                    subscribe.save()
                    return render_to_response(
                        "fb/subscription_thankyou.html",
                        {"form": form, "valid": valid},
                        context_instance=RequestContext(request),
                    )
            except NewsLetter.DoesNotExist:
                return render_to_response(
                    "fb/subscription_thankyou.html",
                    {"form": form, "valid": valid},
                    context_instance=RequestContext(request),
                )

        else:
            valid = False
            return render_to_response(
                "fb/dailydeals_popup.html", {"form": form, "valid": valid}, context_instance=RequestContext(request)
            )

    return render_to_response(
        "fb/dailydeals_popup.html", {"form": form, "valid": valid}, context_instance=RequestContext(request)
    )
Exemplo n.º 5
0
Arquivo: fb.py Projeto: daasara/riba
def subscribe_email_link(request, alliance_name=None):
    form = FBRegisterForm()
    url = request.get_full_path()
    if not alliance_name:
        raise Http404
    else:
        affiliate_name = alliance_name.strip()
    try:
        affiliate_subscription = SubscriptionLink.objects.get(path='/'+affiliate_name)
    except:
        raise Http404
    affiliate = affiliate_subscription.affiliate
    affiliate_logo = affiliate.logo
    affiliate_text = affiliate.text
    newsletter = affiliate_subscription.newsletter
    do_post = True
    show_avail_coupon = affiliate.is_coupon_avail
    if affiliate_name == "afaqs":
        do_post = False
    errors = []
    welcome_html = 'fb/register_for_deals.html'
    special_offers = ['gift']
    if affiliate_name in special_offers:
        welcome_html = 'fb/register_for_special_offers.html'
    if request.method == 'POST':
        form = FBRegisterForm(request.POST)
        error=''
        already_subscribed = False
        if form.is_valid():
            f=form.cleaned_data
            email_id = f['email'].strip()
            mobile_no = f['mobile'].strip()
            name = f['name'].strip()
            email_user,phone_user,email_alert_on,sms_alert_on = get_user_by_email_or_mobile(email_id,mobile_no)
            html_page = 'fb/discount-%s.html' % affiliate_name

            is_valid = True
            _coupon = Voucher.objects.filter(affiliate= affiliate, status="active").order_by('id')
            text = 'your' 
            total_coupon_codes ={}
            if affiliate.is_coupon_avail:
                if _coupon:
                    _coupon = _coupon[0]
                    total_coupon_codes[affiliate_name] = _coupon.code
                else:
                    errors.append("Sorry!! Coupons are not available")
                    is_valid = False
                if affiliate_name == 'esc':
                    total_coupon_codes = assign_coupons(affiliate)
            if is_valid:
                if not email_user and not phone_user: #new user
                    user,profile = utils.get_or_create_user(email_id, email_id, None, name)

                    email = UserEmail.objects.get(user=profile,type='primary',email=email_id)
                    email_alert_on = email
                    phone = Phone(user=profile,type='primary',phone=mobile_no)
                    phone.save()
                    sms_alert_on = phone
                elif email_user and phone_user:
                    if phone_user == email_user:
                        is_valid = True
                    else:
                        errors.append('Email id and Phone are not registered for the same user.')
                        is_valid = False
                elif not email_user and phone_user: #user with phone number already exist, update his email address only
                    errors.append('Mobile number is already subscribed.')
                    is_valid = False
                elif not phone_user and email_user: #user with email already exist, update his phone number only
                    errors.append('Email address is already subscribed.')
                    is_valid = False
                
            if not is_valid:
                return render_to_response(welcome_html,
                    {
                        'form':form,
                        'affiliate_logo':affiliate_logo,
                        'affiliate_text':affiliate_text,
                        'affiliate_name':affiliate_name,
                        'do_post':do_post,
                        'errors':errors,
                    },context_instance = RequestContext(request))
            url = request.get_full_path()
            existing_subscription_email = DailySubscription.objects.filter(newsletter=newsletter,email_alert_on=email_alert_on,source = affiliate_name)
            existing_subscription_phone = DailySubscription.objects.filter(newsletter=newsletter,sms_alert_on=sms_alert_on,source = affiliate_name)
            if affiliate_name in ["vcomm",'affinity','tyroo']:
                existing_subscription_email = DailySubscription.objects.filter(email_alert_on=email_alert_on)
                existing_subscription_phone = None
            if not existing_subscription_email and not existing_subscription_phone:
                subscribe = DailySubscription()
                subscribe.newsletter = newsletter
                subscribe.sms_alert_on = sms_alert_on
                subscribe.email_alert_on = email_alert_on
                subscribe.source = affiliate_name
                subscribe.save()

                if request.POST.get("selected_affiliates","") == "selected_affiliates":

                    t_body = get_template('notifications/users/affiliates_afaqs.email')
                    email_body = {}
                    email_body['request'] = request
                    email_body['name'] = name
                    c_body = Context(email_body)
                    t_subject = get_template('notifications/users/subscribe_sub.email')
                    email_from = {}
                    email_subject = {}
                    c_subject = Context(email_subject)
                    mail_obj = EmailAddress()
                    if is_future_ecom(request.client.client):
                        mail_obj.isHtml = True
                    mail_obj._from = request.client.client.promotions_email
                    mail_obj.body = t_body.render(c_body)
                    mail_obj.subject = t_subject.render(c_subject)
                    u_emails = ""
                    email = str(email_id)
                    u_emails = email.strip(',')
                    mail_obj.to = u_emails
                    mail_obj.send()

                    utils.subscribe_send_sms(mobile_no)
                    return HttpResponseRedirect("/")
                
                if not affiliate.is_coupon_avail:
                    if affiliate_name in special_offers:
                        send_coupons_by_email(request, total_coupon_codes, affiliate_name, email_alert_on, show_avail_coupon)
                        send_coupons_by_sms(request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon)
                    else:
                        utils.subscribe_send_email(request,email_id, name)
                        utils.subscribe_send_sms(mobile_no)
                    return render_to_response('fb/thankyou-%s.html' % affiliate_name,{'email_id':email_id},context_instance = RequestContext(request))
                    
                if email_alert_on:
                    send_coupons_by_email(request, total_coupon_codes, affiliate_name, email_alert_on, show_avail_coupon)

                if sms_alert_on:
                    send_coupons_by_sms(request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon)

                if affiliate_name != 'esc': 
                    _coupon.status = "inactive"
                    _coupon.save()
            else:
                errors.append("You have already subscribed for the deal.")
                already_subscribed = True
                is_valid = False

            if affiliate_name in ["vcomm",'affinity','tyroo']:
                return render_to_response('fb/subscribed.html',
                    {'affiliate_name':affiliate_name,'already_subscribed':already_subscribed},
                    context_instance = RequestContext(request))
    
            if is_valid: 
                return render_to_response(html_page,
                    {'affiliate_name':affiliate_name,'coupon_codes':total_coupon_codes, 'already_subscribed':already_subscribed},
                    context_instance = RequestContext(request))
    return render_to_response(welcome_html,
        {
            'form':form,
            'affiliate_logo':affiliate_logo,
            'affiliate_text':affiliate_text,
            'affiliate_name':affiliate_name,
            'do_post':do_post,
            'errors':errors,
            'show_avail_coupon':show_avail_coupon,
        },
        context_instance = RequestContext(request))
Exemplo n.º 6
0
Arquivo: fb.py Projeto: daasara/riba
def daily_deals_registration(request):
    form = FBRegisterForm()
    valid=False
    if request.method == 'POST':
        form = FBRegisterForm(request.POST)
        error=''
        if form.is_valid():
            valid = True
            f=form.cleaned_data
            email_id = f['email'].strip()
            mobile_no = f['mobile'].strip()

            user_info = get_user_by_email_or_mobile(email_id, mobile_no)
            email_user, phone_user, email_alert_on, sms_alert_on = user_info

            if not email_user and not phone_user:
                #new user
                user = User.objects.create_user(email_id,email_id,None)
                user.first_name = f['name'].strip()
                user.save()

                profile = Profile(user=user,full_name=user.first_name)
                profile.save()

                email = UserEmail(user=profile,type='primary',email=email_id)
                email.save()
                email_alert_on = email
                phone = Phone(user=profile,type='primary',phone=mobile_no)
                phone.save()
                sms_alert_on = phone

            if not email_user and phone_user:
                # user with phone number already exist, update his email address only
                email = UserEmail(user=phone_user,type='primary',email=email_id)
                email.save()
                email_alert_on = email

            if not phone_user and email_user:
                # user with email already exist, update his phone number only
                phone = Phone(user=email_user,type='primary',phone=mobile_no)
                phone.save()
                sms_alert_on = phone
            if f['name']:
                u_name = f['name'][0].upper() + f['name'][1:]
            else:
                u_name = None
            utils.subscribe_send_email(request,email_id, u_name)
            utils.subscribe_send_sms(mobile_no)
            try:
                newsletter = NewsLetter.objects.get(newsletter='DailyDeals',client=request.client.client)
                existing_subscription = DailySubscription.objects.filter(newsletter=newsletter,sms_alert_on=sms_alert_on,email_alert_on=email_alert_on)
                if existing_subscription:
                    return render_to_response('fb/subscription_thankyou.html',
                            {'form':form,'valid':valid},
                            context_instance = RequestContext(request))
                else:
                    subscribe = DailySubscription()
                    subscribe.newsletter = newsletter
                    subscribe.sms_alert_on = sms_alert_on
                    subscribe.email_alert_on = email_alert_on
                    subscribe.save()
                    return render_to_response('fb/subscription_thankyou.html',
                            {'form':form,'valid':valid},
                            context_instance = RequestContext(request))
            except NewsLetter.DoesNotExist:
                return render_to_response('fb/subscription_thankyou.html',
                        {'form':form,'valid':valid},
                        context_instance = RequestContext(request))

        else:
            valid=False
            return render_to_response('fb/dailydeals_popup.html',
                    {'form':form,'valid':valid},
                    context_instance = RequestContext(request))

    return render_to_response('fb/dailydeals_popup.html',
            {'form':form,'valid':valid},
            context_instance = RequestContext(request))
Exemplo n.º 7
0
def subscribe_email_link(request, alliance_name=None):
    form = FBRegisterForm()
    url = request.get_full_path()
    if not alliance_name:
        raise Http404
    else:
        affiliate_name = alliance_name.strip()
    try:
        affiliate_subscription = SubscriptionLink.objects.get(path="/" + affiliate_name)
    except:
        raise Http404
    affiliate = affiliate_subscription.affiliate
    affiliate_logo = affiliate.logo
    affiliate_text = affiliate.text
    newsletter = affiliate_subscription.newsletter
    do_post = True
    show_avail_coupon = affiliate.is_coupon_avail
    if affiliate_name == "afaqs":
        do_post = False
    errors = []
    welcome_html = "fb/register_for_deals.html"
    special_offers = ["gift"]
    if affiliate_name in special_offers:
        welcome_html = "fb/register_for_special_offers.html"
    if request.method == "POST":
        form = FBRegisterForm(request.POST)
        error = ""
        already_subscribed = False
        if form.is_valid():
            f = form.cleaned_data
            email_id = f["email"].strip()
            mobile_no = f["mobile"].strip()
            name = f["name"].strip()
            email_user, phone_user, email_alert_on, sms_alert_on = get_user_by_email_or_mobile(email_id, mobile_no)
            html_page = "fb/discount-%s.html" % affiliate_name

            is_valid = True
            _coupon = Voucher.objects.filter(affiliate=affiliate, status="active").order_by("id")
            text = "your"
            total_coupon_codes = {}
            if affiliate.is_coupon_avail:
                if _coupon:
                    _coupon = _coupon[0]
                    total_coupon_codes[affiliate_name] = _coupon.code
                else:
                    errors.append("Sorry!! Coupons are not available")
                    is_valid = False
                if affiliate_name == "esc":
                    total_coupon_codes = assign_coupons(affiliate)
            if is_valid:
                if not email_user and not phone_user:  # new user
                    user, profile = utils.get_or_create_user(email_id, email_id, None, name)

                    email = UserEmail.objects.get(user=profile, type="primary", email=email_id)
                    email_alert_on = email
                    phone = Phone(user=profile, type="primary", phone=mobile_no)
                    phone.save()
                    sms_alert_on = phone
                elif email_user and phone_user:
                    if phone_user == email_user:
                        is_valid = True
                    else:
                        errors.append("Email id and Phone are not registered for the same user.")
                        is_valid = False
                elif (
                    not email_user and phone_user
                ):  # user with phone number already exist, update his email address only
                    errors.append("Mobile number is already subscribed.")
                    is_valid = False
                elif not phone_user and email_user:  # user with email already exist, update his phone number only
                    errors.append("Email address is already subscribed.")
                    is_valid = False

            if not is_valid:
                return render_to_response(
                    welcome_html,
                    {
                        "form": form,
                        "affiliate_logo": affiliate_logo,
                        "affiliate_text": affiliate_text,
                        "affiliate_name": affiliate_name,
                        "do_post": do_post,
                        "errors": errors,
                    },
                    context_instance=RequestContext(request),
                )
            url = request.get_full_path()
            existing_subscription_email = DailySubscription.objects.filter(
                newsletter=newsletter, email_alert_on=email_alert_on, source=affiliate_name
            )
            existing_subscription_phone = DailySubscription.objects.filter(
                newsletter=newsletter, sms_alert_on=sms_alert_on, source=affiliate_name
            )
            if affiliate_name in ["vcomm", "affinity", "tyroo"]:
                existing_subscription_email = DailySubscription.objects.filter(email_alert_on=email_alert_on)
                existing_subscription_phone = None
            if not existing_subscription_email and not existing_subscription_phone:
                subscribe = DailySubscription()
                subscribe.newsletter = newsletter
                subscribe.sms_alert_on = sms_alert_on
                subscribe.email_alert_on = email_alert_on
                subscribe.source = affiliate_name
                subscribe.save()

                if request.POST.get("selected_affiliates", "") == "selected_affiliates":

                    t_body = get_template("notifications/users/affiliates_afaqs.email")
                    email_body = {}
                    email_body["request"] = request
                    email_body["name"] = name
                    c_body = Context(email_body)
                    t_subject = get_template("notifications/users/subscribe_sub.email")
                    email_from = {}
                    email_subject = {}
                    c_subject = Context(email_subject)
                    mail_obj = EmailAddress()
                    if is_future_ecom(request.client.client):
                        mail_obj.isHtml = True
                    mail_obj._from = request.client.client.promotions_email
                    mail_obj.body = t_body.render(c_body)
                    mail_obj.subject = t_subject.render(c_subject)
                    u_emails = ""
                    email = str(email_id)
                    u_emails = email.strip(",")
                    mail_obj.to = u_emails
                    mail_obj.send()

                    utils.subscribe_send_sms(mobile_no)
                    return HttpResponseRedirect("/")

                if not affiliate.is_coupon_avail:
                    if affiliate_name in special_offers:
                        send_coupons_by_email(
                            request, total_coupon_codes, affiliate_name, email_alert_on, show_avail_coupon
                        )
                        send_coupons_by_sms(
                            request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon
                        )
                    else:
                        utils.subscribe_send_email(request, email_id, name)
                        utils.subscribe_send_sms(mobile_no)
                    return render_to_response(
                        "fb/thankyou-%s.html" % affiliate_name,
                        {"email_id": email_id},
                        context_instance=RequestContext(request),
                    )

                if email_alert_on:
                    send_coupons_by_email(
                        request, total_coupon_codes, affiliate_name, email_alert_on, show_avail_coupon
                    )

                if sms_alert_on:
                    send_coupons_by_sms(request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon)

                if affiliate_name != "esc":
                    _coupon.status = "inactive"
                    _coupon.save()
            else:
                errors.append("You have already subscribed for the deal.")
                already_subscribed = True
                is_valid = False

            if affiliate_name in ["vcomm", "affinity", "tyroo"]:
                return render_to_response(
                    "fb/subscribed.html",
                    {"affiliate_name": affiliate_name, "already_subscribed": already_subscribed},
                    context_instance=RequestContext(request),
                )

            if is_valid:
                return render_to_response(
                    html_page,
                    {
                        "affiliate_name": affiliate_name,
                        "coupon_codes": total_coupon_codes,
                        "already_subscribed": already_subscribed,
                    },
                    context_instance=RequestContext(request),
                )
    return render_to_response(
        welcome_html,
        {
            "form": form,
            "affiliate_logo": affiliate_logo,
            "affiliate_text": affiliate_text,
            "affiliate_name": affiliate_name,
            "do_post": do_post,
            "errors": errors,
            "show_avail_coupon": show_avail_coupon,
        },
        context_instance=RequestContext(request),
    )
Exemplo n.º 8
0
def register_for_deals(request):
    form = FBRegisterForm()
    if request.method == 'POST':
        form = FBRegisterForm(request.POST)
        error = ''
        if form.is_valid():
            f = form.cleaned_data
            email_id = f['email']
            mobile_no = f['mobile']

            user_info = get_user_by_email_or_mobile(email_id, mobile_no)
            email_user, phone_user, email_alert_on, sms_alert_on = user_info

            if not email_user and not phone_user:
                #new user
                user = User.objects.create_user(email_id, email_id, None)
                user.first_name = f['name']
                user.save()

                profile = Profile(user=user, full_name=user.first_name)
                profile.save()

                email = UserEmail(user=profile, type='primary', email=email_id)
                email.save()
                email_alert_on = email
                phone = Phone(user=profile, type='primary', phone=mobile_no)
                phone.save()
                sms_alert_on = phone

            if not email_user and phone_user:
                # user with phone number already exist, update his email address only
                email = UserEmail(user=phone_user,
                                  type='primary',
                                  email=email_id)
                email.save()
                email_alert_on = email

            if not phone_user and email_user:
                # user with email already exist, update his phone number only
                phone = Phone(user=email_user, type='primary', phone=mobile_no)
                phone.save()
                sms_alert_on = phone
            if f['name']:
                u_name = f['name'][0].upper() + f['name'][1:]
            else:
                u_name = None
            utils.subscribe_send_email(request, email_id, u_name)
            utils.subscribe_send_sms(mobile_no)
            try:
                newsletter = NewsLetter.objects.get(
                    newsletter='DailyDeals', client=request.client.client)
                existing_subscription = DailySubscription.objects.filter(
                    newsletter=newsletter,
                    sms_alert_on=sms_alert_on,
                    email_alert_on=email_alert_on)
                if existing_subscription:
                    return HttpResponse(
                        simplejson.dumps(dict(status='ok', msg='subscribed')))
                else:
                    subscribe = DailySubscription()
                    subscribe.newsletter = newsletter
                    subscribe.sms_alert_on = sms_alert_on
                    subscribe.email_alert_on = email_alert_on
                    subscribe.save()
                    return HttpResponse(
                        simplejson.dumps(dict(status='ok', msg='subscribed')))
            except NewsLetter.DoesNotExist:
                return HttpResponse(
                    simplejson.dumps(
                        dict(status='ok', msg='newsletter does not exists')))

        else:
            errors = []
            # we are restricting to on error per field.
            for e in form['email'].errors[:1]:
                errors.append(e)
            for e in form['mobile'].errors[:1]:
                errors.append(e)
            return HttpResponse(
                simplejson.dumps(dict(status='failed', error=errors)))

    return render_to_response('fb/popup.html', {'form': form},
                              context_instance=RequestContext(request))