示例#1
0
文件: __init__.py 项目: ap13p/elearn
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)
示例#2
0
文件: __init__.py 项目: ap13p/elearn
def tugas_delete(tugas_id):
    if g.user and g.user.level.name == 'dosen':
        tugas = None
        try:
            tugas = Tugas.get(Tugas.id == tugas_id)
        except Tugas.DoesNotExist:
            flash('Tidak bisa menghapus tugas', 'error')
        if tugas:
            tugas.delete_instance(True)
            flash('Sukses menghapus tugas')
        return redirect(url_for('dosen:tugas:list'))
    return render_template('dosen/tugas/list.html')
示例#3
0
文件: __init__.py 项目: ap13p/elearn
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)
示例#4
0
文件: __init__.py 项目: ap13p/elearn
def tugas_kumpulkan(tugas_id):
    tugas = Tugas.get(Tugas.id == tugas_id)
    user = current_user()
    kumpul_tugas = KumpulTugas()
    kumpul_tugas.mahasiswa = user
    kumpul_tugas.tugas = tugas
    phile = request.files['phile']
    if isinstance(phile, FileStorage):
        path = generate_path(str(user.id), str(tugas.id))
        path = os.path.join(path, secure_filename(phile.filename))
        phile.save(path)
        f = Phile()
        f.filename = phile.filename
        f.filetype = phile.mimetype
        f.filepath = path
        f.save()
        kumpul_tugas.phile = f
    kumpul_tugas.save()
    return redirect(url_for('mhs:tugas:detail', tugas_id=tugas.id))