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 tugas_detail(tugas_id): user = current_user() dosens = (User .select(User, MataKuliah.judul, Profile.nama) .join(MataKuliah, on=(MataKuliah.dosen == User.id)) .join(Level, JOIN.LEFT_OUTER, on=(User.level == Level.id)) .join(Profile, on=(User.profile == Profile.id)) .group_by(User) .where(Level.name == 'dosen') .order_by(Profile.nama.asc())) tugas = Tugas.get(Tugas.id == tugas_id) dosen_id = tugas.mata_kuliah.dosen.id file_list = TugasFile.select().where(TugasFile.tugas == tugas) try: sudah_mengumpulkan = KumpulTugas.get(KumpulTugas.tugas == tugas, KumpulTugas.mahasiswa == user) except KumpulTugas.DoesNotExist: sudah_mengumpulkan = False form = KumpulkanTugasForm(request.form) form.action = url_for('mhs:tugas:kumpulkan', tugas_id=tugas.id) return render_template('mhs/detail.html', tugas=tugas, dosens=dosens, form=form, sudah_mengumpulkan=sudah_mengumpulkan, dosen_id=dosen_id, file_list=file_list)