コード例 #1
0
ファイル: views.py プロジェクト: kahihia/appbid
def sendNewCommentEmail(request, *args, **kwargs):
    """Send email to seller and buyer, when user add comment."""
    app = kwargs.get('app')
    comment = kwargs.get('comment')
    common_msg = comment.comment
    massEmailThread = email.MassEmailThread()
    if request.user.id != app.publisher.id:
        templates_seller = models.NotificationTemplate.objects.filter(
            name='new_comment_inform_seller')
        templates_buyer = models.NotificationTemplate.objects.filter(
            name='new_comment_inform_buyer')
        item_seller = app.publisher.subscriptionitem_set.filter(
            key='new_comment')
        if item_seller and templates_seller:
            subject = templates_seller[0].subject
            message = templates_seller[0].template.replace(
                '{param1}',
                app.publisher.username).replace('{param2}', app.app_name)
            massEmailThread.addEmailData(subject=subject,
                                         message=message,
                                         recipient_list=[app.publisher.email])
    watchApps = dashboardModels.WatchApp.objects.filter(app_id=app.id)
    for watchApp in watchApps:
        if templates_buyer:
            subject = templates_buyer[0].subject.replace(
                '{param1}', app.app_name)
            message = templates_buyer[0].template.replace(
                '{param1}',
                watchApp.buyer.username).replace('{param2}', app.app_name)
            massEmailThread.addEmailData(subject=subject,
                                         message=message,
                                         recipient_list=[watchApp.buyer.email])
    massEmailThread.start()
コード例 #2
0
ファイル: views.py プロジェクト: kahihia/appbid
def sendNewBidEmail(request, *args, **kwargs):
    """Send email when new bidding."""
    app = kwargs.get('app')
    bid = kwargs.get('bid')
    massEmailThread = email.MassEmailThread()
    templates_seller = models.NotificationTemplate.objects.filter(
        name='new_bid_inform_seller')
    templates_buyer = models.NotificationTemplate.objects.filter(
        name='new_bid_inform_buyer')
    item_seller = app.publisher.subscriptionitem_set.filter(key='new_bid')
    if item_seller and templates_seller:
        subject = templates_seller[0].subject
        message = templates_seller[0].template.replace(
            '{param1}',
            app.publisher.username).replace('{param2}', app.app_name)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[app.publisher.email])
    user_ids = [bid.buyer.id]
    bids = app.bidding_set.exclude(buyer_id=bid.buyer.id)
    for bidding in bids:
        if bidding.buyer.id not in user_ids:
            user_ids.append(bidding.buyer.id)
            item_buyer = bidding.buyer.subscriptionitem_set.filter(
                key='new_bid_above_mine')
            if item_buyer and templates_buyer:
                subject = templates_seller[0].subject
                message = templates_seller[0].template.replace(
                    '{param1}',
                    bidding.buyer.username).replace('{param2}', app.app_name)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[bidding.buyer.email])
    massEmailThread.start()
コード例 #3
0
def checkIfSellApp(*args, **kwargs):
    """
        The task will be done every hour.
        When service stop, if bidding price is more than max price, seller has 7 days to trade now. Then seller did not
        trade app in 7 days, seller's credit points will be decreased.
    """
    transactions = txnModels.Transaction.objects.filter(
        status=1,
        end_time__isnull=False,
        end_time__lte=datetime.datetime.now()).exclude(buy_type=1)
    massEmailThread = email.MassEmailThread()
    points = common.getSystemParam(key='cp_buyer_unpaid', default=50)
    log.info("----")
    for transaction in transactions:
        log.info(transaction.id)
        #Decrease seller's credit points
        creditViews.decreaseCreditPoint(user=transaction.seller,
                                        point=string.atoi(points),
                                        type=1,
                                        ref_id=transaction.id)
        templates = notificationModels.NotificationTemplate.objects.filter(
            name='unsold_end_inform_seller')
        if templates:
            subject = templates[0].subject
            message = templates[0].template.replace(
                '{param1}',
                transaction.seller.username).replace('{param2}', points)
            massEmailThread.addEmailData(
                subject=subject,
                message=message,
                recipient_list=[transaction.seller.email])
    massEmailThread.start()
    return None
