Exemplo n.º 1
0
def download(request, fileID, versionID):
    storage = WebServer.storage()
    database = WebServer.database()
    
    version = database.find(SyncedFileVersion, SyncedFileVersion.ID == int(versionID)).one()
    if (version.syncedfile.owner != request.user):
        return HttpResponseRedirect('/')
    filed = version.open(storage)
    
    resp = HttpResponse(filed, mimetype=version.syncedfile.mimetype)
    resp['Content-Disposition'] = 'attachment; filename='+version.syncedfile.fileName
    return resp
Exemplo n.º 2
0
def uploadVersion(request, fileID):
    if request.method == "POST":
        uploadVersionForm = forms.UploadNewVersionForm(request.POST, request.FILES)
        
        if (uploadVersionForm.is_valid()):
            storage = WebServer.storage()
            database = WebServer.database()
            
            syncedFile = database.find(SyncedFile, SyncedFile.ID == int(fileID)).one()
        
            if (syncedFile.owner != request.user):
                return HttpResponseRedirect('/')
            
            uploadedFile = uploadVersionForm.cleaned_data['syncedFile']
            version = SyncedFileVersion(UploadedFileWrapper(uploadedFile),
                                        u'Version from %s (from web)' % datetime.datetime.now(WebServer.timezone()).strftime('%Y-%m-%d %H:%M'),
                                        unicode(datetime.datetime.now(WebServer.timezone()).strftime('%Y-%m-%dT%H:%M:%S%z')),
                                        storage)
            syncedFile.add_version(version)
            database.commit()
            return HttpResponseRedirect('/files/' + str(syncedFile.ID) + '/')
Exemplo n.º 3
0
def createFile(request):    
    if (request.method == "POST"):
        createFileForm = forms.CreateFileForm(request.POST, request.FILES)
        if (createFileForm.is_valid()):
            storage = WebServer.storage()
            database = WebServer.database()
                        
            uploadedFile = createFileForm.cleaned_data['syncedFile']
            sf = SyncedFile(uploadedFile.name, request.user)
            sf.mimetype = unicode(uploadedFile.content_type)
            sf.add_to_store(database)
            
            version = SyncedFileVersion(UploadedFileWrapper(uploadedFile),
                                        u'Initial Version (from web)',
                                        unicode(datetime.datetime.now(WebServer.timezone()).strftime('%Y-%m-%dT%H:%M:%S%z')),
                                        storage)
            sf.add_version(version)
            database.commit()
            
            return HttpResponseRedirect('/files/' + str(sf.ID) + '/')
        else:
            return render_to_response('barabas/createFile.html', { 'createFileForm': createFileForm },
                                      context_instance=RequestContext(request))