示例#1
0
文件: theme.py 项目: doomdooms/reed
 def browse(index):
     current = datetime.now()
     if index < 0:
         return "Cannot go to the future.", None
     elif index > ThemeModel.get_count(current):
         return "No more themes.", None
     else:
         wanted_time = current + timedelta(days=index)
         list_of_themes = ThemeModel.list_below_by_release_time(wanted_time)
         if not list_of_themes:
             return "No more themes.", None
         return "", list_of_themes
示例#2
0
    def browse(days, client_id):
        # need to get client_id from the Resouce(view)
        current = datetime.now()
        quantity = days * 2

        if quantity < 0:
            return "Cannot go to the future.", None

        elif quantity >= ThemeModel.get_count(
                current) or quantity < ThemeModel.get_count(current):
            quantity = ThemeModel.get_count(current)
            lowbound_time = current - timedelta(days=days)
            highbound_time = current
            list_of_themes = ThemeModel.list_between_by_release_time(
                lowbound_time, highbound_time, quantity)
            new_list_of_themes = []
            # print(list_of_themes) # 2EA
            # print(list_of_themes[1].json()) #1

            if not list_of_themes:
                return "No more themes.", None

            # call UserModel.written through client_id
            target = UserModel.find_by_id(client_id)
            # print(target.written[0].json())

            for theme in list_of_themes:
                json_written = theme.json()
                for post in target.written:
                    if theme.theme == post.theme:
                        json_written.update({'written': True})
                    else:
                        json_written.update({'written': False})
                new_list_of_themes.append(json_written)
            print(new_list_of_themes)

            # print(json_written)

            # return "", list_of_themes
            return "", new_list_of_themes