Coverage for otaku_info/routes/external_service.py: 52%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of otaku-info.
6otaku-info is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11otaku-info is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with otaku-info. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from flask import request, redirect, url_for
21from flask.blueprints import Blueprint
22from flask_login import login_required, current_user
23from jerrycan.base import db
24from otaku_info.enums import ListService
25from otaku_info.db.ServiceUsername import ServiceUsername
28def define_blueprint(blueprint_name: str) -> Blueprint:
29 """
30 Defines the blueprint for this route
31 :param blueprint_name: The name of the blueprint
32 :return: The blueprint
33 """
34 blueprint = Blueprint(blueprint_name, __name__)
36 @blueprint.route("/set_service_username", methods=["POST"])
37 @login_required
38 def set_service_username():
39 """
40 Sets an exernal service username for the current user
41 :return:
42 """
43 username = request.form["username"]
44 service = ListService(request.form["service"])
46 service_username: ServiceUsername = ServiceUsername.query\
47 .filter_by(user=current_user, service=service).first()
48 if service_username is None:
49 service_username = ServiceUsername(
50 user=current_user, username=username, service=service
51 )
52 db.session.add(service_username)
53 else:
54 service_username.username = username
56 db.session.commit()
57 return redirect(url_for("user_management.profile"))
59 return blueprint