def tugas_create(): form = TugasForm(request.form) if form.validate_on_submit(): tugas = Tugas() form.populate_obj(tugas) user = g.user matkul = MataKuliah.get(MataKuliah.dosen == user) tugas.mata_kuliah = matkul tugas.save() file_list = request.files.getlist('file_pendukung') for f in file_list: if isinstance(f, FileStorage) and len(f.filename) != 0: import os path = generate_path() save_to = os.path.join(path, secure_filename(user.email)) if not os.path.exists(save_to): os.makedirs(save_to) tujuan = os.path.join(save_to, secure_filename(f.filename)) f.save(tujuan) p = Phile.create( filename=f.filename, filepath=tujuan, filetype=f.mimetype ) TugasFile.create(tugas=tugas, phile=p) flash('Sukses membuat tugas') return redirect(url_for('dosen:tugas:list')) return render_template('dosen/tugas/create.html', form=form)
def matkul_delete(matkul_id): if g.user and g.user.level.name == 'admin': matkul = None try: matkul = MataKuliah.get(MataKuliah.id == matkul_id) except MataKuliah.DoesNotExist: flash('Tidak bisa menghapus mata kuliah') if matkul: matkul.delete_instance() flash('Sukses menghapus mata kuliah') return redirect(url_for('admin:matkul:list')) return redirect(url_for('login'))
def matkul_update(matkul_id): matkul = MataKuliah.get(MataKuliah.id == matkul_id) form = MataKuliahForm(request.form, obj=matkul) form.dosen.choices = get_dosen() form.action = url_for('admin:matkul:update', matkul_id=matkul.id) if form.validate_on_submit(): form.populate_obj(matkul) matkul.dosen = User.get(User.id == form.dosen.data) matkul.save() flash('Sukses memperbarui mata kuliah') return redirect(url_for('admin:matkul:list')) return render_template('admin/matkul/update.html', form=form)
def tugas_update(tugas_id): tugas = Tugas.get(Tugas.id == tugas_id) user = g.user form = TugasForm(request.form, obj=tugas) form.action = url_for('dosen:tugas:update', tugas_id=tugas_id) matkul = MataKuliah.get(MataKuliah.dosen == user) if form.validate_on_submit(): form.populate_obj(tugas) tugas.mata_kuliah = matkul tugas.save() flash('Sukses memperbarui tugas') return redirect(url_for('dosen:tugas:list')) return render_template('dosen/tugas/update.html', form=form)