Fakultas Ilmu Komputer UI

Commit 810cd0db authored by Nabilah Adani's avatar Nabilah Adani
Browse files

Merge branch 'inigo/refactor-case-subject-models' into...

Merge branch 'inigo/refactor-case-subject-models' into 'pbi-6-diagram-statistik-kasus-se-kota-depok'

Refactor CaseSubject Model

See merge request !6
parents 349097aa 3446fe1a
Pipeline #69725 passed with stages
in 6 minutes and 11 seconds
BEJI = "Beji"
BEJI_TIMUR = "Beji Timur"
KEMIRIMUKA = "Kemirimuka"
KUKUSAN = "Kukusan"
PONDOK_CINA = "Pondok Cina"
TANAH_BARU = "Tanah Baru"
BOJONGSARI = "Bojongsari"
BOJONGSARI_BARU = "Bojongsari Baru"
BOJONGSARI_LAMA = "Bojongsari Lama"
CURUG = "Curug"
DUREN_MEKAR = "Duren Mekar"
DUREN_SERIBU = "Duren Seribu"
PONDOK_PETIR = "Pondok Petir"
SERUA = "Serua"
CILODONG = "Cilodong"
JATIMULYA = "Jatimulya"
KALIBARU = "Kalibaru"
KALIMULYA = "Kalimulya"
SUKAMAJU = "Sukamaju"
CIMANGGIS = "Cimanggis"
CISALAK_PASAR = "Cisalak Pasar"
HARJAMUKTI = "Harjamukti"
MEKARSARI = "Mekarsari"
PASIR_GUNUNG_SELATAN = "Pasir Gunung Selatan"
TUGU = "Tugu"
CINERE = "Cinere"
GANDUL = "Gandul"
PANGKALAN_JATI = "Pangkalan Jati"
PANGKALAN_JATI_BARU = "Pangkalan Jati Baru"
CIPAYUNG = "Cipayung"
BOJONG_PONDOK_TERONG = "Bojong Pondok Terong"
CIPAYUNG_JAYA = "Cipayung Jaya"
PONDOK_JAYA = "Pondok Jaya"
RATUJAYA = "Ratujaya"
LIMO = "Limo"
GROGOL = "Grogol"
KRUKUT = "Krukut"
MERUYUNG = "Meruyung"
PANCORAN_MAS = "Pancoran Mas"
DEPOK = "Depok"
DEPOK_JAYA = "Depok Jaya"
MAMPANG = "Mampang"
RANGKAPAN_JAYA = "Rangkapan Jaya"
RANGKAPAN_JAYA_BARU = "Rangkapan Jaya Baru"
SAWANGAN = "Sawangan"
BEDAHAN = "Bedahan"
CINANGKA = "Cinangka"
KEDAUNG = "Kedaung"
PASIR_PUTIH = "Pasir Putih"
PENGASINAN = "Pengasinan"
SAWANGAN_BARU = "Sawangan Baru"
SAWANGAN_LAMA = "Sawangan Lama"
SUKMAJAYA = "Sukmajaya"
ABADIJAYA = "Abadijaya"
BAKTI_JAYA = "Bakti Jaya"
CISALAK = "Cisalak"
MEKAR_JAYA = "Mekar Jaya"
TIRTAJAYA = "Tirtajaya"
TAPOS = "Tapos"
CILANGKAP = "Cilangkap"
CIMPAEUN = "Cimpaeun"
JATIJAJAR = "Jatijajar"
LEUWINANGGUNG = "Leuwinanggung"
SUKAMAJU_BARU = "Sukamaju Baru"
SUKATANI = "Sukatani"
DISTRICT_CHOICES = [
(BEJI, "Beji"),
(BOJONGSARI, "Bojongsari"),
(CILODONG, "Cilodong"),
(CIMANGGIS, "Cimanggis"),
(CINERE, "Cinere"),
(CIPAYUNG, "Cipayung"),
(LIMO, "Limo"),
(PANCORAN_MAS, "Pancoran Mas"),
(SAWANGAN, "Sawangan"),
(SUKMAJAYA, "Sukmajaya"),
(TAPOS, "Tapos")
]
SUB_DISTRICT_CHOICES = [
(BEJI, 'Beji'),
(BEJI_TIMUR, 'Beji Timur'),
(KEMIRIMUKA, 'Kemirimuka'),
(KUKUSAN, 'Kukusan'),
(PONDOK_CINA, 'Pondok Cina'),
(TANAH_BARU, 'Tanah Baru'),
(BOJONGSARI_BARU, 'Bojongsari Baru'),
(BOJONGSARI_LAMA, 'Bojongsari Lama'),
(CURUG, 'Curug'),
(DUREN_MEKAR, 'Duren Mekar'),
(DUREN_SERIBU, 'Duren Seribu'),
(PONDOK_PETIR, 'Pondok Petir'),
(SERUA, 'Serua'),
(CILODONG, 'Cilodong'),
(JATIMULYA, 'Jatimulya'),
(KALIBARU, 'Kalibaru'),
(KALIMULYA, 'Kalimulya'),
(SUKAMAJU, 'Sukamaju'),
(CISALAK_PASAR, 'Cisalak Pasar'),
(CURUG, 'Curug'),
(HARJAMUKTI, 'Harjamukti'),
(MEKARSARI, 'Mekarsari'),
(PASIR_GUNUNG_SELATAN, 'Pasir Gunung Selatan'),
(TUGU, 'Tugu'),
(CINERE, 'Cinere'),
(GANDUL, 'Gandul'),
(PANGKALAN_JATI, 'Pangkalan Jati'),
(PANGKALAN_JATI_BARU, 'Pangkalan Jati Baru'),
(BOJONG_PONDOK_TERONG, 'Bojong Pondok Terong'),
(CIPAYUNG, 'Cipayung'),
(CIPAYUNG_JAYA, 'Cipayung Jaya'),
(PONDOK_JAYA, 'Pondok Jaya'),
(RATUJAYA, 'Ratujaya'),
(GROGOL, 'Grogol'),
(KRUKUT, 'Krukut'),
(LIMO, 'Limo'),
(MERUYUNG, 'Meruyung'),
(DEPOK_JAYA, 'Depok'),
(DEPOK_JAYA, 'Depok Jaya'),
(MAMPANG, 'Mampang'),
(PANCORAN_MAS, 'Pancoran Mas'),
(RANGKAPAN_JAYA, 'Rangkapan Jaya'),
(RANGKAPAN_JAYA_BARU, 'Rangkapan Jaya Baru'),
(BEDAHAN, 'Bedahan'),
(CINANGKA, 'Cinangka'),
(KEDAUNG, 'Kedaung'),
(PASIR_PUTIH, 'Pasir Putih'),
(PENGASINAN, 'Pengasinan'),
(SAWANGAN_BARU, 'Sawangan Baru'),
(SAWANGAN_LAMA, 'Sawangan Lama'),
(ABADIJAYA, 'Abadijaya'),
(BAKTI_JAYA, 'Bakti Jaya'),
(CISALAK, 'Cisalak'),
(MEKAR_JAYA, 'Mekar Jaya'),
(SUKAMAJU, 'Sukmajaya'),
(TIRTAJAYA, 'Tirtajaya'),
(CILANGKAP, 'Cilangkap'),
(CIMPAEUN, 'Cimpaeun'),
(JATIJAJAR, 'Jatijajar'),
(LEUWINANGGUNG, 'Leuwinanggung'),
(SUKAMAJU_BARU, 'Sukamaju Baru'),
(SUKATANI, 'Sukatani'),
(TAPOS, 'Tapos'),
]
SUB_DISTRICT_MAPPING = {
BEJI: [
BEJI_TIMUR,
KEMIRIMUKA,
KUKUSAN,
PONDOK_CINA,
TANAH_BARU
],
BOJONGSARI: [
BOJONGSARI_BARU,
BOJONGSARI_LAMA,
CURUG,
DUREN_MEKAR,
DUREN_SERIBU,
PONDOK_PETIR, SERUA
],
CILODONG: [
CILODONG,
JATIMULYA,
KALIBARU,
KALIMULYA,
SUKAMAJU
],
CIMANGGIS: [
CISALAK_PASAR,
CURUG,
HARJAMUKTI,
MEKARSARI,
PASIR_GUNUNG_SELATAN,
TUGU
],
CINERE: [
CINERE,
GANDUL,
PANGKALAN_JATI,
PANGKALAN_JATI_BARU
] ,
CIPAYUNG: [
BOJONG_PONDOK_TERONG,
CIPAYUNG,
CIPAYUNG_JAYA,
PONDOK_JAYA,
RATUJAYA
],
LIMO: [
GROGOL,
KRUKUT,
LIMO,
MERUYUNG
],
PANCORAN_MAS: [
DEPOK,
DEPOK_JAYA,
MAMPANG,
PANCORAN_MAS,
RANGKAPAN_JAYA,
RANGKAPAN_JAYA_BARU
],
SAWANGAN: [
BEDAHAN,
CINANGKA,
KEDAUNG,
PASIR_PUTIH,
PENGASINAN,
SAWANGAN_BARU,
SAWANGAN_LAMA
],
SUKMAJAYA: [
ABADIJAYA,
BAKTI_JAYA,
CISALAK,
MEKAR_JAYA,
SUKMAJAYA,
TIRTAJAYA
],
TAPOS: [
CILANGKAP,
CIMPAEUN,
JATIJAJAR,
LEUWINANGGUNG,
SUKAMAJU_BARU,
SUKATANI,
TAPOS
]
}
\ No newline at end of file
# Generated by Django 3.0.1 on 2021-04-04 13:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cases', '0012_auto_20200518_1532'),
]
operations = [
migrations.AlterField(
model_name='casesubject',
name='district',
field=models.CharField(choices=[('Beji', 'Beji'), ('Bojongsari', 'Bojongsari'), ('Cilodong', 'Cilodong'), ('Cimanggis', 'Cimanggis'), ('Cinere', 'Cinere'), ('Cipayung', 'Cipayung'), ('Limo', 'Limo'), ('Pancoran Mas', 'Pancoran Mas'), ('Sawangan', 'Sawangan'), ('Sukmajaya', 'Sukmajaya'), ('Tapos', 'Tapos')], max_length=128),
),
migrations.AlterField(
model_name='casesubject',
name='sub_district',
field=models.CharField(choices=[('Beji', 'Beji'), ('Beji Timur', 'Beji Timur'), ('Kemirimuka', 'Kemirimuka'), ('Kukusan', 'Kukusan'), ('Pondok Cina', 'Pondok Cina'), ('Tanah Baru', 'Tanah Baru'), ('Bojongsari Baru', 'Bojongsari Baru'), ('Bojongsari Lama', 'Bojongsari Lama'), ('Curug', 'Curug'), ('Duren Mekar', 'Duren Mekar'), ('Duren Seribu', 'Duren Seribu'), ('Pondok Petir', 'Pondok Petir'), ('Serua', 'Serua'), ('Cilodong', 'Cilodong'), ('Jatimulya', 'Jatimulya'), ('Kalibaru', 'Kalibaru'), ('Kalimulya', 'Kalimulya'), ('Sukamaju', 'Sukamaju'), ('Cisalak Pasar', 'Cisalak Pasar'), ('Curug', 'Curug'), ('Harjamukti', 'Harjamukti'), ('Mekarsari', 'Mekarsari'), ('Pasir Gunung Selatan', 'Pasir Gunung Selatan'), ('Tugu', 'Tugu'), ('Cinere', 'Cinere'), ('Gandul', 'Gandul'), ('Pangkalan Jati', 'Pangkalan Jati'), ('Pangkalan Jati Baru', 'Pangkalan Jati Baru'), ('Bojong Pondok Terong', 'Bojong Pondok Terong'), ('Cipayung', 'Cipayung'), ('Cipayung Jaya', 'Cipayung Jaya'), ('Pondok Jaya', 'Pondok Jaya'), ('Ratujaya', 'Ratujaya'), ('Grogol', 'Grogol'), ('Krukut', 'Krukut'), ('Limo', 'Limo'), ('Meruyung', 'Meruyung'), ('Depok Jaya', 'Depok'), ('Depok Jaya', 'Depok Jaya'), ('Mampang', 'Mampang'), ('Pancoran Mas', 'Pancoran Mas'), ('Rangkapan Jaya', 'Rangkapan Jaya'), ('Rangkapan Jaya Baru', 'Rangkapan Jaya Baru'), ('Bedahan', 'Bedahan'), ('Cinangka', 'Cinangka'), ('Kedaung', 'Kedaung'), ('Pasir Putih', 'Pasir Putih'), ('Pengasinan', 'Pengasinan'), ('Sawangan Baru', 'Sawangan Baru'), ('Sawangan Lama', 'Sawangan Lama'), ('Abadijaya', 'Abadijaya'), ('Bakti Jaya', 'Bakti Jaya'), ('Cisalak', 'Cisalak'), ('Mekar Jaya', 'Mekar Jaya'), ('Sukamaju', 'Sukmajaya'), ('Tirtajaya', 'Tirtajaya'), ('Cilangkap', 'Cilangkap'), ('Cimpaeun', 'Cimpaeun'), ('Jatijajar', 'Jatijajar'), ('Leuwinanggung', 'Leuwinanggung'), ('Sukamaju Baru', 'Sukamaju Baru'), ('Sukatani', 'Sukatani'), ('Tapos', 'Tapos')], max_length=128),
),
migrations.AlterField(
model_name='casesubjecthistory',
name='district',
field=models.CharField(choices=[('Beji', 'Beji'), ('Bojongsari', 'Bojongsari'), ('Cilodong', 'Cilodong'), ('Cimanggis', 'Cimanggis'), ('Cinere', 'Cinere'), ('Cipayung', 'Cipayung'), ('Limo', 'Limo'), ('Pancoran Mas', 'Pancoran Mas'), ('Sawangan', 'Sawangan'), ('Sukmajaya', 'Sukmajaya'), ('Tapos', 'Tapos')], max_length=128),
),
migrations.AlterField(
model_name='casesubjecthistory',
name='sub_district',
field=models.CharField(choices=[('Beji', 'Beji'), ('Beji Timur', 'Beji Timur'), ('Kemirimuka', 'Kemirimuka'), ('Kukusan', 'Kukusan'), ('Pondok Cina', 'Pondok Cina'), ('Tanah Baru', 'Tanah Baru'), ('Bojongsari Baru', 'Bojongsari Baru'), ('Bojongsari Lama', 'Bojongsari Lama'), ('Curug', 'Curug'), ('Duren Mekar', 'Duren Mekar'), ('Duren Seribu', 'Duren Seribu'), ('Pondok Petir', 'Pondok Petir'), ('Serua', 'Serua'), ('Cilodong', 'Cilodong'), ('Jatimulya', 'Jatimulya'), ('Kalibaru', 'Kalibaru'), ('Kalimulya', 'Kalimulya'), ('Sukamaju', 'Sukamaju'), ('Cisalak Pasar', 'Cisalak Pasar'), ('Curug', 'Curug'), ('Harjamukti', 'Harjamukti'), ('Mekarsari', 'Mekarsari'), ('Pasir Gunung Selatan', 'Pasir Gunung Selatan'), ('Tugu', 'Tugu'), ('Cinere', 'Cinere'), ('Gandul', 'Gandul'), ('Pangkalan Jati', 'Pangkalan Jati'), ('Pangkalan Jati Baru', 'Pangkalan Jati Baru'), ('Bojong Pondok Terong', 'Bojong Pondok Terong'), ('Cipayung', 'Cipayung'), ('Cipayung Jaya', 'Cipayung Jaya'), ('Pondok Jaya', 'Pondok Jaya'), ('Ratujaya', 'Ratujaya'), ('Grogol', 'Grogol'), ('Krukut', 'Krukut'), ('Limo', 'Limo'), ('Meruyung', 'Meruyung'), ('Depok Jaya', 'Depok'), ('Depok Jaya', 'Depok Jaya'), ('Mampang', 'Mampang'), ('Pancoran Mas', 'Pancoran Mas'), ('Rangkapan Jaya', 'Rangkapan Jaya'), ('Rangkapan Jaya Baru', 'Rangkapan Jaya Baru'), ('Bedahan', 'Bedahan'), ('Cinangka', 'Cinangka'), ('Kedaung', 'Kedaung'), ('Pasir Putih', 'Pasir Putih'), ('Pengasinan', 'Pengasinan'), ('Sawangan Baru', 'Sawangan Baru'), ('Sawangan Lama', 'Sawangan Lama'), ('Abadijaya', 'Abadijaya'), ('Bakti Jaya', 'Bakti Jaya'), ('Cisalak', 'Cisalak'), ('Mekar Jaya', 'Mekar Jaya'), ('Sukamaju', 'Sukmajaya'), ('Tirtajaya', 'Tirtajaya'), ('Cilangkap', 'Cilangkap'), ('Cimpaeun', 'Cimpaeun'), ('Jatijajar', 'Jatijajar'), ('Leuwinanggung', 'Leuwinanggung'), ('Sukamaju Baru', 'Sukamaju Baru'), ('Sukatani', 'Sukatani'), ('Tapos', 'Tapos')], max_length=128),
),
]
......@@ -2,6 +2,7 @@ import uuid
import pytz
from datetime import datetime
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from django.db import models
from apps.accounts.models import Account
......@@ -14,15 +15,15 @@ from apps.constants import (
ACTIVITY_TYPE_DELETE,
ACTIVITY_TYPE_EDIT,
)
from .constants import ( DISTRICT_CHOICES, SUB_DISTRICT_CHOICES, SUB_DISTRICT_MAPPING )
class CaseSubjectHistory(HistoryModel):
name = models.CharField(max_length=128)
age = models.IntegerField()
is_male = models.BooleanField(db_index=True)
address = models.CharField(max_length=256)
district = models.CharField(max_length=128)
sub_district = models.CharField(max_length=128)
district = models.CharField(max_length=128, choices=DISTRICT_CHOICES)
sub_district = models.CharField(max_length=128, choices=SUB_DISTRICT_CHOICES)
author = models.ForeignKey(
Account,
blank=True,
......@@ -39,14 +40,18 @@ class CaseSubjectHistory(HistoryModel):
def __str__(self):
return f"[History] {self.revision_id} | {self.object_id}"
def clean(self):
if self.sub_district not in SUB_DISTRICT_MAPPING[self.district]:
raise ValidationError(_('Inconsistent district and sub district value'))
class CaseSubject(HistoryEnabledModel):
name = models.CharField(max_length=128)
age = models.IntegerField()
is_male = models.BooleanField(db_index=True)
address = models.CharField(max_length=256)
district = models.CharField(max_length=128)
sub_district = models.CharField(max_length=128)
district = models.CharField(max_length=128, choices=DISTRICT_CHOICES)
sub_district = models.CharField(max_length=128, choices=SUB_DISTRICT_CHOICES)
author = models.ForeignKey(
Account,
blank=True,
......@@ -69,6 +74,10 @@ class CaseSubject(HistoryEnabledModel):
+ f"{self.district}, {self.sub_district}"
)
def clean(self):
if self.sub_district not in SUB_DISTRICT_MAPPING[self.district]:
raise ValidationError(_('Inconsistent district and sub district value'))
class InvestigationCaseHistory(HistoryModel):
case_subject_id = models.UUIDField(blank=True, null=True)
......
import uuid
from apps.cases.models import CaseSubject
from apps.cases.constants import (
DISTRICT_CHOICES,
SUB_DISTRICT_MAPPING
)
from django.contrib.auth.models import User
from faker import Faker
import factory
import random
faker = Faker()
......@@ -17,5 +22,5 @@ class CaseSubjectFactory(factory.DjangoModelFactory):
age = 19
is_male = True
address = faker.address()
district = faker.state()
sub_district = faker.city()
district = random.choice(DISTRICT_CHOICES)[0]
sub_district = factory.LazyAttribute(lambda o: random.choice(SUB_DISTRICT_MAPPING[o.district]))
......@@ -54,7 +54,7 @@ def init_data():
)
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Unknown",
district="Limo",
age=21,
is_male=False,
),
......@@ -154,9 +154,9 @@ class ExportableViewTest(APITestCase):
},
"Limo": {
"positive": 0,
"negative": 0,
"negative": 1,
"undetermined": 0,
"total_count": 0
"total_count": 1
},
"Pancoran Mas": {
"positive": 0,
......@@ -181,12 +181,6 @@ class ExportableViewTest(APITestCase):
"negative": 1,
"undetermined": 0,
"total_count": 1
},
"Unknown": {
"positive": 0,
"negative": 1,
"undetermined": 0,
"total_count": 1
}
},
"sex": {
......@@ -205,7 +199,8 @@ class ExportableViewTest(APITestCase):
},
"total_count": 5
}
self.maxDiff = None
self.assertJSONEqual(response.content, data)
def test_url_filter_exportable(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment