Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
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
Diskominfo-D'Blood
Mantan Aab-D Blood
Commits
654cbdc6
Commit
654cbdc6
authored
Jun 19, 2020
by
Nabila Febri Viola
Browse files
Merge branch 'warmfix-navy' into 'staging'
Warmfix navy Fix
#72
Closes
#72
See merge request
!119
parents
251038de
bae28b7c
Pipeline
#50000
passed with stages
in 5 minutes and 23 seconds
Changes
43
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/acara_donor/admin.py
View file @
654cbdc6
from
django.http
import
HttpResponse
from
django.contrib
import
admin
from
django.conf
import
settings
from
django.utils.timezone
import
localtime
from
django.utils.html
import
mark_safe
from
acara_donor.models
import
AcaraDonor
from
donor.models
import
JadwalDonor
from
acara_donor.filters
import
AcaraDonorFilter
def
download_acara_donor
(
modeladmin
,
request
,
queryset
):
import
pandas
as
pd
from
django_pandas.io
import
read_frame
response
=
HttpResponse
(
content_type
=
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
response
[
'Content-Disposition'
]
=
f
'attachment; filename=
{
modeladmin
.
model
.
_meta
}
.xlsx'
df
=
read_frame
(
queryset
)
df
[
'waktu_donor'
]
=
df
[
'waktu_donor'
].
astype
(
str
).
str
[:
-
6
]
# Strip tzinfo
writer
=
pd
.
ExcelWriter
(
response
,
engine
=
'xlsxwriter'
)
df
.
to_excel
(
writer
,
sheet_name
=
'Sheet1'
)
workbook
=
writer
.
book
# worksheet = writer.sheets['Sheet1']
workbook
.
close
()
return
response
download_acara_donor
.
short_description
=
'Download Acara Donor as Excel Workbook'
@
admin
.
register
(
AcaraDonor
)
class
AcaraDonorAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'nama_institusi'
,
'alamat_lokasi_donor'
,
'display_waktu'
,
'status'
)
list_filter
=
(
'status'
,
AcaraDonorFilter
,
'kecamatan'
,
'kategori'
)
search_fields
=
(
'waktu_mulai'
,)
search_fields
=
(
'waktu_mulai'
,
'alamat_lokasi_donor'
)
readonly_fields
=
(
'id'
,
'user'
,
'nama_institusi'
,
...
...
@@ -43,4 +24,59 @@ class AcaraDonorAdmin(admin.ModelAdmin):
'email_koor'
,
'no_telp_koor'
,
'keterangan'
,
'foto_lokasi'
)
'foto_lokasi'
,
'show_image'
)
fieldsets
=
(
(
None
,
{
'fields'
:
(
'id'
,
'user'
,
'status'
)
}),
(
'INFORMASI ACARA DONOR'
,
{
'fields'
:
(
'kategori'
,
'alamat_lokasi_donor'
,
'kecamatan'
,
(
'waktu_mulai'
,
'waktu_berakhir'
),
'perkiraan_jumlah_donor'
,
'keterangan'
,
'show_image'
)
}),
(
'INFORMASI PENYELENGGARA'
,
{
'fields'
:
(
'nama_institusi'
,
'alamat_institusi'
,
'email_kantor'
,
'no_telp_kantor'
)
}),
(
'KONTAK KOORDINATOR'
,
{
'fields'
:
(
'nama_koor'
,
'email_koor'
,
'no_telp_koor'
)
}),
)
def
display_waktu
(
self
,
obj
):
"""Create a string for waktu acara donor."""
waktu_mulai
=
localtime
(
obj
.
waktu_mulai
)
waktu_berakhir
=
localtime
(
obj
.
waktu_berakhir
)
return
f
"
{
waktu_mulai
.
date
().
strftime
(
'%d/%m/%Y'
)
}
\
(
{
waktu_mulai
.
hour
:
02
d
}
:
{
waktu_mulai
.
minute
:
02
d
}
\
-
{
waktu_berakhir
.
hour
:
02
d
}
:
{
waktu_berakhir
.
minute
:
02
d
}
)"
def
show_image
(
self
,
obj
):
"""Create an image preview for foto lokasi acara donor."""
return
mark_safe
(
'<img src="%s" style="width=auto; height=auto;
\
max-height: 1000px; max-width: 1000px;" />'
%
(
obj
.
foto_lokasi
.
url
))
display_waktu
.
short_description
=
'Waktu'
show_image
.
short_description
=
'Preview foto lokasi'
class
Media
:
js
=
[
settings
.
MEDIA_URL
+
'/js/acara_donor_custom_admin.js'
,
]
def
save_model
(
self
,
request
,
obj
,
form
,
change
):
if
(
obj
.
status
):
JadwalDonor
.
objects
.
create
(
kecamatan
=
obj
.
kecamatan
,
location
=
obj
.
alamat_lokasi_donor
,
time_start
=
obj
.
waktu_mulai
,
time_end
=
obj
.
waktu_berakhir
,
quota
=
obj
.
perkiraan_jumlah_donor
,
category
=
obj
.
kategori
)
super
().
save_model
(
request
,
obj
,
form
,
change
)
backend/acara_donor/factories.py
View file @
654cbdc6
...
...
@@ -26,17 +26,15 @@ class AcaraDonorFactory(factory.DjangoModelFactory):
email_koor
=
factory
.
Faker
(
'free_email'
,
locale
=
LOCALE
)
no_telp_koor
=
factory
.
Sequence
(
lambda
n
:
'021-1128-%04d'
%
n
)
kategori
=
factory
.
LazyAttribute
(
lambda
_
:
choice
(
JadwalDonor
.
Category
.
choices
)[
0
])
kategori
=
factory
.
LazyAttribute
(
lambda
_
:
choice
(
JadwalDonor
.
Category
.
choices
)[
0
])
# NOSONAR
alamat_lokasi_donor
=
factory
.
Faker
(
'address'
,
locale
=
LOCALE
)
kecamatan
=
factory
.
LazyAttribute
(
lambda
_
:
choice
(
JadwalDonor
.
Kecamatan
.
choices
)[
0
])
waktu_mulai
=
factory
.
LazyAttribute
(
lambda
_
:
timezone
.
now
()
+
timedelta
(
days
=
randint
(
1
,
66
),
hours
=
randint
(
1
,
23
)))
# NOSONAR
waktu_berakhir
=
factory
.
LazyAttribute
(
lambda
t
:
t
.
waktu_mulai
+
timedelta
(
hours
=
randint
(
2
,
6
)))
# NOSONAR
kecamatan
=
factory
.
LazyAttribute
(
lambda
_
:
choice
(
JadwalDonor
.
Kecamatan
.
choices
)[
0
])
# NOSONAR
waktu_mulai
=
factory
.
LazyAttribute
(
lambda
_
:
timezone
.
now
()
+
timedelta
(
days
=
randint
(
1
,
66
),
# NOSONAR
hours
=
randint
(
1
,
23
)))
# NOSONAR
waktu_berakhir
=
factory
.
LazyAttribute
(
lambda
t
:
t
.
waktu_mulai
+
timedelta
(
hours
=
randint
(
2
,
6
)))
# NOSONAR
perkiraan_jumlah_donor
=
factory
.
fuzzy
.
FuzzyInteger
(
low
=
33
,
high
=
666
)
keterangan
=
factory
.
Faker
(
'text'
)
backend/acara_donor/migrations/0002_auto_20200602_2055.py
0 → 100644
View file @
654cbdc6
# Generated by Django 3.0.5 on 2020-06-02 13:55
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'acara_donor'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'acaradonor'
,
name
=
'status'
,
field
=
models
.
BooleanField
(
default
=
None
,
null
=
True
),
),
]
backend/acara_donor/models.py
View file @
654cbdc6
...
...
@@ -7,7 +7,7 @@ from donor.models import JadwalDonor
class
AcaraDonor
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
)
status
=
models
.
BooleanField
(
null
=
True
)
status
=
models
.
BooleanField
(
null
=
True
,
default
=
None
)
nama_institusi
=
models
.
CharField
(
max_length
=
95
)
alamat_institusi
=
models
.
CharField
(
max_length
=
140
)
...
...
@@ -18,10 +18,10 @@ class AcaraDonor(models.Model):
email_koor
=
models
.
EmailField
()
no_telp_koor
=
models
.
CharField
(
max_length
=
20
)
kategori
=
models
.
CharField
(
max_length
=
20
,
kategori
=
models
.
CharField
(
max_length
=
20
,
blank
=
False
,
null
=
False
,
choices
=
JadwalDonor
.
Category
.
choices
)
alamat_lokasi_donor
=
models
.
CharField
(
max_length
=
140
)
kecamatan
=
models
.
CharField
(
max_length
=
20
,
kecamatan
=
models
.
CharField
(
max_length
=
20
,
blank
=
False
,
null
=
False
,
choices
=
JadwalDonor
.
Kecamatan
.
choices
)
waktu_mulai
=
models
.
DateTimeField
()
waktu_berakhir
=
models
.
DateTimeField
()
...
...
backend/acara_donor/serializers.py
View file @
654cbdc6
...
...
@@ -26,4 +26,5 @@ class AcaraDonorSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
AcaraDonor
exclude
=
[
"user"
,
]
extra_kwargs
=
{
'foto_lokasi'
:
{
'required'
:
False
}}
extra_kwargs
=
{
'foto_lokasi'
:
{
'required'
:
False
},
'status'
:
{
'default'
:
None
}}
backend/acara_donor/tests.py
View file @
654cbdc6
import
datetime
from
unittest.mock
import
patch
from
django.contrib.auth
import
get_user_model
from
django.test
import
TestCase
from
django.utils
import
timezone
from
django.utils.timezone
import
localtime
...
...
@@ -14,9 +13,6 @@ from acara_donor.admin import AcaraDonorAdmin
from
acara_donor.filters
import
AcaraDonorFilter
User
=
get_user_model
()
class
AcaraDonorTest
(
TestCase
):
""" Test module for Acara Donor model"""
...
...
backend/donor/admin.py
View file @
654cbdc6
from
django.contrib
import
admin
from
django.conf
import
settings
from
django.http
import
HttpResponse
from
donor.models
import
JadwalDonor
,
DaftarDonor
...
...
@@ -65,12 +66,70 @@ download_jadwaldonor.short_description = 'Download Jadwal Donor as Excel Workboo
@
admin
.
register
(
JadwalDonor
)
class
JadwalDonorAdmin
(
admin
.
ModelAdmin
):
list_filter
=
(
'kecamatan'
,
'time_start'
,
'category'
)
search_fields
=
(
'time_start'
,
'location'
)
actions
=
[
download_jadwaldonor
]
class
Media
:
js
=
[
settings
.
MEDIA_URL
+
'/js/acara_donor_custom_admin.js'
,
]
@
admin
.
register
(
DaftarDonor
)
class
DaftarDonorAdmin
(
admin
.
ModelAdmin
):
list_filter
=
(
'has_attended'
,
)
list_display
=
(
'user'
,
'has_attended'
,
'get_goldar'
,
'jadwal_donor'
)
search_fields
=
(
'user__email'
,
'jadwal_donor__location'
,
'jadwal_donor__time_start'
)
fields
=
(
'has_attended'
,
'id'
,
'user'
,
'jadwal_donor'
,
'merasa_sehat'
,
'minum_antibiotik'
,
'minum_obat_infeksi'
,
'minum_aspirin'
,
'sakit_kepala_dan_demam'
,
'sedang_hamil'
,
'kehamilan_berapa'
,
'donor_darah_trombosit_plasma'
,
'menerima_vaksinasi'
,
'kontak_vaksinasi'
,
'donor_aferesis'
,
'pernah_transfusi'
,
'pernah_transplasi'
,
'pernah_cangkok_tulang'
,
'pernah_tusuk_jarum_medis'
,
'pernah_seks_aids'
,
'pernah_seks_psk'
,
'pernah_seks_narkoba'
,
'pernah_seks_konsentrat'
,
'wanita_pernah_seks_laki_biseksual'
,
'pernah_seks_dengan_hepatitis'
,
'tinggal_dengan_hepatitis'
,
'punya_tato'
,
'punya_tindik'
,
'sedang_sifilis_go'
,
'pernah_dipenjara'
,
'pernah_di_luar_indonesia'
,
'pernah_jualan_seks'
,
'pernah_homoseks'
,
'pernah_tinggal_di_eropa'
,
'pernah_terima_transfusi_di_inggris'
,
'pernah_tinggal_di_inggris'
,
'positif_aids'
,
'pakai_jarum_suntik'
,
'pakai_konsentrat'
,
'menderita_hepatitis'
,
'menderita_malaria'
,
'menderita_kanker'
,
'bermasalah_jantung_paru_paru'
,
'menderita_pendarahan'
,
'seks_dengan_orang_afrika'
,
'tinggal_di_afrika'
)
list_filter
=
(
'has_attended'
,
'user__profile__blood_type'
)
def
get_goldar
(
self
,
obj
):
return
obj
.
user
.
profile
.
blood_type
get_goldar
.
short_description
=
'Goldar'
get_goldar
.
admin_order_field
=
'user__profile__blood_type'
def
get_readonly_fields
(
self
,
request
,
obj
=
None
):
readonly_fields
=
list
(
set
(
...
...
@@ -80,3 +139,6 @@ class DaftarDonorAdmin(admin.ModelAdmin):
if
'has_attended'
in
readonly_fields
:
readonly_fields
.
remove
(
'has_attended'
)
return
readonly_fields
class
Media
:
js
=
[
settings
.
MEDIA_URL
+
'/js/daftar_donor_custom_admin.js'
,
]
backend/donor/migrations/0012_auto_20200604_1236.py
0 → 100644
View file @
654cbdc6
# Generated by Django 3.0.5 on 2020-06-04 05:36
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'donor'
,
'0011_auto_20200602_0227'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'jadwaldonor'
,
name
=
'location'
,
field
=
models
.
CharField
(
max_length
=
140
),
),
]
backend/donor/models.py
View file @
654cbdc6
...
...
@@ -26,7 +26,7 @@ class JadwalDonor(models.Model):
PRIVATE
=
"Tertutup"
kecamatan
=
models
.
CharField
(
max_length
=
20
,
choices
=
Kecamatan
.
choices
)
location
=
models
.
CharField
(
max_length
=
3
0
)
location
=
models
.
CharField
(
max_length
=
14
0
)
time_start
=
models
.
DateTimeField
()
time_end
=
models
.
DateTimeField
()
quota
=
models
.
PositiveIntegerField
()
...
...
backend/edukasi/admin.py
View file @
654cbdc6
from
django.contrib
import
admin
from
django.conf
import
settings
from
edukasi.models
import
Artikel
@
admin
.
register
(
Artikel
)
class
ArtikelAdmin
(
admin
.
ModelAdmin
):
pass
list_display
=
(
'title'
,
'posted_at'
)
search_fields
=
(
'posted_at'
,
'title'
)
fields
=
(
'posted_at'
,
'title'
,
'featured_image'
,
'content'
)
readonly_fields
=
(
'posted_at'
,)
class
Media
:
js
=
[
settings
.
MEDIA_URL
+
'/js/artikel_custom_admin.js'
,
]
backend/edukasi/factories.py
View file @
654cbdc6
...
...
@@ -12,6 +12,6 @@ class ArtikelFactory(factory.DjangoModelFactory):
class
Meta
:
model
=
Artikel
title
=
fake
.
sentence
()[:
-
1
][:
30
]
title
=
fake
.
sentence
()[:
-
1
][:
58
]
featured_image
=
os
.
path
.
join
(
"edukasi"
,
"placeholder.jpg"
)
content
=
"
\n
"
.
join
(
fake
.
paragraphs
())
backend/edukasi/management/commands/seed_artikel.py
View file @
654cbdc6
...
...
@@ -14,9 +14,9 @@ class Command(BaseCommand):
help
=
'Add dummy data artikel edukasi'
def
handle
(
self
,
*
args
,
**
options
):
for
i
in
range
(
20
):
for
_
in
range
(
20
):
content
=
[]
for
i
in
range
(
5
):
for
_
in
range
(
5
):
content
.
append
(
" "
.
join
(
fake
.
paragraphs
()))
Artikel
.
objects
.
create
(
title
=
fake
.
sentence
()[:
-
1
][:
30
],
...
...
backend/edukasi/migrations/0003_auto_20200603_2016.py
0 → 100644
View file @
654cbdc6
# Generated by Django 3.0.5 on 2020-06-03 13:16
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'edukasi'
,
'0002_artikel_posted_at'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'artikel'
,
name
=
'title'
,
field
=
models
.
CharField
(
max_length
=
25
),
),
]
backend/edukasi/migrations/0004_auto_20200603_2020.py
0 → 100644
View file @
654cbdc6
# Generated by Django 3.0.5 on 2020-06-03 13:20
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'edukasi'
,
'0003_auto_20200603_2016'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'artikel'
,
name
=
'title'
,
field
=
models
.
CharField
(
max_length
=
30
),
),
]
backend/edukasi/migrations/0005_auto_20200603_2118.py
0 → 100644
View file @
654cbdc6
# Generated by Django 3.0.5 on 2020-06-03 14:18
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'edukasi'
,
'0004_auto_20200603_2020'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'artikel'
,
name
=
'title'
,
field
=
models
.
CharField
(
max_length
=
60
),
),
]
backend/edukasi/models.py
View file @
654cbdc6
...
...
@@ -2,7 +2,7 @@ from django.db import models
class
Artikel
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
32
)
title
=
models
.
CharField
(
max_length
=
60
)
featured_image
=
models
.
ImageField
()
content
=
models
.
TextField
()
posted_at
=
models
.
DateTimeField
(
auto_now_add
=
True
)
...
...
backend/edukasi/serializers.py
View file @
654cbdc6
...
...
@@ -6,4 +6,4 @@ from .models import Artikel
class
ArtikelSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Artikel
fields
=
[
'id'
,
'title'
,
'featured_image'
,
'content'
]
fields
=
[
'id'
,
'title'
,
'featured_image'
,
'content'
,
'posted_at'
]
backend/main/admin.py
View file @
654cbdc6
from
django.contrib
import
admin
from
django.conf
import
settings
from
django.contrib.auth.admin
import
UserAdmin
as
DjangoUserAdmin
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -9,10 +10,17 @@ from .models import User, Profile
class
UserAdmin
(
DjangoUserAdmin
):
"""Define admin model for custom User model with no username field."""
readonly_fields
=
(
'email'
,
'first_name'
,
'last_name'
,
'last_login'
,
'date_joined'
)
fieldsets
=
(
(
None
,
{
'fields'
:
(
'email'
,
'password'
)}),
(
_
(
'Personal info'
),
{
'fields'
:
(
'first_name'
,
'last_name'
)}),
(
_
(
'Permissions'
),
{
'fields'
:
(
'is_active'
,
'is_staff'
,
'is_superuser'
,
'is_verified'
,
(
_
(
'Permissions'
),
{
'fields'
:
(
'is_active'
,
'is_staff'
,
'is_superuser'
,
'is_verified'
,
'groups'
,
'user_permissions'
)}),
(
_
(
'Important dates'
),
{
'fields'
:
(
'last_login'
,
'date_joined'
)}),
)
...
...
@@ -26,7 +34,61 @@ class UserAdmin(DjangoUserAdmin):
search_fields
=
(
'email'
,
'first_name'
,
'last_name'
)
ordering
=
(
'email'
,)
class
Media
:
js
=
[
settings
.
MEDIA_URL
+
'/js/user_custom_admin.js'
,
]
@
admin
.
register
(
Profile
)
class
ProfileAdmin
(
admin
.
ModelAdmin
):
pass
list_display
=
(
'user'
,
'district'
,
'address'
,
'age'
,
'sex'
,
'blood_type'
)
list_filter
=
(
'blood_type'
,
'sex'
)
search_fields
=
(
'address'
,
'district'
)
readonly_fields
=
(
'user'
,
'body_weight'
,
'id_card_no'
,
'birthplace'
,
'birthdate'
,
'sex'
,
'profession'
,
'blood_type'
,
'married_status'
,
'address'
,
'city'
,
'district'
,
'village'
,
'phone_no'
,
'work_address'
,
'work_email'
,
'work_phone_no'
,
'age'
)
fieldsets
=
(
(
None
,
{
'fields'
:
(
'user'
,)}),
(
'INFORMASI PRIBADI'
,
{
'fields'
:
(
'id_card_no'
,
'birthplace'
,
'birthdate'
,
'age'
,
'body_weight'
,
'sex'
,
'profession'
,
'blood_type'
,
'married_status'
)
}),
(
'ALAMAT'
,
{
'fields'
:
(
'address'
,
'village'
,
'district'
,
'city'
,
'work_address'
)
}),
(
'KONTAK'
,
{
'fields'
:
(
'phone_no'
,
'work_email'
,
'work_phone_no'
)
}),
)
class
Media
:
js
=
[
settings
.
MEDIA_URL
+
'/js/profile_custom_admin.js'
,
]
backend/main/models.py
View file @
654cbdc6
...
...
@@ -98,7 +98,7 @@ class Profile(models.Model):
return
today
.
year
-
born
.
year
-
((
today
.
month
,
today
.
day
)
<
(
born
.
month
,
born
.
day
))
def
__str__
(
self
):
return
f
'(
{
self
.
sex
}
,
{
self
.
blood_type
}
)'
return
f
'
{
self
.
user
}
(
{
self
.
sex
}
,
{
self
.
blood_type
}
)'
class
Meta
:
pass
backend/main/test_models.py
View file @
654cbdc6
...
...
@@ -105,7 +105,7 @@ class ProfileTests(TestCase):
profile__sex
=
Sex
.
FEMALE
,
profile__blood_type
=
'O+'
)
self
.
assertEqual
(
str
(
user
.
profile
),
'
(F, O+)'
)
self
.
assertEqual
(
str
(
user
.
profile
),
f
'
{
str
(
user
)
}
(F, O+)'
)
def
test_dont_save_new_profile_on_user_update
(
self
):
user
=
UserFactory
(
last_name
=
'Musthofa'
)
...
...
Prev
1
2
3
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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