number poll candidates depending on setting

This commit is contained in:
Joshua Sangmeister 2020-01-29 16:13:05 +01:00 committed by FinnStutzenstein
parent e2585fb757
commit b16afaa285
9 changed files with 32 additions and 14 deletions

View File

@ -154,7 +154,7 @@ export class ListOfSpeakersComponent extends BaseViewComponent implements OnInit
private config: ConfigService
) {
super(title, translate, snackBar);
this.addSpeakerForm = new FormGroup({ user_id: new FormControl([]) });
this.addSpeakerForm = new FormGroup({ user_id: new FormControl() });
}
/**
@ -201,6 +201,7 @@ export class ListOfSpeakersComponent extends BaseViewComponent implements OnInit
}
})
);
this.subscriptions.push(
this.config.get('agenda_present_speakers_only').subscribe(() => {
this.filterUsers();

View File

@ -142,7 +142,7 @@
<os-sorting-list
[input]="assignment.assignment_related_users"
[live]="true"
[count]="true"
[count]="assignment.number_poll_candidates"
[enable]="hasPerms('addOthers')"
(sortEvent)="onSortingChange($event)"
>

View File

@ -64,7 +64,7 @@ class AgendaAppConfig(AppConfig):
yield self.get_model("ListOfSpeakers")
def required_users(element: Dict[str, Any]) -> Set[int]:
async def required_users(element: Dict[str, Any]) -> Set[int]:
"""
Returns all user ids that are displayed as speaker in the given element.
"""

View File

@ -72,16 +72,26 @@ class AssignmentsAppConfig(AppConfig):
yield self.get_model(model_name)
def required_users(element: Dict[str, Any]) -> Set[int]:
async def required_users(element: Dict[str, Any]) -> Set[int]:
"""
Returns all user ids that are displayed as candidates (including poll
options) in the assignment element.
TODO: Adapt this method for new poll structure!!
"""
from openslides.assignments.models import AssignmentPoll, AssignmentOption
from openslides.utils.cache import element_cache
candidates = set(
related_user["user_id"] for related_user in element["assignment_related_users"]
)
for poll in element["polls"]:
candidates.update(option["candidate_id"] for option in poll["options"])
for poll_id in element["polls_id"]:
poll = await element_cache.get_element_data(
AssignmentPoll.get_collection_string(), poll_id
)
if poll:
for option_id in poll["options_id"]:
option = await element_cache.get_element_data(
AssignmentOption.get_collection_string(), option_id
)
if option:
candidates.add(option["user_id"])
return candidates

View File

@ -86,6 +86,7 @@ class AssignmentManager(BaseManager):
"lists_of_speakers",
"tags",
"attachments",
"polls",
)
)

View File

@ -9,6 +9,7 @@ from openslides.poll.serializers import (
from openslides.utils.rest_api import (
BooleanField,
DecimalField,
IdPrimaryKeyRelatedField,
IntegerField,
ModelSerializer,
ValidationError,
@ -150,6 +151,7 @@ class AssignmentSerializer(ModelSerializer):
write_only=True, required=False, min_value=1, max_value=3, allow_null=True
)
agenda_parent_id = IntegerField(write_only=True, required=False, min_value=1)
polls = IdPrimaryKeyRelatedField(many=True, read_only=True)
class Meta:
model = Assignment
@ -169,6 +171,7 @@ class AssignmentSerializer(ModelSerializer):
"tags",
"attachments",
"number_poll_candidates",
"polls",
)
validators = (posts_validator,)

View File

@ -107,7 +107,7 @@ class MotionsAppConfig(AppConfig):
yield self.get_model(model_name)
def required_users(element: Dict[str, Any]) -> Set[int]:
async def required_users(element: Dict[str, Any]) -> Set[int]:
"""
Returns all user ids that are displayed as as submitter or supporter in
any motion if request_user can see motions. This function may return an

View File

@ -1,4 +1,4 @@
from typing import Any, Callable, Dict, List, Set
from typing import Any, Callable, Coroutine, Dict, List, Set
from asgiref.sync import async_to_sync
@ -59,7 +59,7 @@ class RequiredUsers:
Helper class to find all users that are required by another element.
"""
callables: Dict[str, Callable[[Dict[str, Any]], Set[int]]] = {}
callables: Dict[str, Callable[[Dict[str, Any]], Coroutine[Any, Any, Set[int]]]] = {}
def get_collection_strings(self) -> Set[str]:
"""
@ -68,7 +68,9 @@ class RequiredUsers:
return set(self.callables.keys())
def add_collection_string(
self, collection_string: str, callable: Callable[[Dict[str, Any]], Set[int]]
self,
collection_string: str,
callable: Callable[[Dict[str, Any]], Coroutine[Any, Any, Set[int]]],
) -> None:
"""
Add a callable for a collection_string to get the required users of the
@ -94,7 +96,7 @@ class RequiredUsers:
continue
for element in collection_data.values():
user_ids.update(get_user_ids(element))
user_ids.update(await get_user_ids(element))
return user_ids

View File

@ -23,6 +23,7 @@ def test_assignment_db_queries():
* 1 request to get the list of speakers,
* 1 request to get the tags,
* 1 request to get the attachments and
* 1 Request to get the polls of the assignment
"""
for index in range(10):
assignment = Assignment.objects.create(title=f"assignment{index}", open_posts=1)
@ -34,7 +35,7 @@ def test_assignment_db_queries():
type=AssignmentPoll.TYPE_NAMED,
)
assert count_queries(Assignment.get_elements)() == 6
assert count_queries(Assignment.get_elements)() == 7
class CreateAssignment(TestCase):