Exemplo n.º 1
0
    def order_refunded(self, order):
        """
        The seller has refunded an order
        """
        context = self._order_context(order)
        self._sendmail('order-refunded-to-customer', order.user.email, context)

        self._sendmail('order-refunded-to-stall-owner', order.stall.user.email,
                       context)

        try:
            # Track the Seller refunding the Order
            order_info = self._mixpanel_order_info(order)
            mixpanel_track(self.request, "Clicked Refund Button", order_info)
            mixpanel_engage(self.request, {'$add': {'Refunds Made': 1}})

            # Update the Buyers properties, reducing their GMV
            # XXX: we can't delete the transaction after it's refunded!!!
            #      adding the transaction needs to happen on Dispatch
            user = order.user
            stall = order.stall
            mixpanel_engage(None, {
                '$set': {
                    'Orders': user.orders.completed().count(),
                    'Total GMV to Date': str(
                        user.get_profile().total_gmv.amount),
                },
                '$ignore_time': True
            },
                            distinct_id=user.id)
        except:
            LOG.warning("Couldn't notify MixPanel of refund", exc_info=True)
Exemplo n.º 2
0
    def user_followed(self, follow):
        """
        :param follow: UserFollow object which has just been created
        """
        mixpanel_track(self.request, "Followed User",
                       {"followed_user": follow.target.username})

        mixpanel_engage(self.request, get_mixpanel_info(follow.user),
                        follow.user.id)

        mixpanel_engage(self.request,
                        get_mixpanel_info(follow.target, ignore_time=True),
                        follow.target.id)

        template_name = 'new-follower-notification'
        context = {
            'USER_USERNAME':
            follow.user.username,
            'USER_PROFILE_URL':
            absolute_uri(follow.user.get_profile().get_absolute_url()),
            'TARGET_USER_USERNAME':
            follow.target.username,
            'TARGET_USER_PROFILE_URL':
            absolute_uri(follow.target.get_profile().get_absolute_url())
        }
        print absolute_uri(follow.user.get_profile().get_absolute_url()), \
            absolute_uri(follow.target.get_profile().get_absolute_url())
        email_notification = follow.target.email_notification
        if email_notification.follower_notifications:
            self._sendmail(template_name, follow.target.email, context)
        else:
            LOG.info(
                "Email not send to %s, since follower_notifications is set to OFF",
                follow.target.email)
Exemplo n.º 3
0
    def order_placed(self, order):
        """
         1) Syncs cart with SailThru
         2) Sends 'Order Completed' e-mail to customer via Sailthru
         3) Syncs order information with MixPanel
        """
        # Technically the transaction isn't complete yet because the seller hasn't
        # marked the order as complete so could potentially refund the money.
        try:
            context = self._order_context(order)
            self._sendmail('order-placed-to-customer', order.user.email,
                           context)

            self._sendmail('order-placed-to-stall-owner',
                           order.stall.user.email, context)
        except:
            LOG.error("Events.order_placed failed to send email",
                      exc_info=True)

        # Send completed order to SailThru, this updates the users 'Total Revenue'
        try:
            self.sailthru.order_purchased(order)
        except:
            LOG.error("Events.order_placed failed to sync order with SailThru",
                      exc_info=True)

        # Sync user properties with MixPanel
        try:
            user = order.user
            mixpanel_engage(self.request, {
                '$set': {
                    'Orders': user.orders.completed().count(),
                    'Total GMV to Date': str(
                        user.get_profile().total_gmv.amount),
                }
            },
                            distinct_id=user.id)
            mixpanel_engage(self.request, {
                '$append': {
                    '$transactions': {
                        '$time': order.created.isoformat(),
                        '$amount': str(order.total().amount),
                        'Order ID': order.id
                    }
                }
            },
                            distinct_id=user.id)
            if self.request is not None:
                order_info = self._mixpanel_order_info(order)
                mixpanel_track(self.request, "Purchased Order", order_info)
        except:
            LOG.warning("Couldn't notify MixPanel of new order", exc_info=True)
