コード例 #1
0
ファイル: handlers.py プロジェクト: xinhan2000/Cardmeleon
    def create(self, request):
        """
        Creates a new user.
        """
        attrs = self.flatten_dict(request.data)
        #print attrs
        
        if self.userExists(attrs):
            return rc.DUPLICATE_ENTRY
        
        #insert new user
        user = User()
        self.updateModel(user, attrs)
        user.save()
        
        userprofile = UserProfile()
        self.updateModel(userprofile, attrs)
        userprofile.user = user
        
        #update referral activity table
        refererDict = attrs.get('referer')
        if refererDict:
            refererName = refererDict.get('username')
            if not refererName:
                refererName = refererDict.get('facebook')
            if refererName:
                referer = self.userByLogin(refererName)
                if referer:
                    userprofile.referer = referer
                    refereeName = user.username
                    try:
                        #TODO - the following query may fail to get the referral activity record.  revisit it later for a better way
                        referActivity = ReferralActivity.objects.filter(referer__id=referer.id, referee_name__iexact=refereeName).latest('time')
                        referActivity.referee = user
                        referActivity.referee_join_time = datetime.now()
                        referActivity.save()
                    except ReferralActivity.DoesNotExist:
                        pass
                    #update UserPoint for referral bonus
                    userPoint = UserPoint.objects.get(user__id=referer.id)
                    userPoint.points += REFERRAL_BONUS
                    

        userprofile.save()
        
        return rc.CREATED
コード例 #2
0
ファイル: handlers.py プロジェクト: tttthemanCorp/Cardmeleon
    def create(self, request):
        """
        Creates a new user.
        """
        attrs = self.flatten_dict(request.data)
        #print attrs
        
        if self.userExists(attrs):
            return rc.DUPLICATE_ENTRY
        
        #insert new user
        user = User()
        self.updateModel(user, attrs)
        user.save()
        
        userprofile = UserProfile()
        self.updateModel(userprofile, attrs)
        userprofile.user = user
        
        #update referral activity table
        refererDict = attrs.get('referer')
        if refererDict:
            referCode = refererDict.get('refer_code')
            if referCode:
                try:
                    referActivity = ReferralActivity.objects.get(id=referCode)
                    referActivity.referee = user
                    referActivity.referee_join_time = datetime.now()
                    referActivity.save()
                    # update user profile with refer
                    userprofile.referer = referActivity.referer
                    # update UserPoint for referral bonus
                    userPoint = UserPoint.objects.get(user__id=userprofile.referer.id)
                    userPoint.points += REFERRAL_BONUS
                    userPoint.save()
                except ReferralActivity.DoesNotExist:
                    pass

        userprofile.save()
        
        return rc.CREATED