コード例 #4
0
def verificationAppForSeller(*args, **kwargs):
    """
        The task will be done in at schedule time, such as: every four hours.
        After Seller creating app clicks verified, verified app owner ship on schedule plan
    """
    times = string.atoi(
        common.getSystemParam(key='verify_app_times', default=3))
    ownerShipScans = appModels.OwnerShip_Scan.objects.filter(times__lte=times)
    massEmailThread = email.MassEmailThread()
    for ownerShipScan in ownerShipScans:
        app = ownerShipScan.app
        result = common.getITunes(app.apple_id)
        if result is None:
            continue
        description = result.get('description', None)
        if app.verify_token in description:
            templates = notificationModels.NotificationTemplate.objects.filter(
                name='verified_app_success_inform_seller')
            if templates:
                subject = templates[0].subject.replace('{param1}',
                                                       app.app_name)
                message = templates[0].template.replace(
                    '{param1}',
                    app.publisher.username).replace('{param2}', app.app_name)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[app.publisher.email])
                ownerShipScan.delete()
                #Update app is_verified value
                app.is_verified = True
                app.save()
        else:
            ownerShipScan.times += 1
            ownerShipScan.save()
            templates = notificationModels.NotificationTemplate.objects.filter(
                name='verified_app_failed_inform_seller')
            if ownerShipScan.times == 3 and templates:
                subject = templates[0].subject.replace('{param1}',
                                                       app.app_name)
                message = templates[0].template.replace(
                    '{param1}',
                    app.publisher.username).replace('{param2}', app.app_name)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[app.publisher.email])
    massEmailThread.start()

    return None
コード例 #5
0
ファイル: views.py プロジェクト: kahihia/appbid
def sendNewMessageEmail(request, *args, **kwargs):
    """Send email to seller or buyer, when user send message to seller or buyer."""
    message = kwargs.get('message')
    item_user = message.receiver.subscriptionitem_set.filter(key='private_msg')
    templates = models.NotificationTemplate.objects.filter(
        name='new_message_inform_user')
    if item_user and templates:
        massEmailThread = email.MassEmailThread()
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}',
                                                message.receiver.username)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[message.receiver.email])
        massEmailThread.start()
コード例 #6
0
ファイル: views.py プロジェクト: kahihia/appbid
def remindBuyerPay(request, *args, **kwargs):
    """Seller remind buyer to pay."""
    transaction = kwargs.get('transaction')
    templates = models.NotificationTemplate.objects.filter(
        name='seller_remind_buyer_pay')
    if transaction and templates:
        massEmailThread = email.MassEmailThread()
        subject = templates[0].subject.replace('{param1}',
                                               transaction.app.app_name)
        message = templates[0].template.replace(
            '{param1}',
            transaction.buyer.username).replace('{param2}',
                                                transaction.app.app_name)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[transaction.buyer.email])
        massEmailThread.start()
