示例#1
0
文件: __init__.py 项目: ap13p/elearn
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)
示例#2
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)