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
def process_request(self, request): """Empty docstring""" if (request.session and 'userid' in request.session): db = WebServer.database() request.user = db.find(User, User.id == request.session['userid']).one() else: request.user = None
def index(request): if request.user: db = WebServer().database() tags = db.find(FileTag.tagName, SyncedFile.ID == FileTag.fileID, SyncedFile.owner == request.user) \ .group_by(FileTag.tagName) \ .order_by(Desc(Count(SyncedFile.ID))) createFileForm = forms.CreateFileForm() return render_to_response('barabas/index.html', { 'tagCloud': tags, 'createFileForm': createFileForm }, context_instance=RequestContext(request)) else: return render_to_response('barabas/index_anon.html', context_instance=RequestContext(request))
def clean(self): """Empty docstring""" data = self.cleaned_data db = WebServer.database() pa = db.find(PasswordAuthentication, PasswordAuthentication.username == data['username']).one() if not (pa and pa.testPassword(data['password'])): raise forms.ValidationError("Wrong username or password") data['passwordAuthentication'] = pa return data
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) + '/')
def tag(request, fileID): if request.method == "POST": tagForm = forms.TagFileForm(request.POST) if (tagForm.is_valid()): database = WebServer.database() syncedFile = database.find(SyncedFile, SyncedFile.ID == int(fileID)).one() if (syncedFile.owner != request.user): return HttpResponseRedirect('/') syncedFile.tag(tagForm.cleaned_data['tagName']) database.commit() return HttpResponseRedirect('/files/' + str(syncedFile.ID) + '/')
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))
def clean(self): """Empty docstring""" data = self.cleaned_data print data['password'] db = WebServer.database() user = User(data['firstName'], data['lastName'], data['email']) pa = PasswordAuthentication() pa.username = data['username'] pa.password(data['password']) pa.user = user data['user'] = user data['passwordAuth'] = pa return data
def signup(request): if request.method == "POST": registrationForm = PasswordBasedRegistrationForm(request.POST) if (registrationForm.is_valid()): database = WebServer.database() user = registrationForm.cleaned_data['user'] pa = registrationForm.cleaned_data['passwordAuth'] database.add(user) database.commit() return HttpResponseRedirect('/') else: registrationForm = PasswordBasedRegistrationForm() return render_to_response('users/signup.html', { 'registrationForm': registrationForm }, context_instance=RequestContext(request))