コード例 #7
0
ファイル: views.py プロジェクト: kahihia/appbid
def closedTradeInform(*args, **kwargs):
    """After buyer close trade, send email to seller that trade is closed."""
    transaction = kwargs.get('transaction')
    if transaction:
        massEmailThread = email.MassEmailThread()
        templates_seller = models.NotificationTemplate.objects.filter(
            name='closed_trade_inform_seller')
        if templates_seller:
            subject = templates_seller[0].subject
            message = templates_seller[0].template.replace(
                '{param1}', transaction.seller.username)
            recipient_list = [transaction.seller.email]
            massEmailThread.addEmailData(subject=subject,
                                         message=message,
                                         recipient_list=recipient_list)
        templates_buyer = models.NotificationTemplate.objects.filter(
            name='closed_trade_inform_buyer')
        if templates_buyer:
            subject = templates_buyer[0].subject
            message = templates_buyer[0].template.replace(
                '{param1}', transaction.buyer.username)
            recipient_list = [transaction.seller.email]
            massEmailThread.addEmailData(subject=subject,
                                         message=message,
                                         recipient_list=recipient_list)
        #Notify user when new auctions appear for user's watched categories
        categories = transaction.app.category.all()
        watchCategories = dashboardModels.WatchCategory.objects.filter(
            category__in=categories)
        templates_watch = models.NotificationTemplate.objects.filter(
            name='closed_trade_inform_buyer_watched_category')
        for watchCategory in watchCategories:
            if templates_watch:
                subject = templates_watch[0].subject
                message = templates_watch[0].template.replace(
                    '{param1}', transaction.buyer.username).replace(
                        '{param2}', transaction.app.app_name)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[watchCategory.buyer.email])
        massEmailThread.start()
    return None
コード例 #8
0
ファイル: views.py プロジェクト: kahihia/appbid
def buyerPayInformSellerEmail(*args, **kwargs):
    """After buyer pay, send email to seller inform that buyer has paid, and he can trade now."""
    transaction = kwargs.get('transaction')
    templates = models.NotificationTemplate.objects.filter(
        name='buyer_paid_inform_seller')
    if transaction and templates:
        massEmailThread = email.MassEmailThread()
        subject = templates[0].subject.replace('{param1}',
                                               transaction.app.app_name)
        message = templates[0].template.replace(
            '{param1}', transaction.seller.username).replace(
                '{param2}',
                transaction.buyer.username).replace('{param3}',
                                                    transaction.app.app_name)
        massEmailThread.addEmailData(
            subject=subject,
            message=message,
            recipient_list=[transaction.app.publisher.email])
        massEmailThread.start()
    return None
コード例 #9
0
ファイル: views.py プロジェクト: kahihia/appbid
def sendSecurityVerificationEmail(request, *args, **kwargs):
    """After user update email in security setting, send the email verification link to the new email."""
    user = kwargs.get('user')
    templates = models.NotificationTemplate.objects.filter(
        name='email_security_verification')
    if user and templates:
        massEmailThread = email.MassEmailThread()
        link_header = common.getHttpHeader(request)
        token = common.getToken(key='token_length', default=30)
        active_link = '/'.join([
            link_header, 'usersetting', user.username, 'emails',
            str(user.id), 'email-security-verification', token
        ])
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}',
                                                user.username).replace(
                                                    '{param2}', active_link)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[user.email])
        massEmailThread.start()
    return None
コード例 #10
0
ファイル: views.py プロジェクト: kahihia/appbid
def sendNewAppEmail(request, *args, **kwargs):
    """Send email to user, when the new app whose publisher watched by user is created."""
    app = kwargs.get('app')
    watchSellers = dashboardModels.WatchSeller.objects.filter(
        seller_id=app.publisher.id)
    if app and watchSellers:
        massEmailThread = email.MassEmailThread()
        templates = models.NotificationTemplate.objects.filter(
            name='new_app_inform_buyer')
        for watchSeller in watchSellers:
            if templates:
                subject = templates[0].subject.replace(
                    '{param1}', watchSeller.seller.username)
                message = templates[0].template.replace(
                    '{param1}', watchSeller.buyer.username).replace(
                        '{param2}', watchSeller.seller.username).replace(
                            '{param3}', app.app_name)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[watchSeller.buyer.email])
        massEmailThread.start()
コード例 #11
0
ファイル: views.py プロジェクト: kahihia/appbid
def sendRegisterActiveEmail(request, *args, **kwargs):
    """After user register, send the account active link to his email."""
    user = kwargs.get('user')
    templates = models.NotificationTemplate.objects.filter(
        name='register_active')
    if user and templates:
        massEmailThread = email.MassEmailThread()
        link_header = common.getHttpHeader(request)
        token = common.getToken(key='token_length', default=30)
        active_link = '/'.join([
            link_header, 'usersetting', user.username, 'emails',
            str(user.id), 'register-confirm-verification', token
        ])
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}',
                                                user.username).replace(
                                                    '{param2}', active_link)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[user.email])
        massEmailThread.start()
    return None
