Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
4d28fef4
Commit
4d28fef4
authored
Apr 08, 2020
by
Jonathan Christopher Jakub
Browse files
Register Models to Django-Admin Page
parent
24382149
Changes
14
Hide whitespace changes
Inline
Side-by-side
apps/accounts/admin.py
View file @
4d28fef4
from
django.contrib
import
admin
from
apps.accounts.models
import
Account
# Register your models here.
admin
.
site
.
register
(
Account
)
apps/accounts/migrations/0001_initial.py
View file @
4d28fef4
...
...
@@ -43,6 +43,6 @@ class Migration(migrations.Migration):
),
),
],
options
=
{
"verbose_name_plural"
:
"accounts"
,
"db_table"
:
"account"
,},
options
=
{
"verbose_name_plural"
:
"accounts"
,
"db_table"
:
"account"
,
},
),
]
apps/accounts/models.py
View file @
4d28fef4
...
...
@@ -20,3 +20,8 @@ class Account(models.Model):
class
Meta
:
db_table
=
"account"
verbose_name_plural
=
"accounts"
def
__str__
(
self
):
if
self
.
is_admin
:
return
f
"[Admin]
{
self
.
user
.
username
}
"
return
f
"[Officer]
{
self
.
user
.
username
}
"
apps/accounts/tests/test_units/test_accounts.py
View file @
4d28fef4
...
...
@@ -35,6 +35,13 @@ class AccountViewTest(APITestCase):
def
setUp
(
self
):
self
.
client
=
APIClient
(
HTTP_AUTHORIZATION
=
HEADER_PREFIX
+
self
.
token_1
.
key
)
def
test_string_representation
(
self
):
admin_str
=
f
"[Admin]
{
self
.
admin
.
user
.
username
}
"
self
.
assertEqual
(
admin_str
,
str
(
self
.
admin
))
officer_str
=
f
"[Officer]
{
self
.
officer
.
user
.
username
}
"
self
.
assertEqual
(
officer_str
,
str
(
self
.
officer
))
def
test_list_all_accounts_success
(
self
):
url
=
self
.
BASE_URL
...
...
apps/cases/admin.py
View file @
4d28fef4
from
django.contrib
import
admin
from
apps.cases.models
import
(
CaseSubject
,
InvestigationCase
,
MonitoringCase
,
PositiveCase
,
)
# Register your models here.
admin
.
site
.
register
(
CaseSubject
)
admin
.
site
.
register
(
InvestigationCase
)
admin
.
site
.
register
(
MonitoringCase
)
admin
.
site
.
register
(
PositiveCase
)
apps/cases/models.py
View file @
4d28fef4
...
...
@@ -29,6 +29,17 @@ class CaseSubject(models.Model):
verbose_name_plural
=
"case subjects"
ordering
=
[
"-created_at"
]
def
__str__
(
self
):
if
self
.
is_active
:
return
(
f
"[Active] Rev.
{
self
.
revision_id
}
-
{
self
.
name
}
| "
+
f
"
{
self
.
district
}
,
{
self
.
sub_district
}
"
)
return
(
f
"[Inactive] Rev.
{
self
.
revision_id
}
-
{
self
.
name
}
| "
+
f
"
{
self
.
district
}
,
{
self
.
sub_district
}
"
)
def
delete
(
self
):
if
self
.
deleted_at
is
None
:
self
.
is_active
=
False
...
...
@@ -59,6 +70,11 @@ class PositiveCase(models.Model):
verbose_name_plural
=
"positive cases"
ordering
=
[
"-created_at"
]
def
__str__
(
self
):
if
self
.
is_active
:
return
f
"[Active] Rev.
{
self
.
revision_id
}
| by
{
self
.
author
}
"
return
f
"[Inactive] Rev.
{
self
.
revision_id
}
| by
{
self
.
author
}
"
def
delete
(
self
):
if
self
.
deleted_at
is
None
:
self
.
is_active
=
False
...
...
@@ -100,6 +116,11 @@ class InvestigationCase(models.Model):
verbose_name_plural
=
"investigation cases"
ordering
=
[
"-created_at"
]
def
__str__
(
self
):
if
self
.
is_active
:
return
f
"[Active] Rev.
{
self
.
revision_id
}
| by
{
self
.
author
}
"
return
f
"[Inactive] Rev.
{
self
.
revision_id
}
| by
{
self
.
author
}
"
def
delete
(
self
):
if
self
.
deleted_at
is
None
:
self
.
is_active
=
False
...
...
@@ -149,6 +170,11 @@ class MonitoringCase(models.Model):
verbose_name_plural
=
"monitoring cases"
ordering
=
[
"-created_at"
]
def
__str__
(
self
):
if
self
.
is_active
:
return
f
"[Active] Rev.
{
self
.
revision_id
}
| by
{
self
.
author
}
"
return
f
"[Inactive] Rev.
{
self
.
revision_id
}
| by
{
self
.
author
}
"
def
save
(
self
,
*
args
,
**
kwargs
):
self
.
clean
()
return
super
(
MonitoringCase
,
self
).
save
(
*
args
,
**
kwargs
)
...
...
apps/cases/tests/test_units/test_case_subjects.py
View file @
4d28fef4
...
...
@@ -38,6 +38,19 @@ class CaseSubjectViewTest(APITestCase):
def
setUp
(
self
):
self
.
client
=
APIClient
(
HTTP_AUTHORIZATION
=
HEADER_PREFIX
+
self
.
token_1
.
key
)
def
test_string_representation
(
self
):
inactive_case_subject_str
=
(
f
"[Inactive] Rev.
{
self
.
case_subject_3
.
revision_id
}
-
{
self
.
case_subject_3
.
name
}
| "
+
f
"
{
self
.
case_subject_3
.
district
}
,
{
self
.
case_subject_3
.
sub_district
}
"
)
self
.
assertEqual
(
inactive_case_subject_str
,
str
(
self
.
case_subject_3
))
active_case_subject_str
=
(
f
"[Active] Rev.
{
self
.
case_subject_1
.
revision_id
}
-
{
self
.
case_subject_1
.
name
}
| "
+
f
"
{
self
.
case_subject_1
.
district
}
,
{
self
.
case_subject_1
.
sub_district
}
"
)
self
.
assertEqual
(
active_case_subject_str
,
str
(
self
.
case_subject_1
))
def
test_list_case_subjects_only_shows_active_entries_success
(
self
):
url
=
self
.
BASE_URL
...
...
apps/cases/tests/test_units/test_investigation_cases.py
View file @
4d28fef4
...
...
@@ -46,7 +46,7 @@ class InvestigationCaseViewTest(APITestCase):
reference_case_id
=
self
.
reference_case
.
case_id
,
deleted_at
=
datetime
.
now
(
tz
=
pytz
.
timezone
(
TIMEZONE
)),
)
self
.
other_
inactive_case
=
InvestigationCaseFactory
(
self
.
inactive_case
=
InvestigationCaseFactory
(
author
=
self
.
author
,
case_subject_id
=
self
.
case_subject
.
subject_id
,
reference_case_id
=
self
.
reference_case
.
case_id
,
...
...
@@ -56,6 +56,17 @@ class InvestigationCaseViewTest(APITestCase):
def
setUp
(
self
):
self
.
client
=
APIClient
(
HTTP_AUTHORIZATION
=
HEADER_PREFIX
+
self
.
token_1
.
key
)
def
test_string_representation
(
self
):
inactive_case_str
=
(
f
"[Inactive] Rev.
{
self
.
inactive_case
.
revision_id
}
| by
{
self
.
inactive_case
.
author
}
"
)
self
.
assertEqual
(
inactive_case_str
,
str
(
self
.
inactive_case
))
active_case_str
=
(
f
"[Active] Rev.
{
self
.
case
.
revision_id
}
| by
{
self
.
case
.
author
}
"
)
self
.
assertEqual
(
active_case_str
,
str
(
self
.
case
))
def
test_list_investigation_cases_success
(
self
):
url
=
self
.
BASE_URL
...
...
@@ -223,15 +234,15 @@ class InvestigationCaseViewTest(APITestCase):
self
.
assertIn
(
'"action_type":"{}"'
.
format
(
ACTIVITY_TYPE_EDIT
),
response_string
)
def
test_edit_inactive_investigation_case_fails
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
other_
inactive_case
.
revision_id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
inactive_case
.
revision_id
)
+
"/"
data
=
{
"case_subject_id"
:
str
(
self
.
other_
inactive_case
.
case_subject_id
),
"case_subject_id"
:
str
(
self
.
inactive_case
.
case_subject_id
),
"reference_case_id"
:
str
(
self
.
reference_case
.
case_id
),
"case_relation"
:
self
.
other_
inactive_case
.
case_relation
,
"medical_symptoms"
:
self
.
other_
inactive_case
.
medical_symptoms
,
"risk_factors"
:
self
.
other_
inactive_case
.
risk_factors
,
"is_referral_needed"
:
not
self
.
other_
inactive_case
.
is_referral_needed
,
"medical_facility_reference"
:
self
.
other_
inactive_case
.
medical_facility_reference
,
"case_relation"
:
self
.
inactive_case
.
case_relation
,
"medical_symptoms"
:
self
.
inactive_case
.
medical_symptoms
,
"risk_factors"
:
self
.
inactive_case
.
risk_factors
,
"is_referral_needed"
:
not
self
.
inactive_case
.
is_referral_needed
,
"medical_facility_reference"
:
self
.
inactive_case
.
medical_facility_reference
,
}
response
=
self
.
client
.
put
(
path
=
url
,
data
=
data
,
format
=
"json"
,)
...
...
@@ -299,7 +310,7 @@ class InvestigationCaseViewTest(APITestCase):
)
def
test_delete_inactive_investigation_case_fails
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
other_
inactive_case
.
revision_id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
inactive_case
.
revision_id
)
+
"/"
response
=
self
.
client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
)
apps/cases/tests/test_units/test_monitoring_cases.py
View file @
4d28fef4
...
...
@@ -53,7 +53,7 @@ class MonitoringCaseViewTest(APITestCase):
positive_case_id
=
self
.
positive_case
.
case_id
,
deleted_at
=
datetime
.
now
(
tz
=
pytz
.
timezone
(
TIMEZONE
)),
)
self
.
other_
inactive_case
=
MonitoringCaseFactory
(
self
.
inactive_case
=
MonitoringCaseFactory
(
author
=
self
.
author
,
positive_case_id
=
self
.
positive_case
.
case_id
,
is_active
=
False
,
...
...
@@ -62,6 +62,17 @@ class MonitoringCaseViewTest(APITestCase):
def
setUp
(
self
):
self
.
client
=
APIClient
(
HTTP_AUTHORIZATION
=
HEADER_PREFIX
+
self
.
token
.
key
)
def
test_string_representation
(
self
):
inactive_case_str
=
(
f
"[Inactive] Rev.
{
self
.
inactive_case
.
revision_id
}
| by
{
self
.
inactive_case
.
author
}
"
)
self
.
assertEqual
(
inactive_case_str
,
str
(
self
.
inactive_case
))
active_case_str
=
(
f
"[Active] Rev.
{
self
.
case_1
.
revision_id
}
| by
{
self
.
case_1
.
author
}
"
)
self
.
assertEqual
(
active_case_str
,
str
(
self
.
case_1
))
def
test_list_monitoring_cases_success
(
self
):
url
=
self
.
BASE_URL
...
...
@@ -193,7 +204,7 @@ class MonitoringCaseViewTest(APITestCase):
self
.
assertIn
(
'"action_type":"{}"'
.
format
(
ACTIVITY_TYPE_EDIT
),
response_string
)
def
test_edit_inactive_monitoring_case_fails
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
other_
inactive_case
.
revision_id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
inactive_case
.
revision_id
)
+
"/"
data
=
{
"positive_case_id"
:
str
(
self
.
positive_case
.
revision_id
),
...
...
@@ -240,6 +251,6 @@ class MonitoringCaseViewTest(APITestCase):
)
def
test_delete_inactive_monitoring_case_fails
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
other_
inactive_case
.
revision_id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
inactive_case
.
revision_id
)
+
"/"
response
=
self
.
client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
)
apps/cases/tests/test_units/test_positive_cases.py
View file @
4d28fef4
...
...
@@ -37,7 +37,7 @@ class PositiveCaseViewTest(APITestCase):
case_subject_id
=
self
.
case_subject
.
subject_id
,
deleted_at
=
datetime
.
now
(
tz
=
pytz
.
timezone
(
TIMEZONE
)),
)
self
.
other_
inactive_case
=
PositiveCaseFactory
(
self
.
inactive_case
=
PositiveCaseFactory
(
author
=
self
.
author
,
case_subject_id
=
self
.
case_subject
.
subject_id
,
is_active
=
False
,
...
...
@@ -46,6 +46,17 @@ class PositiveCaseViewTest(APITestCase):
def
setUp
(
self
):
self
.
client
=
APIClient
(
HTTP_AUTHORIZATION
=
HEADER_PREFIX
+
self
.
token_1
.
key
)
def
test_string_representation
(
self
):
inactive_case_str
=
(
f
"[Inactive] Rev.
{
self
.
inactive_case
.
revision_id
}
| by
{
self
.
inactive_case
.
author
}
"
)
self
.
assertEqual
(
inactive_case_str
,
str
(
self
.
inactive_case
))
active_case_str
=
(
f
"[Active] Rev.
{
self
.
case
.
revision_id
}
| by
{
self
.
case
.
author
}
"
)
self
.
assertEqual
(
active_case_str
,
str
(
self
.
case
))
def
test_list_positive_cases_success
(
self
):
url
=
self
.
BASE_URL
...
...
@@ -191,7 +202,7 @@ class PositiveCaseViewTest(APITestCase):
self
.
assertIn
(
'"action_type":"{}"'
.
format
(
ACTIVITY_TYPE_EDIT
),
response_string
)
def
test_edit_inactive_positive_case_fails
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
other_
inactive_case
.
revision_id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
inactive_case
.
revision_id
)
+
"/"
data
=
{
"case_subject_id"
:
str
(
self
.
case
.
case_subject_id
),
...
...
@@ -246,6 +257,6 @@ class PositiveCaseViewTest(APITestCase):
)
def
test_delete_inactive_positive_case_fails
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
other_
inactive_case
.
revision_id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
inactive_case
.
revision_id
)
+
"/"
response
=
self
.
client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
)
apps/cases/urls.py
View file @
4d28fef4
...
...
@@ -13,7 +13,9 @@ router = DefaultRouter()
router
.
register
(
r
"case-subjects"
,
CaseSubjectViewSet
,
basename
=
"case-subject"
)
router
.
register
(
r
"positive-cases"
,
PositiveCaseViewSet
,
basename
=
"positive-case"
)
router
.
register
(
r
"monitoring-cases"
,
MonitoringCaseViewSet
,
basename
=
"monitoring-case"
)
router
.
register
(
r
"investigation-cases"
,
InvestigationCaseViewSet
,
basename
=
"investigation-case"
)
router
.
register
(
r
"investigation-cases"
,
InvestigationCaseViewSet
,
basename
=
"investigation-case"
)
urlpatterns
=
[
path
(
""
,
include
(
router
.
urls
)),
...
...
apps/logs/admin.py
View file @
4d28fef4
from
django.contrib
import
admin
from
apps.logs.models
import
Log
# Register your models here.
admin
.
site
.
register
(
Log
)
apps/logs/models.py
View file @
4d28fef4
...
...
@@ -29,6 +29,9 @@ class Log(models.Model):
verbose_name_plural
=
"activity logs"
ordering
=
[
"-created_at"
]
def
__str__
(
self
):
return
f
"
{
self
.
created_at
}
| [
{
self
.
action_type
}
]
{
self
.
model_name
}
-
{
self
.
author
}
"
def
get_model
(
self
):
model_app
=
MODEL_APP_MAPPING
.
get
(
self
.
model_name
)
Model
=
apps
.
get_model
(
model_app
,
self
.
model_name
)
...
...
apps/logs/tests/test_units/test_logs.py
View file @
4d28fef4
...
...
@@ -50,6 +50,13 @@ class ActivityLogViewTest(APITestCase):
def
setUp
(
self
):
self
.
client
=
APIClient
(
HTTP_AUTHORIZATION
=
HEADER_PREFIX
+
self
.
token
.
key
)
def
test_string_representation
(
self
):
log_str
=
(
f
"
{
self
.
log
.
created_at
}
| [
{
self
.
log
.
action_type
}
] "
+
f
"
{
self
.
log
.
model_name
}
-
{
self
.
log
.
author
}
"
)
self
.
assertEqual
(
log_str
,
str
(
self
.
log
))
def
test_list_only_current_author_logs_success
(
self
):
url
=
"/logs/"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment