Move sex and age fields from questionnaire to user and add planning role restrictions

This commit is contained in:
Keannu Christian Bernasol 2024-12-04 01:29:30 +08:00
parent 724132e396
commit e0eba6ca21
25 changed files with 157 additions and 320 deletions

View file

@ -1,4 +1,4 @@
# Generated by Django 5.1.3 on 2024-11-24 02:27
# Generated by Django 5.1.3 on 2024-12-03 16:27
import django.db.models.deletion
import django.utils.timezone
@ -44,13 +44,6 @@ class Migration(migrations.Migration):
default=django.utils.timezone.now, editable=False
),
),
(
"sex",
models.CharField(
choices=[("male", "Male"), ("female", "Female")], max_length=16
),
),
("age", models.IntegerField()),
("region_of_residence", models.CharField(max_length=64)),
("service_availed", models.CharField(max_length=64)),
(
@ -121,7 +114,7 @@ class Migration(migrations.Migration):
"sqd0_answer",
models.CharField(
choices=[
("1", "Strongly disagree"),
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
@ -135,7 +128,7 @@ class Migration(migrations.Migration):
"sqd1_answer",
models.CharField(
choices=[
("1", "Strongly disagree"),
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
@ -149,7 +142,7 @@ class Migration(migrations.Migration):
"sqd2_answer",
models.CharField(
choices=[
("1", "Strongly disagree"),
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
@ -163,7 +156,7 @@ class Migration(migrations.Migration):
"sqd3_answer",
models.CharField(
choices=[
("1", "Strongly disagree"),
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
@ -177,7 +170,7 @@ class Migration(migrations.Migration):
"sqd4_answer",
models.CharField(
choices=[
("1", "Strongly disagree"),
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
@ -191,7 +184,7 @@ class Migration(migrations.Migration):
"sqd5_answer",
models.CharField(
choices=[
("1", "Strongly disagree"),
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
@ -205,7 +198,7 @@ class Migration(migrations.Migration):
"sqd6_answer",
models.CharField(
choices=[
("1", "Strongly disagree"),
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
@ -219,7 +212,7 @@ class Migration(migrations.Migration):
"sqd7_answer",
models.CharField(
choices=[
("1", "Strongly disagree"),
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
@ -233,7 +226,7 @@ class Migration(migrations.Migration):
"sqd8_answer",
models.CharField(
choices=[
("1", "Strongly disagree"),
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),

View file

@ -1,148 +0,0 @@
# Generated by Django 5.1.3 on 2024-11-28 07:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("questionnaires", "0001_initial"),
]
operations = [
migrations.AlterField(
model_name="questionnaire",
name="sqd0_answer",
field=models.CharField(
choices=[
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
("5", "Strongly Agree"),
("6", "N/A"),
],
max_length=16,
),
),
migrations.AlterField(
model_name="questionnaire",
name="sqd1_answer",
field=models.CharField(
choices=[
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
("5", "Strongly Agree"),
("6", "N/A"),
],
max_length=16,
),
),
migrations.AlterField(
model_name="questionnaire",
name="sqd2_answer",
field=models.CharField(
choices=[
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
("5", "Strongly Agree"),
("6", "N/A"),
],
max_length=16,
),
),
migrations.AlterField(
model_name="questionnaire",
name="sqd3_answer",
field=models.CharField(
choices=[
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
("5", "Strongly Agree"),
("6", "N/A"),
],
max_length=16,
),
),
migrations.AlterField(
model_name="questionnaire",
name="sqd4_answer",
field=models.CharField(
choices=[
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
("5", "Strongly Agree"),
("6", "N/A"),
],
max_length=16,
),
),
migrations.AlterField(
model_name="questionnaire",
name="sqd5_answer",
field=models.CharField(
choices=[
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
("5", "Strongly Agree"),
("6", "N/A"),
],
max_length=16,
),
),
migrations.AlterField(
model_name="questionnaire",
name="sqd6_answer",
field=models.CharField(
choices=[
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
("5", "Strongly Agree"),
("6", "N/A"),
],
max_length=16,
),
),
migrations.AlterField(
model_name="questionnaire",
name="sqd7_answer",
field=models.CharField(
choices=[
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
("5", "Strongly Agree"),
("6", "N/A"),
],
max_length=16,
),
),
migrations.AlterField(
model_name="questionnaire",
name="sqd8_answer",
field=models.CharField(
choices=[
("1", "Strongly Disagree"),
("2", "Disagree"),
("3", "Neither Agree nor Disagree"),
("4", "Agree"),
("5", "Strongly Agree"),
("6", "N/A"),
],
max_length=16,
),
),
]

View file

@ -16,15 +16,8 @@ class Questionnaire(models.Model):
)
date_submitted = models.DateTimeField(default=now, editable=False)
SEX_CHOICES = (
("male", "Male"),
("female", "Female"),
)
sex = models.CharField(
max_length=16, choices=SEX_CHOICES, null=False, blank=False)
age = models.IntegerField(null=False, blank=False)
region_of_residence = models.CharField(
max_length=64, null=False, blank=False)
region_of_residence = models.CharField(max_length=64, null=False, blank=False)
service_availed = models.CharField(max_length=64, null=False, blank=False)
I_AM_I_CHOICES = (
("faculty", "Faculty"),

View file

@ -5,16 +5,18 @@ from .models import Questionnaire
class QuestionnaireSerializer(serializers.ModelSerializer):
client = serializers.SlugRelatedField(
many=False, slug_field="email", queryset=CustomUser.objects.all(), required=False
many=False,
slug_field="email",
queryset=CustomUser.objects.all(),
required=False,
)
client_type = serializers.ChoiceField(
choices=Questionnaire.CLIENT_TYPE_CHOICES)
client_type = serializers.ChoiceField(choices=Questionnaire.CLIENT_TYPE_CHOICES)
date_submitted = serializers.DateTimeField(
format="%m-%d-%Y %I:%M %p", read_only=True
)
sex = serializers.ChoiceField(choices=Questionnaire.SEX_CHOICES)
age = serializers.IntegerField(min_value=1)
age = serializers.SerializerMethodField()
sex = serializers.SerializerMethodField()
region_of_residence = serializers.CharField(max_length=64)
service_availed = serializers.CharField(max_length=64)
i_am_a = serializers.ChoiceField(choices=Questionnaire.I_AM_I_CHOICES)
@ -32,6 +34,12 @@ class QuestionnaireSerializer(serializers.ModelSerializer):
sqd8_answer = serializers.ChoiceField(choices=Questionnaire.SQD_CHOICES)
extra_suggestions = serializers.CharField(max_length=512, required=False)
def get_age(self, obj):
return obj.client.age
def get_sex(self, obj):
return obj.client.sex
def to_representation(self, instance):
representation = super().to_representation(instance)
representation["client"] = instance.client.email

View file

@ -3,7 +3,7 @@ from .serializers import QuestionnaireSerializer
from rest_framework.permissions import IsAuthenticated
from .models import Questionnaire
from rest_framework.pagination import PageNumberPagination
from accounts.permissions import IsStaff
from accounts.permissions import IsStaff, IsPlanning
class QuestionnaireListAPIView(generics.ListAPIView):
@ -15,7 +15,7 @@ class QuestionnaireListAPIView(generics.ListAPIView):
serializer_class = QuestionnaireSerializer
queryset = Questionnaire.objects.all()
pagination_class = PageNumberPagination
permission_classes = [IsAuthenticated, IsStaff]
permission_classes = [IsAuthenticated, IsPlanning]
class QuestionnaireSubmitView(generics.CreateAPIView):