コード例 #12
0
ファイル: views.py プロジェクト: kahihia/appbid
def tradeNowInformBuyerPayEmail(request, *args, **kwargs):
    """After seller click button 'Trade Now', send email to buyer inform that he won the bidding, and can pay now."""
    app = kwargs.get('app')
    user = kwargs.get('user')
    templates = models.NotificationTemplate.objects.filter(
        name='seller_trade_now')
    if app and user and templates:
        massEmailThread = email.MassEmailThread()
        link_header = common.getHttpHeader(request)
        app_detail_url = '/'.join(
            [link_header, 'query/app-detail',
             str(app.id)])
        pay_url = '/'.join([link_header, 'dashboard/my-bidding'])
        subject = templates[0].subject
        message = templates[0].template.replace(
            '{param1}',
            user.username).replace('{param2}',
                                   app.app_name).replace('{param3}', pay_url)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[user.email])
        massEmailThread.start()
    return None
コード例 #13
0
ファイル: views.py プロジェクト: kahihia/appbid
def sendResetPasswordEmail(request, *args, **kwargs):
    """Send the email of reset password."""
    user = kwargs.get('user')
    type = kwargs.get('type')
    templates = models.NotificationTemplate.objects.filter(
        name='reset_password_email')
    if user and type and templates:
        massEmailThread = email.MassEmailThread()
        header = common.getHttpHeader(request)
        token = common.getToken(key='token_length', default=30)
        url = '/'.join([
            header, 'usersetting/reset-password',
            str(type),
            str(user.id), user.username, token
        ])
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}',
                                                user.username).replace(
                                                    '{param2}', url)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[user.email])
        massEmailThread.start()
    return None
コード例 #14
0
def checkServiceDateForApps(*args, **kwargs):
    """
        The task will be done every hour.
        Do something, when the app service date is ending.
        1. App status will be changed from published to closed.
        2. Send email of expiry date to seller.(The email: 1.Service end; 2.Seller can trade now.)
    """
    # current_date = datetime.datetime.combine(datetime.date.today(), datetime.time())
    # next_date = datetime.datetime.combine(datetime.date.today() + datetime.timedelta(days=1), datetime.time())
    # apps = appModels.App.objects.filter(status=2, end_date__gte=current_date, end_date__lt=next_date)
    apps = appModels.App.objects.filter(status=2,
                                        end_date__lte=datetime.datetime.now())
    massEmailThread = email.MassEmailThread()
    for app in apps:
        app.status = 3
        app.save()
        max_price = app.bidding_set.filter(status=1).aggregate(Max('price'))
        current_price = max_price.get('price__max', 0)
        #If bidding price is more than max price, seller has 7 days to trade or else seller can not trade it.
        if app.reserve_price and app.reserve_price <= current_price:
            bids = bidModels.Bidding.objects.filter(app_id=app.id,
                                                    price=current_price,
                                                    status=1)
            transactions = app.transaction_set.filter(is_active=True)
            if transactions:
                transaction = transactions[0]
            else:
                transaction = txnModels.Transaction()
                transaction.status = 1
                transaction.app = app
                transaction.is_active = True
            paid_expiry_date = string.atoi(
                common.getSystemParam(key='sell_expiry_date', default=7))
            transaction.end_time = app.end_date + datetime.timedelta(
                days=paid_expiry_date)
            transaction.save()

            transactionsLog = txnModels.TransactionLog()
            transactionsLog.transaction = transaction
            transactionsLog.app = app
            transactionsLog.status = 1
            transactionsLog.save()
            templates = notificationModels.NotificationTemplate.objects.filter(
                name='service_end_inform_seller')
            if templates:
                subject = templates[0].subject.replace('{param1}',
                                                       bids[0].buyer.username)
                message = templates[0].template.replace(
                    '{param1}',
                    app.publisher.username).replace('{param2}', app.app_name)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[app.publisher.email])
        else:
            templates = notificationModels.NotificationTemplate.objects.filter(
                name='service_end_inform_seller_lt_reserve_price')
            if templates:
                subject = templates[0].subject.replace('{param1}',
                                                       app.app_name)
                message = templates[0].template.replace(
                    '{param1}', app.publisher.username)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[app.publisher.email])
    massEmailThread.start()
    return None
