2019-04-23 15:04:38 +02:00
|
|
|
from typing import Any, Dict, List
|
2017-08-30 00:07:54 +02:00
|
|
|
|
2019-04-23 15:04:38 +02:00
|
|
|
from ..users.projector import get_user_name
|
2020-05-15 11:47:43 +02:00
|
|
|
from ..utils.projector import (
|
|
|
|
ProjectorAllDataProvider,
|
|
|
|
get_model,
|
|
|
|
get_models,
|
|
|
|
register_projector_slide,
|
|
|
|
)
|
2019-11-20 17:09:03 +01:00
|
|
|
from .models import AssignmentPoll
|
2015-06-24 22:11:54 +02:00
|
|
|
|
|
|
|
|
2019-03-23 12:06:57 +01:00
|
|
|
async def assignment_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
|
|
|
"""
|
|
|
|
Assignment slide.
|
|
|
|
"""
|
2020-05-15 11:47:43 +02:00
|
|
|
assignment = await get_model(
|
|
|
|
all_data_provider, "assignments/assignment", element.get("id")
|
|
|
|
)
|
2019-04-23 15:04:38 +02:00
|
|
|
|
|
|
|
assignment_related_users: List[Dict[str, Any]] = [
|
2020-05-15 11:47:43 +02:00
|
|
|
{"user": await get_user_name(all_data_provider, aru["user_id"])}
|
2019-04-23 15:04:38 +02:00
|
|
|
for aru in sorted(
|
|
|
|
assignment["assignment_related_users"], key=lambda aru: aru["weight"]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
return {
|
|
|
|
"title": assignment["title"],
|
|
|
|
"phase": assignment["phase"],
|
|
|
|
"open_posts": assignment["open_posts"],
|
|
|
|
"description": assignment["description"],
|
|
|
|
"assignment_related_users": assignment_related_users,
|
2020-02-14 16:44:06 +01:00
|
|
|
"number_poll_candidates": assignment["number_poll_candidates"],
|
2019-04-23 15:04:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-20 17:09:03 +01:00
|
|
|
async def assignment_poll_slide(
|
2020-05-15 11:47:43 +02:00
|
|
|
all_data_provider: ProjectorAllDataProvider,
|
|
|
|
element: Dict[str, Any],
|
|
|
|
projector_id: int,
|
2019-04-23 15:04:38 +02:00
|
|
|
) -> Dict[str, Any]:
|
|
|
|
"""
|
|
|
|
Poll slide.
|
|
|
|
"""
|
2020-05-15 11:47:43 +02:00
|
|
|
poll = await get_model(
|
|
|
|
all_data_provider, "assignments/assignment-poll", element.get("id")
|
|
|
|
)
|
|
|
|
assignment = await get_model(
|
|
|
|
all_data_provider, "assignments/assignment", poll["assignment_id"]
|
|
|
|
)
|
2019-11-20 17:09:03 +01:00
|
|
|
|
|
|
|
poll_data = {
|
|
|
|
key: poll[key]
|
|
|
|
for key in (
|
|
|
|
"title",
|
|
|
|
"type",
|
|
|
|
"pollmethod",
|
|
|
|
"votes_amount",
|
|
|
|
"description",
|
|
|
|
"state",
|
|
|
|
"onehundred_percent_base",
|
|
|
|
"majority_method",
|
|
|
|
)
|
|
|
|
}
|
2019-04-23 15:04:38 +02:00
|
|
|
|
2019-11-20 17:09:03 +01:00
|
|
|
# Add options:
|
|
|
|
poll_data["options"] = []
|
2020-05-15 11:47:43 +02:00
|
|
|
options = await get_models(
|
|
|
|
all_data_provider, "assignments/assignment-option", poll["options_id"]
|
|
|
|
)
|
2020-02-13 18:24:51 +01:00
|
|
|
for option in sorted(options, key=lambda option: option["weight"]):
|
|
|
|
option_data: Dict[str, Any] = {
|
2020-05-15 11:47:43 +02:00
|
|
|
"user": {
|
|
|
|
"short_name": await get_user_name(all_data_provider, option["user_id"])
|
|
|
|
}
|
2020-02-13 18:24:51 +01:00
|
|
|
}
|
2019-11-20 17:09:03 +01:00
|
|
|
if poll["state"] == AssignmentPoll.STATE_PUBLISHED:
|
2020-02-13 18:24:51 +01:00
|
|
|
option_data["yes"] = float(option["yes"])
|
|
|
|
option_data["no"] = float(option["no"])
|
|
|
|
option_data["abstain"] = float(option["abstain"])
|
2019-11-20 17:09:03 +01:00
|
|
|
poll_data["options"].append(option_data)
|
|
|
|
|
|
|
|
if poll["state"] == AssignmentPoll.STATE_PUBLISHED:
|
2020-11-23 18:37:00 +01:00
|
|
|
poll_data["amount_global_yes"] = (
|
|
|
|
float(poll["amount_global_yes"]) if poll["amount_global_yes"] else None
|
|
|
|
)
|
2020-02-13 18:24:51 +01:00
|
|
|
poll_data["amount_global_no"] = (
|
|
|
|
float(poll["amount_global_no"]) if poll["amount_global_no"] else None
|
|
|
|
)
|
|
|
|
poll_data["amount_global_abstain"] = (
|
2020-04-24 07:21:27 +02:00
|
|
|
float(poll["amount_global_abstain"])
|
|
|
|
if poll["amount_global_abstain"]
|
|
|
|
else None
|
2020-02-13 18:24:51 +01:00
|
|
|
)
|
|
|
|
poll_data["votesvalid"] = float(poll["votesvalid"])
|
|
|
|
poll_data["votesinvalid"] = float(poll["votesinvalid"])
|
|
|
|
poll_data["votescast"] = float(poll["votescast"])
|
2019-04-23 15:04:38 +02:00
|
|
|
|
|
|
|
return {
|
2019-11-20 17:09:03 +01:00
|
|
|
"assignment": {"title": assignment["title"]},
|
2019-04-23 15:04:38 +02:00
|
|
|
"poll": poll_data,
|
|
|
|
}
|
2017-08-30 00:07:54 +02:00
|
|
|
|
|
|
|
|
2019-01-27 13:17:17 +01:00
|
|
|
def register_projector_slides() -> None:
|
|
|
|
register_projector_slide("assignments/assignment", assignment_slide)
|
2019-11-20 17:09:03 +01:00
|
|
|
register_projector_slide("assignments/assignment-poll", assignment_poll_slide)
|