mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 09:22:38 +02:00
use a dict for project list
this avoid finding duplicates, and we only need id -> name also, use a common function to avoid duplicate code fix #1081
This commit is contained in:
parent
cc18986b76
commit
dc40c8fc14
2 changed files with 18 additions and 20 deletions
|
@ -105,10 +105,10 @@
|
|||
<li><a class="dropdown-item" href="{{ url_for("main.edit_project") }}">{{ _("Settings") }}</a></li>
|
||||
{% endif %}
|
||||
|
||||
{% if session['projects'] and not ((session['projects'] | length) == 1 and g.project and session['projects'][0][0] == g.project.id) %}
|
||||
{% if session['projects'] and not ((session['projects'] | length) == 1 and g.project and g.project.id in session['projects']) %}
|
||||
<li class="dropdown-divider"></li>
|
||||
<li class="dropdown-header">{{ _('Other projects :') }}</li>
|
||||
{% for id, name in session['projects'] %}
|
||||
{% for id, name in session['projects'].items() %}
|
||||
{% if not g.project or id != g.project.id %}
|
||||
<li><a class="dropdown-item" href="{{ url_for("main.list_bills", project_id=id) }}">{{ _("switch to") }} {{ name }}</a></li>
|
||||
{% endif %}
|
||||
|
|
|
@ -205,6 +205,20 @@ def admin():
|
|||
)
|
||||
|
||||
|
||||
def set_authorized_project(project: Project):
|
||||
# maintain a list of visited projects
|
||||
new_project = {project.id: project.name}
|
||||
if "projects" not in session:
|
||||
session["projects"] = new_project
|
||||
else:
|
||||
# add the project on the top of the list
|
||||
session["projects"] = {**new_project, **session["projects"]}
|
||||
session[project.id] = True
|
||||
# Set session to permanent to make language choice persist
|
||||
session.permanent = True
|
||||
session.update()
|
||||
|
||||
|
||||
@main.route("/<project_id>/join/<string:token>", methods=["GET"])
|
||||
def join_project(token):
|
||||
project_id = g.project.id
|
||||
|
@ -215,15 +229,7 @@ def join_project(token):
|
|||
flash(_("Provided token is invalid"), "danger")
|
||||
return redirect("/")
|
||||
|
||||
# maintain a list of visited projects
|
||||
if "projects" not in session:
|
||||
session["projects"] = []
|
||||
# add the project on the top of the list
|
||||
session["projects"].insert(0, (project_id, g.project.name))
|
||||
session[project_id] = True
|
||||
# Set session to permanent to make language choice persist
|
||||
session.permanent = True
|
||||
session.update()
|
||||
set_authorized_project(g.project)
|
||||
return redirect(url_for(".list_bills"))
|
||||
|
||||
|
||||
|
@ -252,15 +258,7 @@ def authenticate(project_id=None):
|
|||
# else do form authentication authentication
|
||||
is_post_auth = request.method == "POST" and form.validate()
|
||||
if is_post_auth and check_password_hash(project.password, form.password.data):
|
||||
# maintain a list of visited projects
|
||||
if "projects" not in session:
|
||||
session["projects"] = []
|
||||
# add the project on the top of the list
|
||||
session["projects"].insert(0, (project_id, project.name))
|
||||
session[project_id] = True
|
||||
# Set session to permanent to make language choice persist
|
||||
session.permanent = True
|
||||
session.update()
|
||||
set_authorized_project(project)
|
||||
setattr(g, "project", project)
|
||||
return redirect(url_for(".list_bills"))
|
||||
if is_post_auth and not check_password_hash(project.password, form.password.data):
|
||||
|
|
Loading…
Reference in a new issue