コード例 #15
0
def taskForBuyUnpaid(*args, **kwargs):
    """
        The task will be done in at schedule time, such as: every hour.
        Do something, if buy still unpaid after 7 days of paid_expiry_date set in system-param table.
        1. Change transaction is_active from True to False.
        2. Buyer will be subtracted 50 credit point, and put into blacklist.
        3. Buyer's all bidding status is changed from approved to rejected.(Note: All bidding for this buyer.)
        4. Send email to buyer.(The email: 1.Subtract his 50 credit point; 2.Put him into blacklist.)
        5. Send email to seller.(The email: 1.Seller may choice the buyer bidding with second max price to trade again;
                                            2.The unpaid buyer has been put into blacklist.)
        6. Send email to new buyer bidding with second max price. (The email: 1. He is the max bidding one now;
                                            2. Seller will trade with you later.)
    """
    points = string.atoi(
        common.getSystemParam(key='cp_no_closed_trade', default=50))
    templates_buyer = notificationModels.NotificationTemplate.objects.filter(
        name='buyer_unpaid_inform_buyer')
    templates_seller = notificationModels.NotificationTemplate.objects.filter(
        name='buyer_unpaid_inform_seller')
    templates_second_buyer = notificationModels.NotificationTemplate.objects.filter(
        name='buyer_unpaid_inform_second_buyer')
    templates_seller_no_bidding = notificationModels.NotificationTemplate.objects.filter(
        name='buyer_unpaid_inform_seller_no_bidding')

    transactions = txnModels.Transaction.objects.filter(
        is_active=True, status=2, end_time__lte=datetime.datetime.now())
    massEmailThread = email.MassEmailThread()
    for transaction in transactions:
        transaction.is_active = False
        transaction.save()
        creditViews.decreaseCreditPoint(user=transaction.buyer,
                                        point=points,
                                        type=1,
                                        ref_id=transaction.id)
        bidModels.Bidding.objects.filter(
            app_id=transaction.app.id,
            buyer_id=transaction.buyer.id).update(status=False)
        if templates_buyer:
            subject = templates_buyer[0].subject
            message = templates_buyer[0].template.replace(
                '{param1}', transaction.buyer.username)
            massEmailThread.addEmailData(
                subject=subject,
                message=message,
                recipient_list=[transaction.buyer.email])
        bidding = bidModels.Bidding.objects.filter(app_id=transaction.app.id,
                                                   status=1).order_by('-price')
        if bidding:
            if templates_seller:
                subject = templates_seller[0].subject
                message = templates_seller[0].template.replace(
                    '{param1}', transaction.seller.username).replace(
                        '{param2}', transaction.buyer.username)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[transaction.seller.email])
            if templates_second_buyer:
                subject = templates_second_buyer[0].subject
                message = templates_second_buyer[0].template.replace(
                    '{param1}', bidding[0].buyer.username).replace(
                        '{param2}', transaction.app.app_name)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[bidding[0].buyer.email])
        else:
            if templates_seller_no_bidding:
                subject = templates_seller_no_bidding[0].subject
                message = templates_seller_no_bidding[0].template.replace(
                    '{param1}', transaction.seller.username)
                massEmailThread.addEmailData(
                    subject=subject,
                    message=message,
                    recipient_list=[transaction.seller.email])
    massEmailThread.start()

    return None
