コード例 #1
0
def franchise_signup(request):
    params = request.POST
    username = params.get('username','').strip()
    dealer_id = params.get('dealer_id','').strip()
    dealer_code = params.get('dealer_code','').strip()
    password = params.get('password','').strip()
    error = ''
    
    if not utils.is_valid_email(username):
        error = 'Enter a valid e-mail address.'
    else:
        error = validate_username_and_password(username, password, password)
    
    if not error:
        profile = utils.get_profile_by_email_or_phone(username)
        if profile:
            error = 'Sorry, "%s" profile is not available' % username
            user, profile = utils.get_or_create_user(username,'',password)
            print "user--->",user.id,", profile--->",profile.id
            
        else:
            if network_or_franchise_email(username):
                error = "Network or ICW related to this email already exists"
            else:
                if is_user_entry(username):
                    error = "Email already exists in the database"
                else:
                    try:
                        logged_in_network = Network.objects.get(user=request.user)
                        #Some dcode and d-ids already on production which are same. Hence filter and not equal to 0 check
                        franchise_did = Franchise.objects.filter(network=logged_in_network.parent_network, dealer_id = dealer_id)
                        if franchise_did.count() != 0:
                            error = 'Dealer-ID already exists'
                        if not error:
                            franchise_dcode = Franchise.objects.filter(network=logged_in_network.parent_network, dealer_code = dealer_code)
                            if franchise_dcode.count() != 0:
                                error = 'Dealer-CODE already exists'
                    except Network.DoesNotExist:
                        error = 'Please logout and login again.'
    if not error:
        #Add User in first auth-users   / profiles/ email/ phone/
        user, profile = utils.get_or_create_user(username,'',password)
        franchise = Franchise(user=user,network=logged_in_network.parent_network,role='agent', dealer_id = dealer_id, dealer_code = dealer_code)
        franchise.save()
        message = "ICW '%s' added under '%s' network." % (user, logged_in_network)
    
    if error:
        response = dict(status='failed', html=error)
    else:
        response = dict(status='success', html = message)
    return HttpResponse(simplejson.dumps(response))
コード例 #2
0
def add_agents():
    from users.models import Profile
    from django.contrib.auth.models import User

    f = open("ezone_store_agents.txt")
    lines = f.readlines()
    for line in lines:
        print line
        line = line.strip()
        print line.split(",")
        name, email, password = line.split(",")
        namels = name.strip().split()
        if len(namels) > 1:
            first_name = namels[0]
            last_name = namels[1]
        email = email.strip()
        password = password.strip()
        user, profile = utils.get_or_create_user(email, email, password, first_name, last_name)
        profile.is_agent = True
        profile.save()
コード例 #3
0
ファイル: createezoneagents.py プロジェクト: daasara/riba
def add_agents():
    from users.models import Profile
    from django.contrib.auth.models import User

    f = open('ezone_store_agents.txt')
    lines = f.readlines()
    for line in lines:
        print line
        line = line.strip()
        print line.split(',')
        name, email, password = line.split(',')
        namels = name.strip().split()
        if len(namels) > 1:
            first_name = namels[0]
            last_name = namels[1]
        email = email.strip()
        password = password.strip()
        user, profile = utils.get_or_create_user(email, email, password,
                                                 first_name, last_name)
        profile.is_agent = True
        profile.save()
コード例 #4
0
ファイル: fb.py プロジェクト: 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))
コード例 #5
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),
    )
