Пример #1
0
def index(request):
    corpora = Corpus.objects.all()
    langs = Lang.objects.all()
    context = {'my_corpora' : Corpus.objects.filter(user=request.user),
               'other_corpora' : Corpus.objects.exclude(user=request.user),
               'langs' : langs}
    
    if request.method == "POST":
        form = CorpusForm(request.POST, request.FILES)
        if form.is_valid():
            path_type = form.cleaned_data["path_type"]
            
            if (path_type == "file_upload"):
                name = form.cleaned_data["name"]
                file = form.cleaned_data["upload_path"]
                path = files.write_tmp_file(file, name)
            else:
                location = form.cleaned_data["location"].strip("/")
                file_name = form.cleaned_data["file_name"].strip("/")
                path = os.path.join(location, file_name)
            
            
            sample = files.corpus_sample(path, 15)
            context = {'form' : form, 'sample' : sample }
            return render(request, 'corpora/confirm_upload.html', context)
        else:
            context["form"] = form
    else:
        context["form"] = CorpusForm()
    return render(request, 'corpora/index.html', context)
Пример #2
0
def index(request):
    corpora = Corpus.objects.all()
    langs = Lang.objects.all()
    context = {'my_corpora' : Corpus.objects.filter(user=request.user),
               'other_corpora' : Corpus.objects.exclude(user=request.user),
               'langs' : langs}

    if request.method == 'GET':
	if 'q' in request.GET :
            query = request.GET['q']
            context['my_corpora'] = context['my_corpora'].filter(label__contains=query)
            context['other_corpora'] = context['other_corpora'].filter(label__contains=query)

    if request.method == "POST":
        form = CorpusForm(request.POST, request.FILES)
        if form.is_valid():
            path_type = form.cleaned_data["path_type"]
            
            if (path_type == "file_upload"):
                name = form.cleaned_data["name"]
                file = form.cleaned_data["upload_path"]
                path = files.write_tmp_file(file, name)
            else:
                location = form.cleaned_data["location"].strip("/")
                file_name = form.cleaned_data["file_name"].strip("/")
                path = os.path.join(location, file_name)
            
            
            sample = files.corpus_sample(path, 15)
            size = files.file_size(path)
            wc = files.wc(path)
            context = {'form' : form, 'sample' : sample, 'size' : size, 'wc' : wc}
            return render(request, 'corpora/confirm_upload.html', context)
        else:
            context["form"] = form
    else:
        context["form"] = CorpusForm()
    return render(request, 'corpora/index.html', context)
Пример #3
0
 def sample(self, num_lines):
     return files.corpus_sample(self.file_path(), num_lines)
Пример #4
0
 def sample(self, num_lines):
     return files.corpus_sample(self.file_path(), num_lines)