Exemple #1
0
    def is_username_available(cls, username):
        '''
        This method checks to see if an username has been registered by another user

        Args:
            username: The username to be checked for availability

        Returns:
            False is the username has been used by another user
            True if otherwise
        '''
        if username is None:
            return False

        key = 'username_available_' + username
        rv = r.get(key)
        if rv is not None:
            return rv

        if username is not None and \
            User.objects(name=username).first() is None:
            r.set(key, False)
            return True
        else:
            return False
Exemple #2
0
 def num_deals_shared(self):
     key = "".join([self.name, '_num_deals_shared'])
     if r.exists(key):
         return r.get(key)
     else:
         num_votes_given = len(self.deals_submitted)
         r.setex(key, 3600, num_votes_given)
         return num_votes_given
Exemple #3
0
    def num_likes_received(self):
        '''
        This method returns the total amounts of points that this user's
        submitted deal has received
        '''

        key = "".join([self.name, '_num_likes_received'])
        if r.exists(key):
            return r.get(key)
        else:
            # points = [deal.num_votes for deal in self.deals_submitted]
            # total_points = sum(points)
            deals = Deal.objects(id__in=self.deals_submitted)
            points = [deal.num_votes for deal in deals]
            total_points = sum(points)
            r.setex(key, 3600, total_points)
            return total_points
Exemple #4
0
    def is_email_available(cls, email):
        '''
        This method checks to see if an email has been previously used or registered by another user

        Args:
            email: The email to be checked for availability

        Returns:
            False is the email has been used by another user
            True if otherwise
        '''
        if email is None:
            return False

        key = 'email_available_' + email
        rv = r.get(key)
        if rv is not None:
            return rv

        if email is not None and User.objects(email=email).first() is None:
            r.set(key, False)
            return True
        else:
            return False