コード例 #6
0
def migrate_subscriptions():
    start = datetime(day=1, month=4, year=2011)
    subscripions_qs = FtbDealsLogin.objects.filter(registration_time__gte=start)
    newsletter = NewsLetter.objects.get(pk=2)
    for subscription in subscripions_qs:
        if SubscriptionSync.objects.filter(ext_id=subscription.id):
            #print 'Skipping %s: Already synced' % subscription.id
            continue
        email = subscription.email_address or ''
        mobile = subscription.mobile_number or ''
        name = subscription.register_name or ''
        if len(email) > 50 or len(name) > 100:
            #print 'Skipping %s: Long data' % subscription.id
            continue

        source = 'atg'
        if subscription.facebook_user == 1:
            source = 'facebook-atg'

        profile = None

        is_valid_email = False
        e = None
      	if utils.is_valid_email(email):
            is_valid_email = True
            try:
                e = Email.objects.get(email=email)
                profile = e.user
            except Email.DoesNotExist:
                pass

        is_valid_mobile = False
        m = None                 
        if utils.is_valid_mobile(mobile):
            is_valid_mobile = True
            try:
                m = Phone.objects.get(phone=mobile)
                profile = m.user
            except Phone.DoesNotExist:
                pass

        if not is_valid_mobile and is_valid_email:
            #print 'Skipping %s, %s, %s: Invalid data' % (email, mobile, name)
            continue

        if not profile:
            # Create a new profile in our system
            if is_valid_email:
                usr, profile = utils.get_or_create_user(email, email,
                                   password=None, first_name=name)
            if not is_valid_email:
                usr, profile = utils.get_or_create_user(mobile, '',
                                   password=None, first_name=name)

        if not profile:
            # Still not able to create profile
            #print 'Skipping %s, %s, %s: No profile' % (email, mobile, name)
            continue

	if not e:
            try:
                e = Email.objects.get(email=email)
            except Email.DoesNotExist:
                # Create a new email
                e = Email()
                e.user = profile
                e.email = email
                e.save()

        if not m:
            try:
                m = Phone.objects.get(phone=mobile)
            except Phone.DoesNotExist:
                m = Phone()
                m.user = profile
                m.phone = mobile
                m.save()

        # Create an entry into the subscription table 
        subscr = DailySubscription()
        subscr.email_alert_on = e
        subscr.sms_alert_on = m
        subscr.source = source
        subscr.timestamp = subscription.registration_time
        subscr.newsletter = newsletter
        subscr.save()

        link = SubscriptionSync()
        link.ext_id = subscription.id
        link.account = 'futurebazaar'
        link.save() 
コード例 #7
0
ファイル: migrate-subscriptions.py プロジェクト: daasara/riba
def migrate_subscriptions():
    start = datetime(day=1, month=4, year=2011)
    subscripions_qs = FtbDealsLogin.objects.filter(
        registration_time__gte=start)
    newsletter = NewsLetter.objects.get(pk=2)
    for subscription in subscripions_qs:
        if SubscriptionSync.objects.filter(ext_id=subscription.id):
            #print 'Skipping %s: Already synced' % subscription.id
            continue
        email = subscription.email_address or ''
        mobile = subscription.mobile_number or ''
        name = subscription.register_name or ''
        if len(email) > 50 or len(name) > 100:
            #print 'Skipping %s: Long data' % subscription.id
            continue

        source = 'atg'
        if subscription.facebook_user == 1:
            source = 'facebook-atg'

        profile = None

        is_valid_email = False
        e = None
        if utils.is_valid_email(email):
            is_valid_email = True
            try:
                e = Email.objects.get(email=email)
                profile = e.user
            except Email.DoesNotExist:
                pass

        is_valid_mobile = False
        m = None
        if utils.is_valid_mobile(mobile):
            is_valid_mobile = True
            try:
                m = Phone.objects.get(phone=mobile)
                profile = m.user
            except Phone.DoesNotExist:
                pass

        if not is_valid_mobile and is_valid_email:
            #print 'Skipping %s, %s, %s: Invalid data' % (email, mobile, name)
            continue

        if not profile:
            # Create a new profile in our system
            if is_valid_email:
                usr, profile = utils.get_or_create_user(email,
                                                        email,
                                                        password=None,
                                                        first_name=name)
            if not is_valid_email:
                usr, profile = utils.get_or_create_user(mobile,
                                                        '',
                                                        password=None,
                                                        first_name=name)

        if not profile:
            # Still not able to create profile
            #print 'Skipping %s, %s, %s: No profile' % (email, mobile, name)
            continue

        if not e:
            try:
                e = Email.objects.get(email=email)
            except Email.DoesNotExist:
                # Create a new email
                e = Email()
                e.user = profile
                e.email = email
                e.save()

        if not m:
            try:
                m = Phone.objects.get(phone=mobile)
            except Phone.DoesNotExist:
                m = Phone()
                m.user = profile
                m.phone = mobile
                m.save()

        # Create an entry into the subscription table
        subscr = DailySubscription()
        subscr.email_alert_on = e
        subscr.sms_alert_on = m
        subscr.source = source
        subscr.timestamp = subscription.registration_time
        subscr.newsletter = newsletter
        subscr.save()

        link = SubscriptionSync()
        link.ext_id = subscription.id
        link.account = 'futurebazaar'
        link.save()