示例#1
0
    def get_user_imgs_list(self, user_id=None, limit=None, offset=None):
        """Return a list that contains the images posted by "user_id".

        """
        if utils.validate_id(user_id):
            my_imgs_list = []

            if limit and offset:
                conditions = '(user_id = %d AND is_profile = FALSE) ORDER BY created_ts DESC LIMIT %d OFFSET %d' % (
                    user_id,
                    limit,
                    offset,
                )
            else:
                conditions = '(user_id = %d AND is_profile = FALSE) ORDER BY created_ts DESC' % (
                    user_id, )

            fields = 'id, image_filename, image_type'

            table = self._img_nosql_table

            query = f'SELECT {fields} FROM {table} WHERE {conditions}'

            nosql = FotogalNosql()
            query_result = nosql.exec_query_loop(table, query)

            for dict_result in query_result:
                my_imgs_list.append(dict_result)

            return my_imgs_list
示例#2
0
    def get_posted_imgs_list(self,
                             user_id=None,
                             follow_user_id=None,
                             limit=None,
                             offset=None):
        """Returns a list of a user's posted images

        """
        if utils.validate_id(user_id):
            posted_imgs_list = []

            if limit and offset:
                conditions = '(user_id = %d AND is_profile = FALSE) ORDER BY created_ts DESC LIMIT %d OFFSET %d' % (
                    follow_user_id,
                    limit,
                    offset,
                )
            else:
                conditions = '(user_id = %d AND is_profile = FALSE) ORDER BY created_ts DESC' % (
                    follow_user_id, )

            fields = 'id, user_id, image_filename, main_comment, created_ts,' \
                + 'liked_list[$element = %d] AS liked_by_me, disliked_list[$element = %d] AS disliked_by_me' % (user_id, user_id,)

            table = self._img_nosql_table

            query = f'SELECT {fields} FROM {table} WHERE {conditions}'

            nosql = FotogalNosql()
            query_result = nosql.exec_query_loop(table, query)

            fotogal_user = FotogalUser()

            for dict_result in query_result:
                img_username = fotogal_user.get_username(
                    id=dict_result['user_id'])
                profile_img_url = fotogal_user.get_profile_img_url(
                    id=dict_result['user_id'])

                if dict_result['liked_by_me'] is not None:
                    dict_result['liked_by_me'] = True
                else:
                    dict_result['liked_by_me'] = False

                if dict_result['disliked_by_me'] is not None:
                    dict_result['disliked_by_me'] = True
                else:
                    dict_result['disliked_by_me'] = False

                dict_result.update({'username': img_username})
                dict_result.update({'profile_image_url': profile_img_url})
                dict_result.pop('user_id')

                posted_imgs_list.append(dict_result)

            return posted_imgs_list