def search(page=1, all_mods=False): _mods = None mod_search = ModSearch() mod_search.equip_regions.query = TF2EquipRegion.query.all() mod_search.bodygroups.query = TF2BodyGroup.query.all() mod_search.classes.choices = sort_classes_search(TF2Class.query.all()) mod_search.tags.query = Tag.query.all() search_submitted = any([all_mods, request.args]) if search_submitted: item_name = request.args.get('item_name') equip_regions = request.args.getlist('equip_regions') bodygroups = request.args.getlist('bodygroups') classes = request.args.getlist('classes') tags = request.args.getlist('tags') mod_search.item_name.data = item_name mod_search.equip_regions.data = equip_regions mod_search.bodygroups.data = bodygroups mod_search.classes.data = classes mod_search.tags.data = tags _mods = enabled_mods() wildcards = ["%", "_"] if item_name: if any([w in item_name for w in wildcards]): return _mods = _mods.filter(Mod.pretty_name.contains(item_name)) if equip_regions: _mods = _mods.filter(Mod.equip_regions.any(or_(*[TF2EquipRegion.equip_region == equip_region for equip_region in equip_regions]))) if bodygroups: _mods = _mods.filter(Mod.bodygroups.any(or_(*[TF2BodyGroup.bodygroup == bodygroup for bodygroup in bodygroups]))) if classes: sq = db.session.query(ModClassModel.mod_id, func.count(ModClassModel).label("class_count")).group_by(ModClassModel.mod_id).subquery() _mods = _mods.join(sq, Mod.id == sq.c.mod_id) if len(classes) == 9: pass elif len(classes) > 1: _mods = _mods.filter(sq.c.class_count > 1).filter(sq.c.class_count < 9) elif len(classes) == 1: _mods = _mods.filter(sq.c.class_count == 1) for class_name in classes: _mods = _mods.filter(Mod.class_model.any(ModClassModel.class_name == class_name)) if tags: _mods = _mods.filter(Mod.tags.any(or_(*[Tag.id == tag for tag in tags]))) _mods = _mods.paginate(page, 20) for mod in _mods.items: get_mod_stats(mod) return render_template('mods/search.html', mod_search=mod_search, searched=search_submitted, mods=_mods, title="Search")
def page(mod_id, page=1): mod = Mod.query.get_or_404(mod_id) check_mod_permissions(mod) mod_stats = get_mod_stats(mod, True) item_results = format_query(mod_stats.get("item_query"), mod.id, page) item_search_form = ItemSearch() classes = mod.class_model sorted_classes = sort_classes(classes) item_search_form.equip_regions.query = TF2EquipRegion.query.all() item_search_form.bodygroups.query = TF2BodyGroup.query.all() item_search_form.classes.choices = sorted_classes item_search_form.classes.data = [_class for _class in classes] item_search_form.bodygroups.data = [ bodygroup for bodygroup in mod.bodygroups ] item_search_form.equip_regions.data = [ equip_region for equip_region in mod.equip_regions ] return render_template('mods/page.html', mod=mod, mod_stats=mod_stats, item_search=item_search_form, mod_id=mod.id, item_results=item_results.get('items'), page=page, title=mod.pretty_name, sorted_classes=sorted_classes)
def tag(tag_id=None): tag_info = Tag.query.get(tag_id) if not tag_info: return abort(404) mods = enabled_mods().filter( Mod.tags.any(Tag.id == tag_id)).limit(18).all() for mod in mods: mod_stats = get_mod_stats(mod) return render_template('mods/tag.html', mods=mods, tag_info=tag_info, bg_num=tag_info.bg_num, tag_theme=tag_info.id if tag_info.css else None, title=tag_info.id.capitalize() + " tagged mods")
def page(mod_id, page=1): mod = Mod.query.get_or_404(mod_id) check_mod_permissions(mod) mod_stats = get_mod_stats(mod, True) item_results = format_query(mod_stats.get("item_query"), mod.id, page) item_search_form = ItemSearch() classes = mod.class_model sorted_classes = sort_classes(classes) item_search_form.equip_regions.query = TF2EquipRegion.query.all() item_search_form.bodygroups.query = TF2BodyGroup.query.all() item_search_form.classes.choices = sorted_classes item_search_form.classes.data = [_class for _class in classes] item_search_form.bodygroups.data = [bodygroup for bodygroup in mod.bodygroups] item_search_form.equip_regions.data = [equip_region for equip_region in mod.equip_regions] return render_template('mods/page.html', mod=mod, mod_stats=mod_stats, item_search=item_search_form, mod_id=mod.id, item_results=item_results.get('items'), page=page, title=mod.pretty_name, sorted_classes=sorted_classes)
def search(page=1, all_mods=False): _mods = None mod_search = ModSearch() mod_search.equip_regions.query = TF2EquipRegion.query.all() mod_search.bodygroups.query = TF2BodyGroup.query.all() mod_search.classes.choices = sort_classes_search(TF2Class.query.all()) mod_search.tags.query = Tag.query.all() search_submitted = any([all_mods, request.args]) if search_submitted: item_name = request.args.get('item_name') equip_regions = request.args.getlist('equip_regions') bodygroups = request.args.getlist('bodygroups') classes = request.args.getlist('classes') tags = request.args.getlist('tags') mod_search.item_name.data = item_name mod_search.equip_regions.data = equip_regions mod_search.bodygroups.data = bodygroups mod_search.classes.data = classes mod_search.tags.data = tags _mods = enabled_mods() wildcards = ["%", "_"] if item_name: if any([w in item_name for w in wildcards]): return _mods = _mods.filter(Mod.pretty_name.contains(item_name)) if equip_regions: _mods = _mods.filter( Mod.equip_regions.any( or_(*[ TF2EquipRegion.equip_region == equip_region for equip_region in equip_regions ]))) if bodygroups: _mods = _mods.filter( Mod.bodygroups.any( or_(*[ TF2BodyGroup.bodygroup == bodygroup for bodygroup in bodygroups ]))) if classes: sq = db.session.query( ModClassModel.mod_id, func.count(ModClassModel).label("class_count")).group_by( ModClassModel.mod_id).subquery() _mods = _mods.join(sq, Mod.id == sq.c.mod_id) if len(classes) == 9: pass elif len(classes) > 1: _mods = _mods.filter(sq.c.class_count > 1).filter( sq.c.class_count < 9) elif len(classes) == 1: _mods = _mods.filter(sq.c.class_count == 1) for class_name in classes: _mods = _mods.filter( Mod.class_model.any( ModClassModel.class_name == class_name)) if tags: _mods = _mods.filter( Mod.tags.any(or_(*[Tag.id == tag for tag in tags]))) _mods = _mods.paginate(page, 20) for mod in _mods.items: get_mod_stats(mod) return render_template('mods/search.html', mod_search=mod_search, searched=search_submitted, mods=_mods, title="Search")