OpenSlides/server/openslides/poll/migrations/poll_migration_helper.py
Joshua Sangmeister 4b13ff681e user_token, single votes table, entitled_users server changes
server changes finished, tests, cleanup

Add entitled user table

Fix formatting

Finish entitled users table & implement new percent base

Fix typing

Fixed remarks & errors

Fix new precent base representation

Update autoupdate service

Remove unneeded prettier entry

Remove unneeded css
2021-04-01 16:02:47 +02:00

37 lines
1.3 KiB
Python

from ..models import BasePoll
def set_is_pseudoanonymized(poll_model_collection, poll_model_name):
"""
Takes all polls of the given model and updates is_pseudoanonymized, if necessary.
"""
def _set_is_pseudoanonymized(apps, schema_editor):
PollModel = apps.get_model(poll_model_collection, poll_model_name)
for poll in PollModel.objects.all():
if poll.type == BasePoll.TYPE_PSEUDOANONYMOUS or all(
not vote.user_id
for option in poll.options.all()
for vote in option.votes.all()
):
poll.is_pseudoanonymized = True
poll.save(skip_autoupdate=True)
return _set_is_pseudoanonymized
def calculate_vote_fields(poll_model_collection, poll_model_name):
"""
Takes all polls of the given model and updates votes*, if necessary.
"""
def _calculate_vote_fields(apps, schema_editor):
PollModel = apps.get_model(poll_model_collection, poll_model_name)
for poll in PollModel.objects.all():
if poll.state in (BasePoll.STATE_FINISHED, BasePoll.STATE_PUBLISHED):
BasePoll.calculate_votes(poll)
BasePoll.calculate_entitled_users(poll)
poll.save(skip_autoupdate=True)
return _calculate_vote_fields