Skip to content

Instantly share code, notes, and snippets.

@mchoiruln
Created October 21, 2021 06:45
Show Gist options
  • Save mchoiruln/adb9238f884cda9b098e47e7f44b0856 to your computer and use it in GitHub Desktop.
Save mchoiruln/adb9238f884cda9b098e47e7f44b0856 to your computer and use it in GitHub Desktop.
list_ppk
def list_ppk(request):
if request.method != 'GET':
return JsonResponse({'status': 'method not allowed'}, status=405)
api_key = ''
status = 200
result = []
try:
if request.META['HTTP_AUTHORIZATION'] != 'Bearer {}'.format(api_key):
return JsonResponse({'status': 'api authentication failed'}, status=400)
# ppks = PpkView.objects.list_ppk()
ppks = Pegawai.objects.select_related('satker').filter(pegawaigroup__groupid='PPK')
tgl1 = request.GET.get('date', None)
tgl2 = request.GET.get('dateEnd', None)
if tgl1 is not None:
ppks = ppks.filter(auditupdate__gte=datetime.fromtimestamp(int(tgl1)))
if tgl2 is not None:
ppks = ppks.filter(auditupdate__lte=datetime.fromtimestamp(int(tgl2)))
ppks = ppks.exclude(peg_nip='1.05.013220').exclude(peg_nip='1.05.01322')
ppks = ppks.exclude(peg_nip='10601376')
ppks = ppks.exclude(peg_isactive=0) # status nonaktif
batas_sirup = datetime.fromisoformat('2019-01-02 00:00:00')
for ppk in ppks:
last_update = ppk.auditupdate
if last_update < batas_sirup:
last_update = batas_sirup + timedelta(hours=8)
row = {'ID': ppk.peg_id, 'NAMA': ppk.peg_nama, 'JABATAN': ppk.peg_jabatan,
'ALAMAT': ppk.peg_alamat, 'STATUS_PENGGUNA': 1,
'NIP': ppk.peg_nip, 'GOLONGAN': ppk.peg_golongan,
'NO_TELEPON': ppk.peg_telepon, 'EMAIL': ppk.peg_email,
'NO_SK': ppk.peg_no_sk, 'KODE_PD': ppk.satker.stk_kode,
'CREATED_TIME': None,
'LASTUPDATE_TIME': last_update}
result.append(row)
except KeyError:
status = 400 # bad request
return JsonResponse({'status': 'api authentication failed'}, status=status)
return JsonResponse(result, status=status, safe=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment