Exemplo n.º 1
0
    def list_apps(cls,
                  search_query=None,
                  page_no=1,
                  page_size=5,
                  tag=None,
                  choose_type=None):
        if tag:
            # 通过标签筛选
            if not isinstance(tag, list):
                tag = tag.split(',')
            apps = AppBusiness.get_objects(search_query=None,
                                           has_version=True,
                                           privacy='public',
                                           tags=tag,
                                           page_size=page_size,
                                           page_no=page_no)
            apps, total_count = apps.objects, apps.count
            # AppBusiness.read({'tags': tag, 'privacy': 'public'})
            apps = cls._filter_apps(apps, 'top_rates')
        elif choose_type:
            # 其他
            apps = AppBusiness.get_objects(search_query=None,
                                           has_version=True,
                                           privacy='public',
                                           page_size=page_size,
                                           page_no=page_no)
            apps, total_count = apps.objects, apps.count
            # 切换 tab 键
            apps = cls._filter_apps(apps, choose_type)
        else:
            # search_query
            apps = AppBusiness.get_objects(search_query=search_query,
                                           has_version=True,
                                           privacy='public',
                                           page_size=page_size,
                                           page_no=page_no)
            apps, total_count = apps.objects, apps.count
            apps = cls._filter_apps(apps, 'top_rates')

        # 只需要返回最后一个版本
        for app in apps:
            path = app.path + '/OVERVIEW.md'
            if os.path.exists(path):
                with open(path, 'r') as file:
                    app.overview = file.read()
            app.versions = app.versions[-1]
            app.average_rate = app.avg_rate
            app.call_num = app.call
            app.user_ID = app.user.user_ID
            app.user_name = app.user.username
            app.avatarV = app.user.avatarV
            app.avatar_url = app.user.avatar_url
            app.args = AppBusiness.load_app_params(app, app.versions[-1])
        return apps, total_count
Exemplo n.º 2
0
 def get_single_app(cls, app_id):
     app = AppBusiness.get_by_id(app_id)
     path = app.path + '/OVERVIEW.md'
     if os.path.exists(path):
         with open(path, 'r') as file:
             app.overview = file.read()
     app.versions = [app.versions[-1]]
     app.average_rate = app.avg_rate
     app.call_num = app.call
     app.user_ID = app.user.user_ID
     app.user_name = app.user.username
     app.avatarV = app.user.avatarV
     app.args = AppBusiness.load_app_params(app, app.versions[-1])
     app.avatar_url = app.user.avatar_url
     app.view_num = EventBusiness.get_number({'app': app, 'action': "view"})
     return app