f8a72a0a60658d462753fe39a2119932358ccca5,app/server/views.py,DataUpload,post,#DataUpload#Any#,58
Before Change
import_format = request.POST["format"]
try:
if import_format == "csv":
form_data = TextIOWrapper(
request.FILES["file"].file, encoding="utf-8")
if project.is_type_of(Project.SEQUENCE_LABELING):
Document.objects.bulk_create([
Document(text=line.strip(), project=project)
for line in form_data
])
else:
reader = csv.reader(form_data)
Document.objects.bulk_create([
Document(text=line[0].strip(), project=project)
for line in reader
])
elif import_format == "json":
form_data = request.FILES["file"].file
Document.objects.bulk_create([
Document(text=json.loads(entry)["text"], project=project)
for entry in form_data
])
return HttpResponseRedirect(reverse("dataset", args=[project.id]))
except:
After Change
def post(self, request, *args, **kwargs):
project = get_object_or_404(Project, pk=kwargs.get("project_id"))
import_format = request.POST["format"]
try:
file = request.FILES["file"].file
documents = []
if import_format == "csv":
documents = self.csv_to_documents(project, file)
elif import_format == "json":
documents = self.json_to_documents(project, file)
// TODO: Move to the configuration
batch_size = 500
while True:
batch = list(it.islice(documents, batch_size))
if not batch:
break
Document.objects.bulk_create(batch, batch_size=batch_size)
return HttpResponseRedirect(reverse("dataset", args=[project.id]))
except DataUpload.ImportFileError as e:
messages.add_message(request, messages.ERROR, e.message)
return HttpResponseRedirect(reverse("upload", args=[project.id]))
except Exception as e:
logger.exception(e)
messages.add_message(request, messages.ERROR, "Something went wrong")
return HttpResponseRedirect(reverse("upload", args=[project.id]))
class DataDownload(SuperUserMixin, LoginRequiredMixin, TemplateView):
template_name = "admin/dataset_download.html"
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 6
Instances
Project Name: chakki-works/doccano
Commit Name: f8a72a0a60658d462753fe39a2119932358ccca5
Time: 2018-12-26
Author: sergiy.n@attendify.com
File Name: app/server/views.py
Class Name: DataUpload
Method Name: post
Project Name: NervanaSystems/nlp-architect
Commit Name: 24d3656c6c4b3c6806954487720d53af775a1150
Time: 2018-06-07
Author: shira.guskin@intel.com
File Name: set_expansion_demo/ui/main.py
Class Name:
Method Name: get_expand_results_callback
Project Name: comic/grand-challenge.org
Commit Name: 44e7ef0b2b8218781b5fe7e2191b9790c42d73ec
Time: 2019-02-26
Author: code@jmsmkn.com
File Name: app/grandchallenge/container_exec/tasks.py
Class Name:
Method Name: validate_docker_image_async