2020-05-15 11:47:43 +02:00
|
|
|
from typing import Any, Dict, List, Optional
|
2017-08-30 00:07:54 +02:00
|
|
|
|
2019-01-26 20:37:49 +01:00
|
|
|
from ..utils.projector import (
|
2020-05-15 11:47:43 +02:00
|
|
|
ProjectorAllDataProvider,
|
|
|
|
get_model,
|
2019-01-26 20:37:49 +01:00
|
|
|
register_projector_slide,
|
|
|
|
)
|
2015-02-18 01:45:39 +01:00
|
|
|
|
|
|
|
|
2019-03-23 12:06:57 +01:00
|
|
|
async def user_slide(
|
2020-05-15 11:47:43 +02:00
|
|
|
all_data_provider: ProjectorAllDataProvider,
|
|
|
|
element: Dict[str, Any],
|
|
|
|
projector_id: int,
|
2019-02-21 14:40:07 +01:00
|
|
|
) -> Dict[str, Any]:
|
2018-12-23 11:05:38 +01:00
|
|
|
"""
|
|
|
|
User slide.
|
2019-01-26 20:37:49 +01:00
|
|
|
|
|
|
|
The returned dict can contain the following fields:
|
|
|
|
* user
|
2018-12-23 11:05:38 +01:00
|
|
|
"""
|
2020-05-15 11:47:43 +02:00
|
|
|
return {"user": await get_user_name(all_data_provider, element.get("id"))}
|
2015-06-12 21:08:57 +02:00
|
|
|
|
2017-08-30 00:07:54 +02:00
|
|
|
|
2020-05-15 11:47:43 +02:00
|
|
|
async def get_user_name(
|
|
|
|
all_data_provider: ProjectorAllDataProvider, user_id: Optional[int]
|
|
|
|
) -> str:
|
2019-01-27 13:17:17 +01:00
|
|
|
"""
|
|
|
|
Returns the short name for an user_id.
|
|
|
|
"""
|
2020-05-15 11:47:43 +02:00
|
|
|
user = await get_model(all_data_provider, "users/user", user_id)
|
2019-02-15 12:17:08 +01:00
|
|
|
|
2019-01-27 13:17:17 +01:00
|
|
|
name_parts: List[str] = []
|
|
|
|
for name_part in ("title", "first_name", "last_name"):
|
|
|
|
if user[name_part]:
|
|
|
|
name_parts.append(user[name_part])
|
2020-11-18 08:14:33 +01:00
|
|
|
if not name_parts:
|
2019-01-27 13:17:17 +01:00
|
|
|
name_parts.append(user["username"])
|
|
|
|
if user["structure_level"]:
|
|
|
|
name_parts.append(f"({user['structure_level']})")
|
|
|
|
return " ".join(name_parts)
|
|
|
|
|
|
|
|
|
|
|
|
def register_projector_slides() -> None:
|
|
|
|
register_projector_slide("users/user", user_slide)
|