Exemplo n.º 1
0
def view_campaign(request, camp_id):
    campaign = Campaign.objects.get(id=camp_id)
    perks = Perk.objects.filter(campaign=campaign)
    result = ''

    if request.method == 'POST':
        perk = request.POST.get('perk_id') or -1
        contact = request.POST.get('contact')
        amount = request.POST.get('amount')
        claimer = request.user if request.user.is_authenticated() else None
        card = request.POST.get('stripeToken')

        perk = Perk.objects.filter(id=perk).first()

        try:
            stripe_account_id = '' 
            # SocialAccount.objects.get(user__id=campaign.owner.id, provider='stripe').uid
            app_fee = 0.3

            charge = stripe.Charge.create(
                amount=amount,
                currency="usd",
                source=card, # obtained with Stripe.js
                # destination=stripe_account_id,
                # application_fee = int(amount * app_fee),                
                description="Contribute to the Campaign (#{} - {})".format(campaign.id, campaign.title)
            )
    
            PerkClaim.objects.create(campaign_id=camp_id,
                                     perk=perk,
                                     contact=contact,
                                     claimer=claimer,
                                     amount=amount,
                                     transaction=charge.id)
            # send notification email to the owner
            if perk:
                subject = 'Perk Claimatoin from Globalboard'
                content = "Perk ({}) in the campaign ({}) is claimed<br><br>Contact Info:<br>" \
                          .format(perk.title, campaign.title)

                # update perk's claimed count, used for cache for less db transaction
                perk.num_claimed = perk.num_claimed + 1
                perk.save()
            else:
                subject = 'Donation to your campaign on Globalboard'
                content = "Donation (${}) is made to the campaign ({})<br><br>Contact Info:<br>" \
                          .format(int(amount)/100, campaign.title)

            content += contact
            send_email(settings.FROM_EMAIL, subject, campaign.owner.email, content)

            # update campaign's raised amount, used for cache for less db transaction
            campaign.raised = campaign.raised + int(amount) / 100
            campaign.save()

            result = charge.id
        except Exception, e:
            print e, 'stripe error ##'
Exemplo n.º 2
0
def main():
    for post in Post.objects.all():
        if post.status == 'expired':
            continue
        if post.updated_at <= timezone.now() + datetime.timedelta(days=-post.category.duration):
            subject = 'Expired Ad'
            content = ' You Ad ( {} ) has expired. Click link to renew ad. https://www.kojoslist/post-ads/{}'.format(post.title, post.id)
            send_email(settings.FROM_EMAIL, subject, post.owner.email, content)
            post.status = 'expired'
            post.save()
Exemplo n.º 3
0
def rating_notify(sender, instance, **kwargs):
    try:
        content = '<a href="http://{0}/user_show/{1}">{2} {3}</a> left review on your ads (<a href="http://{0}/ads/{6}">{4}</a>) at {5}'.format(
            settings.ALLOWED_HOSTS[0], instance.rater.id,
            instance.rater.first_name, instance.rater.last_name,
            instance.post.title, instance.created_at, instance.post.id)
        send_email(settings.FROM_EMAIL, 'Globalboard Rating Notification',
                   instance.post.owner.email, content)
    except Exception, e:
        print e, '@@@@@ Error in rating_notify()'
Exemplo n.º 4
0
def rating_notify(sender, instance, **kwargs):
    try:
        content = '<a href="{0}/user_show/{1}">{2} {3}</a> left review on your ads (<a href="{0}/ads/{6}">{4}</a>) on {5}'.format(
            settings.MAIN_URL, instance.rater.id, instance.rater.first_name,
            instance.rater.last_name, instance.post.title,
            instance.created_at.strftime("%b-%d-%Y at %H:%M%p"),
            instance.post.id)
        content += "<br><br>" + instance.content
        send_email(settings.FROM_EMAIL, 'Globalboard Rating Notification',
                   instance.post.owner.email, content)
    except Exception as e:
        print(e, '@@@@@ Error in rating_notify()')
Exemplo n.º 5
0
def upload_id(request):
    id_photo = request.POST.get('id_photo')
    request.user.v_statue = 'awaiting_approve'
    # send an email to administrator
    content = """user {} uploaded his ID.<br> Please check and approve it 
                 <a href="http://18.216.225.192/admin/general/customer/{}/change/">here</a>.                 
    """.format(request.user.username, request.user.id)

    send_email(settings.FROM_EMAIL, 'Verification Submitted', settings.ADMIN_EMAIL, content)
    request.user.id_photo = 'ID/' + id_photo
    request.user.save()
    return HttpResponse('')
Exemplo n.º 6
0
def send_friend_email(request):
    from_email = request.POST.get('from_email')
    to_email = request.POST.get('to_email')
    ads_id = request.POST.get('ads_id')
    post = Post.objects.get(id=ads_id)
    content = """
        {} forwarded you this from craigslist:<br><br>
        <h3>{}</h3><br><br>
        http://18.216.225.192/ads/{}
        """.format(from_email, post.title, post.id)

    send_email(settings.FROM_EMAIL, post.title, to_email, content)
    return HttpResponse('')
