예제 #1
0
 def edit_form(self, obj=None):
     obj['categories'] = CategoryGame.game_category_ids(obj['_id'])
     form = super(GameAdmin, self).edit_form(obj)
     cids = Category.all_category_ids()
     categories = Category.get_list(cids)
     form.categories.choices = [(c._id, c.name) for c in categories]
     return form
예제 #2
0
 def edit_form(self, obj=None):
     form = super(CategoryGameAdmin, self).edit_form(obj)
     cids = Category.all_category_ids()
     categories = Category.get_list(cids)
     form.category.choices = [(c._id, c.name) for c in categories]
     form.game.choices = Game.online_games()
     return form
예제 #3
0
def migu_home():
    """获取首页信息 (GET)

    :uri: /migu/home/
    :returns: {'popular': list, 'whats_new': list,
              'hottest_of_today': list, 'recommend': list, 'tags': list}
    """
    ret = dict()
    ret['popular'] = []
    ret['whats_new'] = []
    ret['hottest_of_today'] = []
    ret['recommend'] = []

    tags = []
    cids = Category.all_category_ids()
    categories = Category.get_list(cids)
    for category in categories:
        gids = CategoryGame.category_game_ids(str(category._id))
        games = [g.format() for g in Game.get_list(gids)]
        tags.append(
            dict(games=games, tag_id=str(category._id), name=category.name))

    ret['tags'] = tags

    return ret
예제 #4
0
def migu_all_tags():
    """获取所有标签 (GET)

    :uri: /migu/tags/home/
    :returns: {'tags': list}
    """
    cids = Category.all_category_ids()
    categories = Category.get_list(cids)
    tags = [{str(c._id): c.name} for c in categories]
    return {'tags': tags}
예제 #5
0
class OfflineGameAdmin(WxModelView):
    Model = Game
    form = OfflineGameForm
    _can_create = False
    column_details_list = [
        '_id', 'name', 'url', 'bid', 'package_id', 'version', 'size', 'cover',
        'icon', 'big_icon', 'status'
    ]
    column_list = ('_id', 'name', 'cover', 'icon', 'big_icon', 'status')
    column_labels = dict(_id=u'游戏ID',
                         name=u'游戏名',
                         url=u'下载链接',
                         bid=u'咪咕平台游戏ID',
                         package_id=u'软件包ID',
                         version=u'版本号',
                         size=u'包大小(M)',
                         cover=u'封面图片',
                         icon=u'图标',
                         big_icon=u'大图标',
                         status=u'状态')
    column_formatters = dict(
        _id=format_game,
        icon=format_image,
        big_icon=format_image,
        cover=format_image,
        status=format_choices,
    )
    cids = Category.all_category_ids()
    categories = Category.get_list(cids)
    categories_list = list()
    categories_list.append(('', ''))
    for c in range(len(categories)):
        a_ = str(categories[c]._id)
        b_ = categories[c].name
        categories_list.append((a_, b_))

    column_filters = (EqualFilter('_id', u'游戏ID',
                                  ObjectId), LikeFilter('name', u'游戏名'),
                      CategoryFileter('_id', u'游戏类型', str, categories_list))

    def get_list(self, *args, **kwargs):
        self._filters.append(EqualFilter('status', '', int))
        args[4].append((-1, '', 1))
        count, data = super(OfflineGameAdmin, self).get_list(*args, **kwargs)
        self._filters.pop(-1)
        args[4].pop(-1)
        return count, data
예제 #6
0
def channel_game():
    """获取频道内容 (GET)

    :uri: /channels/games
    :returns: [{'tag_id': string, 'name': string, 'games': list}, ...]
    """
    ret = list()
    cids = Category.all_category_ids()
    categories = Category.get_list(cids)
    for category in categories:
        gids = CategoryGame.category_game_ids(str(category._id))
        games = [
            g.format(exclude_fields=['subscribed'])
            for g in Game.get_list(gids)
        ]
        ret.append(
            dict(games=games,
                 tag_id=str(category._id),
                 name=category.name,
                 icon_type=category.icon_type or 'icon'))
    return ret
예제 #7
0
def format_category(view, context, model, name):
    model = model if isinstance(model, dict) else model_to_dict(model)
    _value = model.get(name, None)
    obj = Category.get_one(str(_value), check_online=False)
    if obj:
        _value = '%s (%s)' % (obj.name, _value)
        html = u'<a href="/admin/categoryview/?flt1_0=%s">%s</a>' % (str(
            obj._id), _value)
        _value = widgets.HTMLString(html)
    else:
        _value = u'分类不存在'
    return _value
예제 #8
0
 def create_form(self, obj=None):
     form = super(GameAdmin, self).create_form(obj)
     cids = Category.all_category_ids()
     categories = Category.get_list(cids)
     form.categories.choices = [(c._id, c.name) for c in categories]
     return form