Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1157 cleanup form approval rule #1159

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import random
from datetime import timedelta

import pandas as pd
Expand All @@ -10,7 +9,7 @@
from api.v1.v1_data.models import PendingFormData, \
PendingAnswers, PendingDataApproval, PendingDataBatch
from api.v1.v1_forms.constants import QuestionTypes, FormTypes
from api.v1.v1_forms.models import FormApprovalRule, FormApprovalAssignment
from api.v1.v1_forms.models import FormApprovalAssignment
from api.v1.v1_forms.models import Forms, UserForms
from api.v1.v1_profile.constants import UserRoleTypes
from api.v1.v1_profile.management.commands.administration_seeder import (
Expand Down Expand Up @@ -129,22 +128,10 @@ def assign_batch_for_approval(batch, user, test):
administration = user.user_access.administration
complete_path = '{0}{1}'.format(administration.path, administration.id)
complete_path = complete_path.split('.')[1:]
approval_rule = FormApprovalRule.objects.filter(
administration_id=complete_path[0], form=batch.form).first()
levels = None
if approval_rule:
levels = approval_rule.levels.all()
if not approval_rule:
randoms = Levels.objects.filter(level__gt=1).count()
randoms = [n + 1 for n in range(randoms)]
limit = random.choices(randoms)
levels = Levels.objects.filter(level__gt=1).order_by('?')[:limit[0]]
levels |= Levels.objects.filter(level=1)
rule = FormApprovalRule.objects.create(
form=batch.form,
administration=Administration.objects.filter(
id=complete_path[0]).first())
rule.levels.set(levels)
randoms = Levels.objects.filter(level__gt=1).count()
randoms = [n + 1 for n in range(randoms)]
levels = Levels.objects.filter(
level__lte=MAX_LEVEL_IN_SOURCE_FILE).order_by('-level').all()
administrations = Administration.objects.filter(id__in=complete_path,
level__in=levels).all()
for administration in administrations:
Expand Down Expand Up @@ -229,7 +216,7 @@ def handle(self, *args, **options):
PendingDataBatch.objects.all().delete()
PendingFormData.objects.all().delete()
fake_geo = pd.read_csv("./source/kenya_random_points.csv")
forms = Forms.objects.all()
forms = Forms.objects.filter(type=FormTypes.county).all()
user = None
if options.get('email'):
# if user type is 'user' -> seed county form only
Expand Down

This file was deleted.

Loading