mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 14:37:36 +01:00
parent
ca3436be0c
commit
785c931890
@ -198,3 +198,16 @@ def set_locale():
|
|||||||
models.db.session.commit()
|
models.db.session.commit()
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/set-nonfree/", methods=["POST"])
|
||||||
|
def set_nonfree():
|
||||||
|
resp = redirect(url_for("homepage.home"))
|
||||||
|
if request.cookies.get("hide_nonfree") == "1":
|
||||||
|
resp.set_cookie("hide_nonfree", "0", expires=0)
|
||||||
|
else:
|
||||||
|
expire_date = datetime.datetime.now()
|
||||||
|
expire_date = expire_date + datetime.timedelta(days=5*365)
|
||||||
|
resp.set_cookie("hide_nonfree", "1", expires=expire_date)
|
||||||
|
|
||||||
|
return resp
|
||||||
|
@ -49,7 +49,7 @@ from app.utils import is_user_bot, get_int_or_abort, is_package_page, abs_url_fo
|
|||||||
|
|
||||||
@bp.route("/packages/")
|
@bp.route("/packages/")
|
||||||
def list_all():
|
def list_all():
|
||||||
qb = QueryBuilder(request.args)
|
qb = QueryBuilder(request.args, cookies=True)
|
||||||
query = qb.build_package_query()
|
query = qb.build_package_query()
|
||||||
title = qb.title
|
title = qb.title
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ def view_editor():
|
|||||||
@bp.route("/todo/topics/")
|
@bp.route("/todo/topics/")
|
||||||
@login_required
|
@login_required
|
||||||
def topics():
|
def topics():
|
||||||
qb = QueryBuilder(request.args)
|
qb = QueryBuilder(request.args, cookies=True)
|
||||||
qb.set_sort_if_none("date")
|
qb.set_sort_if_none("date")
|
||||||
query = qb.build_topic_query()
|
query = qb.build_topic_query()
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ def topics():
|
|||||||
@bp.route("/todo/tags/")
|
@bp.route("/todo/tags/")
|
||||||
@login_required
|
@login_required
|
||||||
def tags():
|
def tags():
|
||||||
qb = QueryBuilder(request.args)
|
qb = QueryBuilder(request.args, cookies=True)
|
||||||
qb.set_sort_if_none("score", "desc")
|
qb.set_sort_if_none("score", "desc")
|
||||||
query = qb.build_package_query()
|
query = qb.build_package_query()
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from flask import abort, current_app
|
from flask import abort, current_app, request
|
||||||
from flask_babel import lazy_gettext
|
from flask_babel import lazy_gettext
|
||||||
from sqlalchemy import or_
|
from sqlalchemy import or_
|
||||||
from sqlalchemy.orm import subqueryload
|
from sqlalchemy.orm import subqueryload
|
||||||
@ -55,7 +55,7 @@ class QueryBuilder:
|
|||||||
return (self.search is not None or len(self.tags) > 1 or len(self.types) > 1 or len(self.hide_flags) > 0 or
|
return (self.search is not None or len(self.tags) > 1 or len(self.types) > 1 or len(self.hide_flags) > 0 or
|
||||||
self.random or self.lucky or self.author or self.version or self.game)
|
self.random or self.lucky or self.author or self.version or self.game)
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args, cookies=False):
|
||||||
|
|
||||||
# Get request types
|
# Get request types
|
||||||
types = args.getlist("type")
|
types = args.getlist("type")
|
||||||
@ -120,6 +120,9 @@ class QueryBuilder:
|
|||||||
if self.game:
|
if self.game:
|
||||||
self.game = Package.get_by_key(self.game)
|
self.game = Package.get_by_key(self.game)
|
||||||
|
|
||||||
|
if cookies and request.cookies.get("hide_nonfree") == "1":
|
||||||
|
self.hide_nonfree = True
|
||||||
|
|
||||||
def set_sort_if_none(self, name, dir="desc"):
|
def set_sort_if_none(self, name, dir="desc"):
|
||||||
if self.order_by is None:
|
if self.order_by is None:
|
||||||
self.order_by = name
|
self.order_by = name
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from flask import request
|
||||||
from flask_babel import format_timedelta, gettext
|
from flask_babel import format_timedelta, gettext
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from markupsafe import Markup
|
from markupsafe import Markup
|
||||||
@ -29,8 +30,8 @@ from .utils.minetest_hypertext import normalize_whitespace as do_normalize_white
|
|||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_debug():
|
def inject_misc():
|
||||||
return dict(debug=app.debug)
|
return dict(debug=app.debug, hide_nonfree=request.cookies.get("hide_nonfree") == "1")
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
|
@ -269,6 +269,15 @@
|
|||||||
<li class="list-inline-item"><a href="https://github.com/minetest/contentdb">{{ _("Source Code") }}</a></li>
|
<li class="list-inline-item"><a href="https://github.com/minetest/contentdb">{{ _("Source Code") }}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<form method="POST" action="{{ url_for('set_nonfree') }}" class="my-3">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||||
|
{% if hide_nonfree %}
|
||||||
|
<input type="submit" class="btn btn-sm btn-secondary" value="{{ _('Show non-free packages') }}">
|
||||||
|
{% else %}
|
||||||
|
<input type="submit" class="btn btn-sm btn-secondary" value="{{ _('Hide non-free packages') }}">
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
|
||||||
{% if debug %}
|
{% if debug %}
|
||||||
<p style="color: red">
|
<p style="color: red">
|
||||||
DEBUG MODE ENABLED
|
DEBUG MODE ENABLED
|
||||||
|
Loading…
Reference in New Issue
Block a user