From fa63ef030706c131472c09c39af6db5251b369cd Mon Sep 17 00:00:00 2001 From: Joshua Sangmeister Date: Wed, 13 May 2020 11:27:45 +0200 Subject: [PATCH] added config for default poll type --- .../services/assignment-poll.service.ts | 5 +++- .../motions/services/motion-poll.service.ts | 5 +++- .../app/site/polls/services/poll.service.ts | 7 +++++- openslides/assignments/config_variables.py | 19 +++++++++++--- .../0013_rename_verbose_poll_types.py | 25 +++++++++++++++++++ openslides/motions/config_variables.py | 17 +++++++++++-- .../0036_rename_verbose_poll_types.py | 25 +++++++++++++++++++ openslides/poll/models.py | 6 ++--- 8 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 openslides/assignments/migrations/0013_rename_verbose_poll_types.py create mode 100644 openslides/motions/migrations/0036_rename_verbose_poll_types.py diff --git a/client/src/app/site/assignments/services/assignment-poll.service.ts b/client/src/app/site/assignments/services/assignment-poll.service.ts index cb9e22188..ec7dd8d81 100644 --- a/client/src/app/site/assignments/services/assignment-poll.service.ts +++ b/client/src/app/site/assignments/services/assignment-poll.service.ts @@ -10,7 +10,7 @@ import { AssignmentPollMethod, AssignmentPollPercentBase } from 'app/shared/models/assignments/assignment-poll'; -import { MajorityMethod, VOTE_UNDOCUMENTED } from 'app/shared/models/poll/base-poll'; +import { MajorityMethod, PollType, VOTE_UNDOCUMENTED } from 'app/shared/models/poll/base-poll'; import { ParsePollNumberPipe } from 'app/shared/pipes/parse-poll-number.pipe'; import { PollKeyVerbosePipe } from 'app/shared/pipes/poll-key-verbose.pipe'; import { @@ -41,6 +41,8 @@ export class AssignmentPollService extends PollService { public defaultPollMethod: AssignmentPollMethod; + public defaultPollType: PollType; + private sortByVote: boolean; /** @@ -66,6 +68,7 @@ export class AssignmentPollService extends PollService { config .get(AssignmentPoll.defaultPollMethodConfig) .subscribe(method => (this.defaultPollMethod = method)); + config.get('assignment_poll_default_type').subscribe(type => (this.defaultPollType = type)); config.get('assignment_poll_sort_poll_result_by_votes').subscribe(sort => (this.sortByVote = sort)); } diff --git a/client/src/app/site/motions/services/motion-poll.service.ts b/client/src/app/site/motions/services/motion-poll.service.ts index f96f0acc1..276f7ef5f 100644 --- a/client/src/app/site/motions/services/motion-poll.service.ts +++ b/client/src/app/site/motions/services/motion-poll.service.ts @@ -6,7 +6,7 @@ import { ConstantsService } from 'app/core/core-services/constants.service'; import { MotionPollRepositoryService } from 'app/core/repositories/motions/motion-poll-repository.service'; import { ConfigService } from 'app/core/ui-services/config.service'; import { MotionPoll, MotionPollMethod } from 'app/shared/models/motions/motion-poll'; -import { MajorityMethod, PercentBase } from 'app/shared/models/poll/base-poll'; +import { MajorityMethod, PercentBase, PollType } from 'app/shared/models/poll/base-poll'; import { ParsePollNumberPipe } from 'app/shared/pipes/parse-poll-number.pipe'; import { PollKeyVerbosePipe } from 'app/shared/pipes/poll-key-verbose.pipe'; import { PollData, PollService, PollTableData, VotingResult } from 'app/site/polls/services/poll.service'; @@ -38,6 +38,8 @@ export class MotionPollService extends PollService { public defaultGroupIds: number[]; + public defaultPollType: PollType; + /** * Constructor. Subscribes to the configuration values needed * @param config ConfigService @@ -57,6 +59,7 @@ export class MotionPollService extends PollService { config .get('motion_poll_default_majority_method') .subscribe(method => (this.defaultMajorityMethod = method)); + config.get('motion_poll_default_type').subscribe(type => (this.defaultPollType = type)); config.get(MotionPoll.defaultGroupsConfig).subscribe(ids => (this.defaultGroupIds = ids)); } diff --git a/client/src/app/site/polls/services/poll.service.ts b/client/src/app/site/polls/services/poll.service.ts index ecc594769..fc5e29307 100644 --- a/client/src/app/site/polls/services/poll.service.ts +++ b/client/src/app/site/polls/services/poll.service.ts @@ -178,6 +178,11 @@ export abstract class PollService { */ public abstract defaultGroupIds: number[]; + /** + * The default poll type + */ + public abstract defaultPollType: PollType; + /** * The majority method currently in use */ @@ -227,7 +232,7 @@ export abstract class PollService { onehundred_percent_base: this.defaultPercentBase, majority_method: this.defaultMajorityMethod, groups_id: this.defaultGroupIds, - type: PollType.Analog + type: this.defaultPollType }; } diff --git a/openslides/assignments/config_variables.py b/openslides/assignments/config_variables.py index 64b7f12e0..65903edc5 100644 --- a/openslides/assignments/config_variables.py +++ b/openslides/assignments/config_variables.py @@ -13,7 +13,7 @@ def get_config_variables(): # Voting yield ConfigVariable( name="assignment_poll_method", - default_value="votes", + default_value=AssignmentPoll.POLLMETHOD_VOTES, input_type="choice", label="Default election method", choices=tuple( @@ -25,9 +25,22 @@ def get_config_variables(): subgroup="Ballot", ) + yield ConfigVariable( + name="assignment_poll_default_type", + default_value=AssignmentPoll.TYPE_ANALOG, + input_type="choice", + label="Default type for assignment polls", + choices=tuple( + {"value": type[0], "display_name": type[1]} for type in AssignmentPoll.TYPES + ), + weight=403, + group="Elections", + subgroup="Ballot", + ) + yield ConfigVariable( name="assignment_poll_default_100_percent_base", - default_value="valid", + default_value=AssignmentPoll.PERCENT_BASE_VALID, input_type="choice", label="Default 100 % base of an election result", choices=tuple( @@ -51,7 +64,7 @@ def get_config_variables(): yield ConfigVariable( name="assignment_poll_default_majority_method", - default_value="simple", + default_value=AssignmentPoll.MAJORITY_SIMPLE, input_type="choice", choices=tuple( {"value": method[0], "display_name": method[1]} diff --git a/openslides/assignments/migrations/0013_rename_verbose_poll_types.py b/openslides/assignments/migrations/0013_rename_verbose_poll_types.py new file mode 100644 index 000000000..9901eab14 --- /dev/null +++ b/openslides/assignments/migrations/0013_rename_verbose_poll_types.py @@ -0,0 +1,25 @@ +# Generated by Django 2.2.9 on 2020-05-13 09:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("assignments", "0012_assignment_vote_unique_together"), + ] + + operations = [ + migrations.AlterField( + model_name="assignmentpoll", + name="type", + field=models.CharField( + choices=[ + ("analog", "analog"), + ("named", "nominal"), + ("pseudoanonymous", "non-nominal"), + ], + max_length=64, + ), + ), + ] diff --git a/openslides/motions/config_variables.py b/openslides/motions/config_variables.py index f9761aa3c..ec66b6b4b 100644 --- a/openslides/motions/config_variables.py +++ b/openslides/motions/config_variables.py @@ -331,9 +331,22 @@ def get_config_variables(): # Voting and ballot papers + yield ConfigVariable( + name="motion_poll_default_type", + default_value=MotionPoll.TYPE_ANALOG, + input_type="choice", + label="Default type for motion polls", + choices=tuple( + {"value": type[0], "display_name": type[1]} for type in MotionPoll.TYPES + ), + weight=367, + group="Motions", + subgroup="Voting and ballot papers", + ) + yield ConfigVariable( name="motion_poll_default_100_percent_base", - default_value="YNA", + default_value=MotionPoll.PERCENT_BASE_YNA, input_type="choice", label="Default 100 % base of a voting result", choices=tuple( @@ -347,7 +360,7 @@ def get_config_variables(): yield ConfigVariable( name="motion_poll_default_majority_method", - default_value="simple", + default_value=MotionPoll.MAJORITY_SIMPLE, input_type="choice", choices=tuple( {"value": method[0], "display_name": method[1]} diff --git a/openslides/motions/migrations/0036_rename_verbose_poll_types.py b/openslides/motions/migrations/0036_rename_verbose_poll_types.py new file mode 100644 index 000000000..ef6120992 --- /dev/null +++ b/openslides/motions/migrations/0036_rename_verbose_poll_types.py @@ -0,0 +1,25 @@ +# Generated by Django 2.2.9 on 2020-05-13 09:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("motions", "0035_motion_vote_unique_together"), + ] + + operations = [ + migrations.AlterField( + model_name="motionpoll", + name="type", + field=models.CharField( + choices=[ + ("analog", "analog"), + ("named", "nominal"), + ("pseudoanonymous", "non-nominal"), + ], + max_length=64, + ), + ), + ] diff --git a/openslides/poll/models.py b/openslides/poll/models.py index 058550544..b3d47d4d8 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -116,9 +116,9 @@ class BasePoll(models.Model): TYPE_NAMED = "named" TYPE_PSEUDOANONYMOUS = "pseudoanonymous" TYPES = ( - (TYPE_ANALOG, "Analog"), - (TYPE_NAMED, "Named"), - (TYPE_PSEUDOANONYMOUS, "Pseudoanonymous"), + (TYPE_ANALOG, "analog"), + (TYPE_NAMED, "nominal"), + (TYPE_PSEUDOANONYMOUS, "non-nominal"), ) type = models.CharField(max_length=64, blank=False, null=False, choices=TYPES)