Example #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
Example #2
0
 def related_app(cls, app_id, user_ID=None, page_size=7):
     app = AppBusiness.get_by_id(app_id)
     tags = app.tags
     related_apps = AppBusiness.get_objects(tags=tags,
                                            has_version=True,
                                            privacy='public')
     related_apps, _ = related_apps.objects, related_apps.count
     related_ids = [str(a.id) for a in related_apps]
     # 拷贝一份
     back_apps = [app for app in related_apps]
     # 删除重复
     if app_id in related_ids:
         index = related_ids.index(app_id)
         del back_apps[index]
     if user_ID:
         self_app, _ = cls.self_apps(user_ID)
         # 拼接, 去重
         for a in self_app:
             if str(
                     a.id
             ) not in related_ids and 'tutorial' not in a.display_name.lower(
             ):
                 back_apps.append(a)
                 related_ids.append(str(a.id))
     # 判断是否小于七个
     if len(related_apps) < page_size:
         # 判断当前个数, 寻找剩余数量
         supplement_apps = AppBusiness.get_objects(page_size=page_size,
                                                   has_version=True,
                                                   privacy='public').objects
         for a in supplement_apps:
             if str(
                     a.id
             ) not in related_ids and 'tutorial' not in a.display_name.lower(
             ):
                 back_apps.append(a)
     # 添加数据
     for app in back_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.avatar_url = app.user.avatar_url
     return back_apps, page_size
Example #3
0
 def self_apps(cls, user_ID):
     apps = AppBusiness.get_objects(
         user=UserBusiness.get_by_user_ID(user_ID), has_version=True)
     apps, total_count = apps.objects, apps.count
     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.view_num = EventBusiness.get_number({
             app.type: app,
             'action': "view"
         })
     return apps, total_count