Exemplo n.º 7
0
def send_reply_email(request):
    from_email = request.POST.get('from_email')
    content = request.POST.get('content')
    ads_id = request.POST.get('ads_id')
    post = Post.objects.get(id=ads_id)

    subject = 'Reply to ' + post.title
    content = """
        {} <br><br>Original post: 
        http://18.216.225.192/ads/{}
        """.format(content, post.id)

    # print (from_email, subject, post.owner.email, content)
    send_email(from_email, subject, post.owner.email, content)
    return HttpResponse('')
Exemplo n.º 8
0
def post_purchase_notify(sender, instance, **kwargs):
    try:
        # send email to the owner
        content = "Ads (<a href='http://{0}/ads/{1}'>{2}</a>) is purchased by {3} {4} at {5}<br><br>Contact Info:<br>" \
                  .format(settings.ALLOWED_HOSTS[0], instance.post.id, instance.post.title,
                          instance.purchaser.first_name, instance.purchaser.last_name, instance.created_at)
        if instance.type == 'direct':
            subject = 'Item purchased directly'
        else:
            subject = 'Item purchased via escrow'

        content += instance.contact
        send_email(settings.FROM_EMAIL, subject, instance.post.owner.email,
                   content)

    except Exception, e:
        print e, '@@@@@ Error in post_purchase_notify()'
Exemplo n.º 9
0
def apply_subscribe(sender, instance, **kwargs):
    try:
        for ss in Search.objects.filter(alert=True).exclude(
                owner=instance.owner):
            isApply = not ss.keyword or ss.keyword.lower(
            ) in instance.title.lower()
            if not ss.search_title and ss.keyword:
                isApply = isApply or ss.keyword.lower(
                ) in instance.content.lower()
            isApply = isApply and (ss.city == instance.region
                                   or ss.state == instance.region.state
                                   or ss.city == instance.region.district)
            isApply = isApply and (ss.category == instance.category
                                   or ss.category == instance.category.parent)
            if ss.has_image:
                isApply = isApply and instance.images.count() > 0

            if instance.price != None and ss.min_price != None:
                isApply = isApply and ss.min_price <= instance.price
            if instance.price != None and ss.max_price != None:
                isApply = isApply and ss.max_price >= instance.price

            if isApply:
                subscription_info = ''

                content = """
                    1 new result for your subscription ( {1} ) as of {2}<br><br>
                    <a href="{0}/ads/{3}">{4}</a><br><br>
                    <a href="{0}/my-subscriptions">See all of your subscriptions.</a><br><br>
                    Thank you for using <a href="http://{0}/">Globalboard</a>.
                """.format(settings.MAIN_URL, ss.category.name,
                           str(instance.created_at), instance.id,
                           instance.title)
                send_email(settings.FROM_EMAIL,
                           'Globalboard Subscription Alarm', ss.owner.email,
                           content)
    except Exception as e:
        print(e, '@@@@@ Error in apply_subscribe()')