コード例 #16
0
def sendMailForRemind(*args, **kwargs):
    """
        The task will be done in at schedule time, such as: every hour.
        1. The paid_expiry_date set in system-param table is 7 days.
           If buyer does not pay, will send email to buyer in remain 4, 2, 1 days.
        2. The txn_expiry_date set in system-param table is 15 days.
           If buyer does not finish trade, will send email to buyer in remain 7, 4 days.
    """
    massEmailThread = email.MassEmailThread()
    seven_next_date = datetime.datetime.now() + datetime.timedelta(days=7)
    four_next_date = datetime.datetime.now() + datetime.timedelta(days=4)
    two_next_date = datetime.datetime.now() + datetime.timedelta(days=2)
    one_next_date = datetime.datetime.now() + datetime.timedelta(days=1)

    remind_template = notificationModels.NotificationTemplate.objects.filter(
        name='pay_remind_buyer')
    if remind_template:
        fourTxn = txnModels.Transaction.objects.filter(
            status=2,
            is_active=True,
            end_time__year=four_next_date.year,
            end_time__month=four_next_date.month,
            end_time__day=four_next_date.day)
        for txn in fourTxn:
            subject = remind_template[0].subject.replace(
                '{param1}', txn.app.app_name)
            message = remind_template[0].template.replace(
                '{param1}', txn.buyer.username).replace('{param2}', 4)
            massEmailThread.addEmailData(subject=subject,
                                         message=message,
                                         recipient_list=[txn.buyer.email])
        twoTxn = txnModels.Transaction.objects.filter(
            status=2,
            is_active=True,
            end_time__year=two_next_date.year,
            end_time__month=two_next_date.month,
            end_time__day=two_next_date.day)
        for txn in twoTxn:
            subject = remind_template[0].subject.replace(
                '{param1}', txn.app.app_name)
            message = remind_template[0].template.template.replace(
                '{param1}', txn.buyer.username).replace('{param2}', 2)
            massEmailThread.addEmailData(subject=subject,
                                         message=message,
                                         recipient_list=[txn.buyer.email])
        oneTxn = txnModels.Transaction.objects.filter(
            status=2,
            is_active=True,
            end_time__year=one_next_date.year,
            end_time__month=one_next_date.month,
            end_time__day=one_next_date.day)
        for txn in oneTxn:
            subject = remind_template[0].subject.replace(
                '{param1}', txn.app.app_name)
            message = remind_template[0].template.template.replace(
                '{param1}', txn.buyer.username).replace('{param2}', 1)
            massEmailThread.addEmailData(subject=subject,
                                         message=message,
                                         recipient_list=[txn.buyer.email])

    remind_template = notificationModels.NotificationTemplate.objects.filter(
        name='txn_remind_seller')
    if remind_template:
        sevenTxn = txnModels.Transaction.objects.filter(
            status=3,
            is_active=True,
            end_time__year=seven_next_date.year,
            end_time__month=seven_next_date.month,
            end_time__day=seven_next_date.day)
        for txn in sevenTxn:
            subject = remind_template[0].subject.replace(
                '{param1}', txn.app.app_name)
            message = remind_template[0].template.template.replace(
                '{param1}',
                txn.seller.username).replace('{param2}', 7).replace(
                    '{param3}', txn.app.app_name)
            massEmailThread.addEmailData(subject=subject,
                                         message=message,
                                         recipient_list=[txn.buyer.email])
        fourTxn = txnModels.Transaction.objects.filter(
            status=3,
            is_active=True,
            end_time__year=four_next_date.year,
            end_time__month=four_next_date.month,
            end_time__day=four_next_date.day)
        for txn in fourTxn:
            subject = remind_template[0].subject.replace(
                '{param1}', txn.app.app_name)
            message = remind_template[0].template.template.replace(
                '{param1}',
                txn.seller.username).replace('{param2}', 4).replace(
                    '{param3}', txn.app.app_name)
            massEmailThread.addEmailData(subject=subject,
                                         message=message,
                                         recipient_list=[txn.buyer.email])
    massEmailThread.start()
    return None