Beispiel #1
0
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))
Beispiel #2
0
def upload():
    phile = request.files.get('upload', None)
    if phile:
        path = generate_path()
        filepath = os.path.join(path, secure_filename(phile.filename))
        phile.save(filepath)
        f = Phile()
        f.filename = phile.filename
        f.filetype = phile.mimetype
        f.filepath = filepath
        f.save()
        return jsonify({
            'uploaded': 1,
            'filename': f.filename,
            'url': url_for('sendfile', file_id=f.id)
        })
    return jsonify({
        'uploaded': 0,
        'error': {
            'message': 'File cannot be uploaded'
        }
    })