def post(self, request, nis): siswa_form = SiswaForm(request.POST) siswa = Siswa.objects.get(nis=nis) try: old_kelas = siswa.kelas.get(tahun_pelajaran=active_tp()) except ObjectDoesNotExist: old_kelas = None if siswa_form.is_valid(): data = form_value(siswa_form) kelas = data['kelas'] del data['kelas'] if old_kelas: siswa.kelas.remove(old_kelas) if kelas: siswa.kelas.add(kelas) siswa.save() Siswa.objects.filter(nis=nis).update(**data) messages.success(request, f'Profil {siswa.nama} berhasil diubah') return redirect('detail-siswa', nis=nis) else: context = { 'siswa_form': siswa_form, } return render(request, 'pages/siswa/detail-siswa.html', context)
def post(self, request, matapelajaran): matapelajaran_form = EditMatapelajaranForm(request.POST) try: if matapelajaran_form.is_valid(): data = form_value(matapelajaran_form) pengetahuan = data['pengetahuan'] keterampilan = data['keterampilan'] del data['pengetahuan'] del data['keterampilan'] MataPelajaran.objects.filter(pk=matapelajaran).update(**data) kkm = KKM.objects.get(matapelajaran__pk=matapelajaran, tahun_pelajaran=active_tp()) kkm.pengetahuan = pengetahuan kkm.keterampilan = keterampilan kkm.save() messages.success( request, f'Data Matapelajaran {kkm.matapelajaran.nama} berhasil diubah' ) except Exception as e: messages.error(request, e) finally: return redirect('detail-matapelajaran', matapelajaran=matapelajaran)
def post(self, request, guru): gelar_form = GelarForm(request.POST) try: subjek = Guru.objects.get(nip=guru) except Guru.DoesNotExist: raise Http404 if gelar_form.is_valid(): Gelar.objects.create(**form_value(gelar_form), guru=subjek) messages.success(request, 'Gelar berhasil ditambahkan') return redirect('detail-guru', guru=guru)
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 post(self, request): sekolah_form = SekolahForm(request.POST) try: if sekolah_form.is_valid(): Sekolah.objects.update(**form_value(sekolah_form)) Sekolah.objects.get().save() messages.success(request, 'Data Sekolah berhasil diubah') except Exception as e: messages.error(request, e) finally: return redirect('detail-sekolah')
def post(self, request): matapelajaran_form = MatapelajaranForm(request.POST) try: if matapelajaran_form.is_valid(): mapel = MataPelajaran.objects.create( **form_value(matapelajaran_form)) messages.success(request, f'{mapel.nama} berhasil dibuat') except Exception as e: messages.error( request, 'Terjadi kesalahan saat mencoba membuat Matapelajaran') finally: return redirect('list-matapelajaran')
def post(self, request): jurusan_form = JurusanForm(request.POST) try: if jurusan_form.is_valid(): jurusan = Jurusan.objects.create(**form_value(jurusan_form)) messages.success(request, f'Jurusan {jurusan.nama} berhasil dibuat') except ValidationError: messages.error(request, f'Jurusan itu sudah tersedia') except Exception as e: messages.error(request, f'Terjadi kesalahan saat membuat jurusan') finally: return redirect('list-jurusan')
def post(self, request): semester_form = SemesterForm(request.POST) try: if semester_form.is_valid(): TahunPelajaran.objects.create(**form_value(semester_form)) messages.success(request, 'Tahun Pelajaran berhasil dibuat') except ValidationError: messages.error( request, 'Tahun Pelajaran dengan data persis seperti itu sudah ada') except Exception as e: print(e) finally: return redirect('list-semester')
def post(self, request): ekskul_form = EkskulForm(request.POST) try: if ekskul_form.is_valid(): ekskul = Ekskul.objects.create(**form_value(ekskul_form)) messages.success( request, f'Ekstrakulikuler {ekskul.nama} berhasil dibuat') except ValidationError: messages.error( request, f'Ekskul dengan data persis seperti itu sudah tersedia') except Exception as e: messages.error(request, f'Terjadi kesalahan saat membuat ekskul ') finally: return redirect('list-ekskul')
def post(self, request): kelas_form = KelasForm(tingkat_choice(get_sekolah()), walikelas_choice(get_validwalikelas()), request.POST) try: if kelas_form.is_valid(): try: kelas_form.cleaned_data['walikelas'] = Guru.objects.get( nip=kelas_form.cleaned_data['walikelas']) except Guru.DoesNotExist: kelas_form.cleaned_data['walikelas'] = None Kelas.objects.create(**form_value(kelas_form), tahun_pelajaran=active_tp()) messages.success( request, 'Kelas berhasil dibuat, segera lengkapi data kelas tadi') except ValidationError: messages.error(request, 'Kelas itu sudah ada') finally: return redirect('list-kelas')
def post(self, request): guru_form = GuruCreateForm(request.POST) try: if guru_form.is_valid(): guru = Guru.objects.create(**form_value(guru_form), is_active=True) guru.set_password(guru_form.cleaned_data['password']) guru.save() messages.success(request, 'Akun berhasil dibuat') except IntegrityError: registered_nip = Guru.objects.get( nip=guru_form.cleaned_data['nip']) if not registered_nip.is_active: messages.error( request, 'Akun dengan NIP itu sudah ada tetapi statusnya nonaktif, silahkan minta admin untuk mengaktifkan akun tadi' ) else: messages.error(request, 'Akun dengan NIP itu sudah ada') finally: return redirect('list-guru')
def post(self, request, guru): profile_form = GuruEditForm(request.POST, request.FILES) try: if profile_form.is_valid(): Guru.objects.filter(nip=guru).update( **form_value(profile_form)) subjek = Guru.objects.get(nip=guru) try: new_ava = request.FILES['avatar'] if '.' in str(new_ava)[-4:]: ext = str(new_ava)[-3:] else: ext = str(new_ava)[-4:] ava_dir = f'{MEDIA_ROOT}/avatar/guru/{subjek.nip}.{ext}' with open(ava_dir, 'wb+') as destination: for chunk in new_ava.chunks(): destination.write(chunk) destination.close() subjek.avatar = ava_dir subjek.save() except MultiValueDictKeyError: try: clearbox = request.POST['avatar-clear'] if clearbox == 'on': subjek.avatar = avatarAPI(subjek) subjek.save() except: pass except Exception as e: messages.error(request, e) messages.success(request, 'Update profil berhasil!') else: messages.error( request, 'Silahkan pilih salah satu antara melakukan clear avatar atau mengupload avatar baru' ) except Exception as e: messages.error(request, e) finally: return redirect('detail-guru', guru=guru)
def post(self, request): siswa_form = SiswaForm(request.POST) try: if siswa_form.is_valid(): data = form_value(siswa_form) kelas = data['kelas'] del data['kelas'] siswa = Siswa.objects.create(**data) siswa.kelas.add(kelas) messages.success( request, 'Data siswa berhasil dicatat kedalam database') else: messages.error( request, 'Data gagal dibuat, periksa apakah NIS atau NISN sudah tersedia di basis data' ) except IntegrityError: messages.error( request, 'Data gagal dibuat, periksa apakah NIS atau NISN sudah tersedia di basis data' ) finally: return redirect('list-siswa')