Exemplo n.º 4
0
    def user_unfollowed(self, unfollow):
        """
        :param unfollow: UserFollow object which is about to be deleted
        """
        mixpanel_track(self.request, "Unfollowed User",
                       {"followed_user": unfollow.target.username})

        mixpanel_engage(self.request, get_mixpanel_info(unfollow.user),
                        unfollow.user.id)

        mixpanel_engage(self.request,
                        get_mixpanel_info(unfollow.target, ignore_time=True),
                        unfollow.target.id)
    def handle(self, *args, **kwargs):
        for user in User.objects.all():
            try:
                user_profile = user.get_profile()
            except:
                continue
            total_gmv = user_profile.total_gmv
            if total_gmv is None or total_gmv <= 0:
                # Don't backdate valueless users
                continue         
            transactions = []
            for order in user.orders.completed():                
                transactions.append({
                    '$time': order.created.isoformat(),
                    '$amount': str(order.total().amount),
                    "Order ID": order.id,
                })
            if len(transactions) == 0:
                print "User has no transactions!"
                continue

            try:
                has_stall = user.stall is not None
            except:
                has_stall = False
            if has_stall:
                member_type = 'Regular'
            else:
                member_type = 'Stall Owner'
            user_properties = {       
                '$set': {                
                    '$email': user.email,
                    '$username': user.username,
                    '$created': user.date_joined.isoformat(),
                    "$last_seen": user.last_login.isoformat(),
                    '$first_name': user.first_name,
                    '$last_name': user.last_name,
                    '$ignore_time': True,
                    '$transactions': transactions,
                    'gender': user_profile.get_gender_display(),
                    'mp_name_tag': user.get_full_name(),
                    'Orders': user.orders.completed().count(),
                    'Total GMV to Date': str(total_gmv.amount),
                    'Member Type': member_type,
                },
                '$ip': 0,
                '$ignore_time': True,
                '$distinct_id': user.id,    
            }
            print user_properties
            mixpanel_engage(None, user_properties, user.id)
Exemplo n.º 6
0
    def cart_updated(self, cart):
        """
        Syncs contents of cart with SailThru and updates MixPanel properties
        for # of items in cart.

        :param cart: Cart object
        """
        try:
            self.sailthru.cart_updated(cart)
            mixpanel_engage(self.request,
                            {'$set': {
                                'Items in Cart': cart.num_items()
                            }})
        except:
            LOG.error("cart_updated failed", exc_info=True)
Exemplo n.º 7
0
    def logged_in(self, user):
        """
        The user has logged in to the site

        :param user: User object
        """
        # Integration with sailthru
        if self.sailthru.enabled():
            self.sailthru.login(user)

        # Internal LifetimeTrack
        try:
            lt = LifetimeTrack.objects.get(user=user)
            merge_lifetime_track(self.request.lifetime_track, lt)
        except Exception as e:
            print "=-" * 34, e

        # Integration with mixpanel
        try:
            mixpanel_track(self.request, "logged in",
                           {"$last_seen": datetime.datetime.now()})
            mixpanel_engage(self.request, {'$add': {'Times Logged In': 1}})
            try:
                has_stall = user.stall is not None
            except:
                has_stall = False
            if has_stall:
                member_type = 'Regular'
            else:
                member_type = 'Stall Owner'
            mixpanel_engage(
                self.request, {
                    '$set': {
                        'last_login': datetime.datetime.now().isoformat(),
                        '$email': user.email,
                        '$username': user.username,
                        '$created': user.date_joined.isoformat(),
                        "$last_seen": datetime.datetime.now().isoformat(),
                        '$first_name': user.first_name,
                        '$last_name': user.last_name,
                        'gender': user.user_profile.get_gender_display(),
                        'mp_name_tag': user.get_full_name(),
                        'Member Type': member_type,
                    }
                })
        except:
            LOG.warn('Could not send login event to MixPanel', exc_info=True)
Exemplo n.º 8
0
    def message_sent(self, msg):
        """
        A new message has been sent, notify the recipient via e-mail

        :param msg: Message object
        """
        if not msg.parent_msg:
            template_name = "new-message-received"
        else:
            template_name = "message-reply-received"

        # TODO: notification settings

        context = {
            "SENDER_USERNAME": msg.sender.username,
            "MESSAGE_SUBJECT": msg.subject,
            "MESSAGE_BODY": msg.body,
            'MESSAGE_VIEW_URL': absolute_uri(reverse('messaging_inbox'))
        }

        # send mail to hipchat
        template_context = Context({
            'request': self.request,
            'message': msg,
        })
        template = loader.get_template(
            "messaging/fragments/hipchat_message.html")
        output = template.render(template_context)

        send_to_hipchat(
            output,
            room_id=settings.HIPCHAT_MAIL_ROOM,
            notify=1,
        )

        mixpanel_track(self.request, "Sent Message", {})
        mixpanel_engage(self.request, {'$add': {'Messages Sent': 1}})

        self._sendmail(template_name, msg.recipient.email, context)
Exemplo n.º 9
0
    def order_dispatched(self, order):
        """
        The seller has marked an order as dispatched
        """
        try:
            context = self._order_context(order)
            self._sendmail('order-dispatched-to-customer', order.user.email,
                           context)
        except:
            LOG.warning("Couldn't send Order Dispatched email to Customer",
                        exc_info=True)

        try:
            order_info = self._mixpanel_order_info(order)
            mixpanel_track(self.request, 'Clicked Mark Order as Dispatched',
                           order_info)
            mixpanel_engage(self.request, {'$add': {
                'Orders Dispatched': 1
            }},
                            distinct_id=order.stall.user.id)
        except:
            LOG.warning("Couldn't update MixPanel after Order Dispatch",
                        exc_info=True)