Skip to content

Commit

Permalink
Merge branch 'alpha' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 8, 2023
2 parents e6a0789 + 161a74e commit 9ad2773
Show file tree
Hide file tree
Showing 31 changed files with 317 additions and 626 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8 as backend-dev
FROM python:3.10 as backend-dev
ENV PYTHONUNBUFFERED=1
RUN useradd -m -d /opt/spacedock -s /bin/bash spacedock
RUN pip3 install --upgrade pip setuptools wheel pip-licenses
Expand Down
21 changes: 5 additions & 16 deletions KerbalStuff/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,27 @@
import werkzeug.wrappers
from flask import Flask, render_template, g, url_for, Response, request
from flask_login import LoginManager, current_user
from flaskext.markdown import Markdown
from markupsafe import Markup
from werkzeug.exceptions import HTTPException, InternalServerError, NotFound
from flask.typing import ResponseReturnValue
from jinja2 import ChainableUndefined
from pymdownx.emoji import gemoji, to_alt

from .blueprints.accounts import accounts
from .blueprints.admin import admin
from .blueprints.anonymous import anonymous
from .blueprints.api import api
from .blueprints.blog import blog, get_all_announcement_posts, get_non_member_announcement_posts
from .blueprints.lists import lists
from .blueprints.login_oauth import list_defined_oauths, login_oauth
from .blueprints.mods import mods
from .blueprints.profile import profiles
from .middleware.session_interface import OnlyLoggedInSessionInterface
from .celery import update_from_github
from .common import first_paragraphs, many_paragraphs, json_output, jsonify_exception, dumb_object, sanitize_text
from .common import first_paragraphs, many_paragraphs, json_output, jsonify_exception, dumb_object, sanitize_text, markdown_renderer
from .config import _cfg, _cfgb, _cfgd, _cfgi, site_logger
from .custom_json import CustomJSONEncoder
from .database import db
from .helpers import is_admin, following_mod
from .kerbdown import KerbDown
from .objects import User, BlogPost
from .objects import User

app = Flask(__name__, template_folder='../templates')
# https://flask.palletsprojects.com/en/1.1.x/security/#set-cookie-options
Expand All @@ -59,15 +56,9 @@
app.jinja_env.filters['bleach'] = sanitize_text
app.jinja_env.auto_reload = app.debug
app.secret_key = _cfg("secret-key")
app.json_encoder = CustomJSONEncoder
app.json_encoder = CustomJSONEncoder # type: ignore[attr-defined]
app.session_interface = OnlyLoggedInSessionInterface()
Markdown(app, extensions=[KerbDown(), 'fenced_code', 'pymdownx.emoji'],
extension_configs={'pymdownx.emoji': {
# GitHub's emojis
'emoji_index': gemoji,
# Unicode output
'emoji_generator': to_alt
}})
app.jinja_env.filters['markdown'] = lambda md: Markup(markdown_renderer.convert(md))
login_manager = LoginManager(app)

prof_dir = _cfg('profile-dir')
Expand Down Expand Up @@ -95,7 +86,6 @@ def load_user(username: str) -> User:

app.register_blueprint(profiles)
app.register_blueprint(accounts)
app.register_blueprint(login_oauth)
app.register_blueprint(anonymous)
app.register_blueprint(blog)
app.register_blueprint(admin)
Expand Down Expand Up @@ -320,7 +310,6 @@ def inject() -> Dict[str, Any]:
'any': any,
'following_mod': following_mod,
'admin': is_admin(),
'oauth_providers': list_defined_oauths(),
'dumb_object': dumb_object,
'first_visit': first_visit,
'request': request,
Expand Down
4 changes: 3 additions & 1 deletion KerbalStuff/blueprints/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ def delete_user(user_id: int) -> Union[str, werkzeug.wrappers.Response]:
abort(404)
db.delete(user)
db.commit()
query = request.form.get('query', '')
return redirect(url_for('admin.users',
page=request.form.get('page', 1),
show_non_public=(request.form.get('show_non_public', '').lower() in TRUE_STR)))
show_non_public=(request.form.get('show_non_public', '').lower() in TRUE_STR),
query=query))


@admin.route("/admin/locked_mods/<int:page>")
Expand Down
4 changes: 3 additions & 1 deletion KerbalStuff/blueprints/anonymous.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
get_featured_mods, get_top_mods, get_new_mods, get_updated_mods, sendfile
from ..config import _cfg
from ..database import db
from ..objects import Featured, Mod, ModVersion, User
from ..objects import Featured, Mod, ModVersion, User, ModList
from ..search import apply_search_to_query

anonymous = Blueprint('anonymous', __name__)
Expand All @@ -29,6 +29,7 @@ def game(gameshort: str) -> str:
recent = get_updated_mods(ga.id, 6)
user_count = User.query.count()
mod_count = ga.mod_count()
pack_count = ModList.query.filter(ModList.game_id == ga.id, ModList.mods.any()).count()
following = sorted(filter(lambda m: m.game_id == ga.id, current_user.following),
key=lambda m: m.updated, reverse=True)[:6] if current_user else list()
return render_template("game.html",
Expand All @@ -41,6 +42,7 @@ def game(gameshort: str) -> str:
recent=recent,
user_count=user_count,
mod_count=mod_count,
pack_count=pack_count,
yours=following)


Expand Down
2 changes: 1 addition & 1 deletion KerbalStuff/blueprints/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def delete(username: str) -> Tuple[Dict[str, Any], int]:
if user == current_user:
logout_user()

return {"error": False}, 400
return {"error": False}, 200


@api.route('/api/mod/<int:mod_id>/update-bg', methods=['POST'])
Expand Down
Loading

0 comments on commit 9ad2773

Please sign in to comment.