def post(self): annotation_type = self.GET.get('type') if annotation_type not in ['file', 'url']: annotation_type = self.cleaned_data['type'] url = self.path + '?' + urllib.urlencode({'type': annotation_type}) return http.HttpResponseRedirect(url) project_id = self.kwargs['uuid'] name = self.cleaned_data['name'] if annotation_type == 'url': url = self.cleaned_data['url'] if annotation_type == 'file': file = self.FILES['file'] filename, fileext = os.path.splitext(file.name) #generatedFilename = str(uuid.uuid4()) + filext project = Project.objects.get(id=project_id) projectFile = ProjectFile(name=filename,extension=fileext,project=project) projectFile.save() location = fileupload_logic.handle_uploaded_file(file, projectFile.diskfilename()) url = settings.BASE_PATH + location # TODO : rewrite this to use UUID instead of original filename annotation_logic.handle_add_annotation(name, url, project_id) return http.HttpResponseRedirect(settings.BASE_PATH + 'annotation/list/' + project_id)
def handle_uploaded_image(file, name, id_str): """TODO: Docstring """ #save the uploaded image proj = Project.objects.get(id=id_str) properties = dict( name=name, project=proj, ) oi = OriginalImage(**properties) oi.save() file_name = oi.id + '.jpg' fileupload_logic.handle_uploaded_file(file, file_name) return oi