Exemplo n.º 10
0
def post_purchase_notify(sender, instance, **kwargs):
    try:
        # send email to the owner
        subject = ''

        if instance.type == 'direct':
            subject = 'Item {0} purchased directly'.format(instance.post.title)
        else:
            subject = 'Item {0} purchased via escrow'.format(
                instance.post.title)

        if instance.type == 'escrow' and instance.paid_percent != 100 and instance.status == 0:

            subject = 'Item {0} cancelled via escrow'.format(
                instance.post.title)

            content = "The transaction <a href='{0}/ads/{1}'>{2}</a> (${3}) has been cancelled by <a href='{0}/user_show/{7}'>{4} {5}</a> on {6}" \
                  .format(settings.MAIN_URL, instance.post.id, instance.post.title, instance.post.price,
                          instance.purchaser.first_name, instance.purchaser.last_name, instance.created_at.strftime("%b-%d-%Y at %H:%M%p"), instance.purchaser.id)

            content += "<br><br>Total Price: ${0}<br>Received Amount: ${2}({3}%)<br> Cancelled Amount: ${4}<br>Service Fee: ${1}(one time payment)<br>Total Amount Received: <span style='color: red'>${5}</span>" \
                        .format(instance.post.price, instance.post.price * settings.APP_FEE, instance.post.price * instance.paid_percent / 100.0, instance.paid_percent , instance.post.price * (1.0 - (instance.paid_percent / 100.0)),
                         instance.post.price * (instance.paid_percent / 100.0 - settings.APP_FEE) if instance.paid_percent != 0 else 0
                        )

            content += "<br><br>Contact Info:<br>" + instance.contact

            content_to_self = "You have cancelled the transaction <a href='{0}/ads/{1}'>{2}</a> (${3}) from <a href='{0}/user_show/{5}'>{6} {7}</a> on {4}" \
                        .format(settings.MAIN_URL, instance.post.id, instance.post.title, instance.post.price,
                               instance.created_at.strftime("%b-%d-%Y at %H:%M%p"), instance.post.owner.id, instance.post.owner.first_name, instance.post.owner.last_name)

            content_to_self += "<br><br>Total Price: ${0}<br> Paid Amount: ${2}({3}%)<br> Cancelled Amount: ${4}<br>Service Fee: ${1}(one time payment)<br>Total Amount Paid: <span style='color: red'>${5}</span>" \
                        .format(instance.post.price, instance.post.price * settings.APP_FEE_BUY, instance.post.price * instance.paid_percent / 100.0, instance.paid_percent, instance.post.price * (1.0 - (instance.paid_percent / 100.0)), instance.post.price * (instance.paid_percent / 100.0 + settings.APP_FEE_BUY) )

            content_to_self += "<br><br>Contact Info:<br>{0} {1}".format(
                instance.post.owner.email, instance.post.owner.address)

        elif instance.type == 'escrow' and instance.paid_percent > 0:

            subject = '{0}% item {1} purchased via escrow'.format(
                instance.paid_percent, instance.post.title)

            content = "{7}% of <a href='{0}/ads/{1}'>{2}</a> (${3}) has been purchased by <a href='{0}/user_show/{8}'>{4} {5}</a> on {6}" \
                  .format(settings.MAIN_URL, instance.post.id, instance.post.title, instance.post.price,
                          instance.purchaser.first_name, instance.purchaser.last_name, instance.created_at.strftime("%b-%d-%Y at %H:%M%p"), instance.paid_percent, instance.purchaser.id)

            content += "<br><br>Total Amount: ${0}<br>Received Amount: ${2}({3}%)<br>Service Fee: ${1}(one time payment)<br>Total Amount Received: <span style='color: red'>${4}</span>" \
                        .format(instance.post.price, instance.post.price * settings.APP_FEE, instance.post.price * instance.paid_percent / 100.0, instance.paid_percent, instance.post.price * (instance.paid_percent / 100.0 - settings.APP_FEE) )

            content += "<br><br>Contact Info:<br>" + instance.contact

            content_to_self = "You have purchased {5}% of <a href='{0}/ads/{1}'>{2}</a> (${3}) from <a href='{0}/user_show/{6}'>{7} {8}</a> on {4}" \
                      .format(settings.MAIN_URL, instance.post.id, instance.post.title, instance.post.price,
                               instance.created_at.strftime("%b-%d-%Y at %H:%M%p"), instance.paid_percent, instance.post.owner.id, instance.post.owner.first_name, instance.post.owner.last_name)

            content_to_self += "<br><br>Total Amount: ${0}<br> Released Amount: ${2}({3}%)<br>Service Fee: ${1}(one time payment)<br>Total Amount Released: <span style='color: red'>${4}</span>" \
                        .format(instance.post.price, instance.post.price * settings.APP_FEE_BUY, instance.post.price * instance.paid_percent / 100.0, instance.paid_percent,  instance.post.price * (instance.paid_percent / 100.0 + settings.APP_FEE_BUY) )

            content_to_self += "<br><br>Contact Info:<br>{0} {1}".format(
                instance.post.owner.email, instance.post.owner.address)

        else:

            content = "<a href='{0}/ads/{1}'>{2}</a> (${3}) has been purchased {7} by <a href='{0}/user_show/{8}'>{4} {5}</a> on {6}" \
                  .format(settings.MAIN_URL, instance.post.id, instance.post.title, instance.post.price,
                          instance.purchaser.first_name, instance.purchaser.last_name, instance.created_at.strftime("%b-%d-%Y at %H:%M%p"), "" if instance.type == "direct" else "via escrow",  instance.purchaser.id)

            if instance.type == "direct":

                content += "<br><br>Total Amount: ${0}<br>Service Fee: ${1}(one time payment)<br>Total Amount Received: <span style='color: red'>${2}</span>" \
                        .format(instance.post.price, instance.post.price * settings.APP_FEE, instance.post.price * (1 - settings.APP_FEE) )

            content += "<br><br>Contact Info:<br>" + instance.contact


            content_to_self = "You purchased a <a href='{0}/ads/{1}'>{2}</a> (${3}) from <a href='{0}/user_show/{6}'>{7} {8}</a> {5} on {4}" \
                  .format(settings.MAIN_URL, instance.post.id, instance.post.title, instance.post.price,
                        instance.created_at.strftime("%b-%d-%Y at %H:%M%p"), "" if instance.type == "direct" else "via escrow", instance.post.owner.id, instance.post.owner.first_name, instance.post.owner.last_name)

            if instance.type == "direct":

                content_to_self += "<br><br>Total Amount: ${0}<br>Service Fee: ${1}(one time payment)<br>Total Amount Paid: <span style='color: red'>${2}</span>" \
                        .format(instance.post.price, instance.post.price * settings.APP_FEE_BUY, instance.post.price * (1 + settings.APP_FEE_BUY) )

            content_to_self += "<br><br>Contact Info:<br>{0} {1}".format(
                instance.post.owner.email, instance.post.owner.address)

        send_email(settings.FROM_EMAIL, subject, instance.post.owner.email,
                   content)

        send_email(settings.FROM_EMAIL, subject, instance.purchaser.email,
                   content_to_self)

    except Exception as e:
        print(e, '@@@@@ Error in post_purchase_notify()')