示例#1
0
def package_scores():
    qb = QueryBuilder(request.args)
    query = qb.buildPackageQuery()

    pkgs = [{ "author": package.author.username, "name": package.name, "score": package.score } \
      for package in query.all()]
    return jsonify(pkgs)
示例#2
0
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)
示例#3
0
def tags():
	qb    = QueryBuilder(request.args)
	qb.setSortIfNone("score", "desc")
	query = qb.buildPackageQuery()

	tags = Tag.query.order_by(db.asc(Tag.title)).all()

	return render_template("todo/tags.html", packages=query.all(), tags=tags)
示例#4
0
def packages():
    qb = QueryBuilder(request.args)
    query = qb.buildPackageQuery()
    ver = qb.getMinetestVersion()

    pkgs = [package.getAsDictionaryShort(current_app.config["BASE_URL"], version=ver) \
      for package in query.all()]
    return jsonify([package for package in pkgs if package.get("release")])
示例#5
0
def api_packages_page():
    qb = QueryBuilder(request.args)
    query = qb.buildPackageQuery()
    ver = qb.getMinetestVersion()

    pkgs = [package.getAsDictionaryShort(app.config["BASE_URL"], version=ver) \
      for package in query.all()]
    return jsonify(pkgs)
示例#6
0
def packages():
    qb = QueryBuilder(request.args)
    query = qb.buildPackageQuery()

    if request.args.get("fmt") == "keys":
        return jsonify(
            [package.getAsDictionaryKey() for package in query.all()])

    pkgs = qb.convertToDictionary(query.all())
    if "engine_version" in request.args or "protocol_version" in request.args:
        pkgs = [package for package in pkgs if package.get("release")]
    return jsonify(pkgs)
示例#7
0
def tags():
    qb = QueryBuilder(request.args)
    qb.setSortIfNone("score", "desc")
    query = qb.buildPackageQuery()

    only_no_tags = isYes(request.args.get("no_tags"))
    if only_no_tags:
        query = query.filter(Package.tags == None)

    tags = Tag.query.order_by(db.asc(Tag.title)).all()

    return render_template("todo/tags.html", current_tab="tags", packages=query.all(), \
      tags=tags, only_no_tags=only_no_tags)
示例#8
0
def package_scores():
    qb = QueryBuilder(request.args)
    query = qb.buildPackageQuery()

    pkgs = [package.getScoreDict() for package in query.all()]
    return jsonify(pkgs)
示例#9
0
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)