def packages_page(): qb = QueryBuilder(request.args) query = qb.buildPackageQuery() title = qb.title if qb.lucky: package = query.first() if package: return redirect(package.getDetailsURL()) topic = qb.buildTopicQuery().first() if qb.search and topic: return redirect("https://forum.minetest.net/viewtopic.php?t=" + str(topic.topic_id)) page = int(request.args.get("page") or 1) num = min(40, int(request.args.get("n") or 100)) query = query.paginate(page, num, True) search = request.args.get("q") type_name = request.args.get("type") next_url = url_for("packages_page", type=type_name, q=search, page=query.next_num) \ if query.has_next else None prev_url = url_for("packages_page", type=type_name, q=search, page=query.prev_num) \ if query.has_prev else None topics = None if qb.search and not query.has_next: topics = qb.buildTopicQuery().all() tags = Tag.query.all() return render_template("packages/list.html", \ title=title, packages=query.items, topics=topics, \ query=search, tags=tags, type=type_name, \ next_url=next_url, prev_url=prev_url, page=page, page_max=query.pages, packages_count=query.total)
def topics(): qb = QueryBuilder(request.args) qb.setSortIfNone("date") query = qb.buildTopicQuery() tmp_q = ForumTopic.query if not qb.show_discarded: tmp_q = tmp_q.filter_by(discarded=False) total = tmp_q.count() topic_count = query.count() page = get_int_or_abort(request.args.get("page"), 1) num = get_int_or_abort(request.args.get("n"), 100) if num > 100 and not current_user.rank.atLeast(UserRank.EDITOR): num = 100 query = query.paginate(page, num, True) next_url = url_for("todo.topics", page=query.next_num, query=qb.search, \ show_discarded=qb.show_discarded, n=num, sort=qb.order_by) \ if query.has_next else None prev_url = url_for("todo.topics", page=query.prev_num, query=qb.search, \ show_discarded=qb.show_discarded, n=num, sort=qb.order_by) \ if query.has_prev else None return render_template("todo/topics.html", topics=query.items, total=total, \ topic_count=topic_count, query=qb.search, show_discarded=qb.show_discarded, \ next_url=next_url, prev_url=prev_url, page=page, page_max=query.pages, \ n=num, sort_by=qb.order_by)
def topics(): qb = QueryBuilder(request.args) query = qb.buildTopicQuery(show_added=True) return jsonify([t.getAsDictionary() for t in query.all()])
def list_all(): qb = QueryBuilder(request.args) query = qb.buildPackageQuery() title = qb.title query = query.options( joinedload(Package.license), joinedload(Package.media_license), subqueryload(Package.tags)) ip = request.headers.get("X-Forwarded-For") or request.remote_addr if ip is not None and not is_user_bot(): edited = False for tag in qb.tags: edited = True key = "tag/{}/{}".format(ip, tag.name) if not has_key(key): set_key(key, "true") Tag.query.filter_by(id=tag.id).update({ "views": Tag.views + 1 }) if edited: db.session.commit() if qb.lucky: package = query.first() if package: return redirect(package.getDetailsURL()) topic = qb.buildTopicQuery().first() if qb.search and topic: return redirect("https://forum.minetest.net/viewtopic.php?t=" + str(topic.topic_id)) page = get_int_or_abort(request.args.get("page"), 1) num = min(40, get_int_or_abort(request.args.get("n"), 100)) query = query.paginate(page, num, True) search = request.args.get("q") type_name = request.args.get("type") authors = [] if search: authors = User.query \ .filter(or_(*[func.lower(User.username) == name.lower().strip() for name in search.split(" ")])) \ .all() authors = [(author.username, search.lower().replace(author.username.lower(), "")) for author in authors] topics = None if qb.search and not query.has_next: qb.show_discarded = True topics = qb.buildTopicQuery().all() tags_query = db.session.query(func.count(Tags.c.tag_id), Tag) \ .select_from(Tag).join(Tags).join(Package).group_by(Tag.id).order_by(db.asc(Tag.title)) tags = qb.filterPackageQuery(tags_query).all() selected_tags = set(qb.tags) return render_template("packages/list.html", title=title, packages=query.items, pagination=query, query=search, tags=tags, selected_tags=selected_tags, type=type_name, authors=authors, packages_count=query.total, topics=topics)