Esempio n. 1
0
    def following(self, page=None):
        """
        This needs to be refactored, but it would be so slow if we
        were grabbing user objects for each user on 1,000 users.
        """
        select = """
          SELECT user.id as user_id, user.name as user_name, user.profile_image as user_image,
                    shake.name as shake_name, shake.type as shake_type , shake.image as shake_image,
                    shake.id as shake_id
            FROM subscription, user, shake
              WHERE subscription.user_id = %s
              AND subscription.shake_id = shake.id
              AND user.id = shake.user_id
              AND shake.deleted = 0
              AND subscription.deleted = 0
        """ % self.id

        if page > 0:
            limit_start = (page - 1) * 20
            select = "%s LIMIT %s, %s" % (select, limit_start, 20)

        users_and_shakes = User.query(select)

        us_list = []
        for us in users_and_shakes:
            this_follow = {}
            this_follow['image'] = '/static/images/default-icon-venti.svg'
            if us['shake_type'] == 'user':
                this_follow['id'] = us['user_id']
                this_follow['path'] = '/user/%s' % (us['user_name'])
                this_follow['name'] = us['user_name']
                this_follow['type'] = 'user'
                if us['user_image']:
                    this_follow['image'] = s3_url("account/%s/profile.jpg" %
                                                  us['user_id'])
            else:
                this_follow['id'] = us['shake_id']
                this_follow['path'] = '/%s' % (us['shake_name'])
                this_follow['name'] = us['shake_name']
                this_follow['type'] = 'shake'
                if us['shake_image']:
                    this_follow['image'] = s3_url(
                        "account/%s/shake_%s.jpg" %
                        (us['user_id'], us['shake_name']))

            us_list.append(this_follow)
        return us_list
Esempio n. 2
0
 def thumbnail_url(self):
     if self.type == 'user':
         return self.owner().profile_image_url(include_protocol=True)
     else:
         if self.image:
             return s3_url("account/%s/shake_%s_small.jpg" %
                           (self.user_id, self.name))
         else:
             if options.app_host == "mltshp.com":
                 return "https://%s/static/images/default-icon-venti.svg" % options.cdn_ssl_host
             else:
                 return "http://%s/static/images/default-icon-venti.svg" % options.app_host
Esempio n. 3
0
 def page_image(self):
     """
     Return's users profile image if it's a user shake or the shake image.
     If no image, returns None.
     """
     if self.type == 'user':
         return self.owner().profile_image_url()
     else:
         if self.image:
             return s3_url("account/%s/shake_%s.jpg" %
                           (self.user_id, self.name))
         else:
             return None