def get(self, request, kelas, **kwargs): try: sekolah = Sekolah.objects.get() semester = active_semester() tp = active_tp() kelas = Kelas.objects.get(nama=kelas, tahun_pelajaran=tp) siswa = Siswa.objects.filter(kelas=kelas) except ObjectDoesNotExist: raise Http404 for siswa in siswa: context = generate_rapor_context(sekolah, semester, siswa) generate_pdf(siswa, kwargs['pdf_dir'], context) bundle_dir = f'{settings.MEDIA_ROOT}/rapor/{kelas.tahun_pelajaran.mulai} - {kelas.tahun_pelajaran.akhir} {semester.semester}/bundel/{kelas.jurusan}' if not os.path.isdir(bundle_dir): os.makedirs(bundle_dir) shutil.make_archive(f'{bundle_dir}/Rapor-{kelas.nama}', 'zip', kwargs['pdf_dir']) zip_file = open(f'{bundle_dir}/Rapor-{kelas.nama}.zip', 'rb') response = FileResponse(zip_file, content_type='application/force-download') response[ 'Content-Disposition'] = f'attachment; filename=Rapor-{kelas.nama}.zip' return response
def get(self, request): request.session['page'] = 'Daftar Kelas' semester = active_semester() if 'search' in request.GET and request.GET['search'] != '': list_kelas = Kelas.objects.filter( Q(tahun_pelajaran=semester.tahun_pelajaran) & (Q(nama__icontains=request.GET['search']) | Q(walikelas__nama__icontains=request.GET['search'])) ).order_by('jurusan', 'tingkat', 'kelas') else: list_kelas = Kelas.objects.filter( tahun_pelajaran=semester.tahun_pelajaran).order_by( 'jurusan', 'tingkat', 'kelas') paginator = Paginator(list_kelas, 5) page_number = request.GET.get('page') page_obj = paginator.get_page(page_number) number_of_pages = [(number + 1) for number in range(page_obj.paginator.num_pages)] context = { 'page_obj': page_obj, 'number_of_pages': number_of_pages, 'list_kelas': list_kelas, } return render(request, 'pages/kelas/kelas.html', context)
def wrapper(request, *args, **kwargs): if active_semester(): return function(request, *args, **kwargs) else: messages.error( request, 'Halaman itu tidak bisa diakses sebelum ada semester yang diaktifkan' ) return redirect('dashboard')
def post(self, request, nis): active_siswa = Siswa.objects.get(nis=nis) absen_form = AbsenForm(request.POST) if absen_form.is_valid(): Absensi.objects.filter( siswa=active_siswa, semester=active_semester()).update(**form_value(absen_form)) messages.success(request, f'Update absensi {active_siswa.nama} berhasil') return redirect('detail-siswa', nis=nis)
def get(self, request, nis, ekskul): active_siswa = Siswa.objects.get(nis=nis) ekskul = Ekskul.objects.get(pk=ekskul) NilaiEkskul.objects.get(ekskul=ekskul, siswa=active_siswa, semester=active_semester()).delete() messages.success( request, f'Ekskul {ekskul.nama} sudah dihapus dari data {active_siswa.nama}' ) return redirect('detail-siswa', nis=nis)
def get(self, request, nis): semester = active_semester() try: siswa = Siswa.objects.prefetch_related('kelas').get(nis=nis) kelas_aktif = siswa.kelas.get( tahun_pelajaran=semester.tahun_pelajaran) except Siswa.DoesNotExist: raise Http404 except Kelas.DoesNotExist: kelas_aktif = None initial = get_initial(siswa) initial['kelas'] = kelas_aktif request.session['page'] = f'Detail {siswa.nama}' if not kelas_aktif: messages.info( request, f'{siswa.nama} belum memiliki kelas di semester ini') absen, created = Absensi.objects.get_or_create(siswa=siswa, semester=semester, defaults={ 'izin': 0, 'sakit': 0, 'bolos': 0 }) context = { 'siswa': siswa, 'kelas': kelas_aktif, 'absensi': absen, 'semester': semester, 'siswa_form': SiswaForm(initial=initial), 'absen_form': AbsenForm(initial=get_initial(absen)), 'nilai_form': zip_pelnilai(siswa, semester), 'data_ekskul': zip_eksnilai(siswa, semester), 'ekskul_form': TambahEkskulSiswaForm( ekskul_list=tambahmapel_choice(get_validekskul(siswa))), 'usia': calculate_age(siswa.tanggal_lahir), } return render(request, 'pages/siswa/detail-siswa.html', context)
def get(self, request): request.session['page'] = 'Dashboard' semester = active_semester() list_tp = TahunPelajaran.objects.all() list_tp = [tp for tp in list_tp] siswa_pria = [ Siswa.objects.exclude(kelas=None).filter(kelas__tahun_pelajaran=tp, gender='P').count() for tp in list_tp ] siswa_wanita = [ Siswa.objects.exclude(kelas=None).filter(kelas__tahun_pelajaran=tp, gender='W').count() for tp in list_tp ] tp = active_tp() context = { 'sekolah': get_sekolah(), 'semester': semester, 'siswa_berkelas': Siswa.objects.exclude(kelas=None).filter( kelas__tahun_pelajaran=tp).count(), 'siswa_nokelas': Siswa.objects.exclude(kelas__tahun_pelajaran=tp).filter( kelas=None).count(), 'jumlah_kelas': Kelas.objects.filter(tahun_pelajaran=tp).count(), 'jumlah_jurusan': Jurusan.objects.count(), 'jumlah_guru': Guru.objects.count(), 'jumlah_walikelas': Guru.objects.filter(is_walikelas=True, is_staftu=False).count(), 'jumlah_tu': Guru.objects.filter(is_staftu=True, is_walikelas=False).count(), 'jumlah_admin': Guru.objects.filter( Q( Q(is_walikelas=True) & Q(is_staftu=True) | Q(is_superuser=True))).count(), 'jumlah_mapel': MataPelajaran.objects.count(), 'jumlah_ekskul': Ekskul.objects.count(), 'chart_data': zip(list_tp, siswa_pria, siswa_wanita), } return render(request, 'pages/dashboard.html', context)
def get(self, request): semester = active_semester() qs = list(Siswa.objects.select_related('kelas').all().values()) if not qs: messages.error(request, 'Tidak ada data siswa yang dapat di ekspor') return redirect('list-siswa') cols = [] for col in [field.name for field in Siswa._meta.fields]: if col in ['id']: continue if col in ['nis', 'nisn']: col = col.upper() else: col = col.title() col = col.replace('_', ' ') cols.append(col) cols.append('Kelas') for siswa in qs: try: siswa['kelas_id'] = Siswa.objects.get( nis=siswa['nis']).kelas.get( tahun_pelajaran=semester.tahun_pelajaran).nama.replace( '-', ' ') except Kelas.DoesNotExist: siswa['kelas_id'] = None siswa['tanggal_lahir'] = siswa['tanggal_lahir'].strftime( '%Y-%m-%d') if siswa['gender'] == 'P': siswa['gender'] = 'Pria' else: siswa['gender'] = 'Wanita' file = f'{settings.MEDIA_ROOT}/excel/Export Siswa.xlsx' json_string = json.dumps(qs) df = pandas.read_json(json_string, dtype={'nis': str, 'nisn': str}) df = df.drop(columns='id') df.columns = cols append_df_to_excel(file, df) file = open(file, 'rb') response = FileResponse(file, content_type='application/force-download') response[ 'Content-Disposition'] = f'attachment; filename=Siswa {semester}.xlsx' return response
def post(self, request, nis): active_siswa = Siswa.objects.get(nis=nis) semester = active_semester() data = zip_eksnilai(active_siswa, semester) try: for id_eks, id_nil, ekskul, nilai, jenis in data: nilai_form = request.POST[f'nilai-{id_eks}'] if nilai_form and nilai != nilai_form: ekskul = Ekskul.objects.get(pk=id_eks) NilaiEkskul.objects.filter( siswa=active_siswa, ekskul=ekskul, semester=semester).update(nilai=nilai_form) messages.success( request, f'Nilai {active_siswa.nama} untuk ekskul {ekskul.nama} berhasil diubah' ) except Exception as e: messages.error(request, e) return redirect('detail-siswa', nis=nis)
def wrapper(request, *args, **kwargs): try: if kwargs['nis']: siswa = Siswa.objects.get(nis=kwargs['nis']) kelas = get_validkelas(siswa) except KeyError: try: if kwargs['kelas']: kelas = Kelas.objects.get(nama=kwargs['kelas'], tahun_pelajaran=active_tp()) except KeyError: kelas = None return redirect('dashboard') semester = active_semester() dirs = f'{settings.MEDIA_ROOT}/rapor/{kelas.tahun_pelajaran.mulai} - {kelas.tahun_pelajaran.akhir} {semester.semester}/{kelas.jurusan}/{kelas.nama}' if not os.path.isdir(dirs): os.makedirs(dirs) kwargs['pdf_dir'] = dirs return function(request, *args, **kwargs)
def post(self, request, nis): try: active_siswa = Siswa.objects.get(nis=nis) semester = active_semester() data = zip_pelnilai(active_siswa, semester) for id_, matapelajaran, pengetahuan, keterampilan in data: matapelajaran = MataPelajaran.objects.get(id=id_) nilai_pengetahuan = int(request.POST[f'pengetahuan-{id_}']) nilai_keterampilan = int(request.POST[f'keterampilan-{id_}']) Nilai.objects.update_or_create(siswa=active_siswa, matapelajaran=matapelajaran, semester=semester, defaults={ 'pengetahuan': nilai_pengetahuan, 'keterampilan': nilai_keterampilan }) messages.success(request, f'Update nilai {active_siswa.nama} berhasil') return redirect('detail-siswa', nis=nis) except Siswa.DoesNotExist: raise Http404
def get(self, request, nis, action, **kwargs): try: siswa = Siswa.objects.get(nis=nis) except ObjectDoesNotExist: raise Http404 sekolah = Sekolah.objects.get() semester = active_semester() context = generate_rapor_context(sekolah, semester, siswa) generate_pdf(siswa, kwargs['pdf_dir'], context) rapor = Rapor.objects.get(siswa=siswa, semester=semester) with open(rapor.rapor, 'rb') as result: response = HttpResponse(result, content_type='application/pdf;') if action == 'unduh': response[ 'Content-Disposition'] = f'attachment; filename={siswa.nama}.pdf' response['Content-Transfer-Encoding'] = 'binary' elif action == 'pratinjau': response[ 'Content-Disposition'] = f'inline; filename={siswa.nama}.pdf' response['Content-Transfer-Encoding'] = 'binary' else: return redirect('dashboard') return response
def post(self, request, nis): ekskul_form = TambahEkskulSiswaForm(request.POST) siswa = Siswa.objects.get(nis=nis) ekskul = request.POST.getlist('ekskul') semester = active_semester() try: for ekskul in ekskul: NilaiEkskul.objects.create( ekskul=Ekskul.objects.get(id=ekskul), siswa=siswa, semester=semester) messages.success( request, f'Ekskul {ekskul_form.cleaned_data["ekskul"]} berhasil ditambahkan untuk {siswa.nama}' ) except ValidationError: messages.error( request, f'{siswa.nama} sudah memiliki ekskul {ekskul_form.cleaned_data["ekskul"]}' ) except Exception as e: request.error(request, e) finally: return redirect('detail-siswa', nis=nis)
def get(self, request, kelas): request.session['page'] = f'Detail {kelas}' tp = active_tp() try: kelas = Kelas.objects.get(nama=kelas, tahun_pelajaran=tp) except ObjectDoesNotExist: raise Http404 try: active_walikelas = Guru.objects.get(kelas=kelas) except ObjectDoesNotExist: active_walikelas = None if active_walikelas == request.user or request.user.is_superuser: auth_walikelas = True else: auth_walikelas = False initial = get_initial(kelas) if initial['walikelas']: initial['walikelas'] = Guru.objects.get(pk=initial['walikelas']) if initial['jurusan']: initial['jurusan'] = Jurusan.objects.get( id=initial['jurusan']).nama list_siswa = Siswa.objects.filter(kelas=kelas).order_by('nama') if list_siswa: finished, unfinished, status = list_siswa_status( list_siswa=list_siswa, semester=active_semester()) else: finished = [] unfinished = [] list_mapel = MataPelajaran.objects.filter( kelas=kelas, kelas__tahun_pelajaran=tp).order_by('kelompok', 'nama') if list_mapel: list_mapel = zip_pelkkm(list_mapel, tp) context = { 'kelas': kelas, 'auth_walikelas': auth_walikelas, 'kelas_form': DisabledKelasForm(initial=initial), 'list_siswa': list_siswa, 'jumlah_siswa': list_siswa.count(), 'status_siswa': f'{len(finished)} Siswa tuntas / {len(unfinished)} Siswa belum tuntas', 'list_matapelajaran': list_mapel, 'active_walikelas': active_walikelas, 'valid_walikelas': get_validwalikelas(), 'tambahmapel_form': TambahMatapelajaranKelas( mapel_list=tambahmapel_choice(get_validpelajaran(kelas.nama))), 'tambahanggota_form': TambahAnggotaKelas( anggota_list=tambahanggota_choice(get_validsiswabaru())), } return render(request, 'pages/kelas/detail-kelas.html', context)
def semester_is_active(): return active_semester()
def get_total_siswa_ekskul(ekskul): try: return NilaiEkskul.objects.filter(ekskul=ekskul, semester=active_semester()).count() except ObjectDoesNotExist: return 0