-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/interrogator/buzzword
- Loading branch information
Showing
11 changed files
with
213 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}buzzword: upload corpus{% endblock %} | ||
|
||
|
||
{% block content %} | ||
|
||
<table class="table"> | ||
<form method="POST" enctype="multipart/form-data"> | ||
{% csrf_token %} | ||
{{ form.as_table }} | ||
<tr> | ||
<td> | ||
<button type="submit" class="btn btn-primary">upload corpus</button> | ||
</td> | ||
</tr> | ||
</form> | ||
</table> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 3.0 on 2019-12-10 14:10 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('explore', '0004_auto_20191205_0900'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Language', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
], | ||
), | ||
migrations.AlterModelOptions( | ||
name='corpus', | ||
options={'verbose_name_plural': 'Corpora'}, | ||
), | ||
migrations.AddField( | ||
model_name='corpus', | ||
name='language_link', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='explore.Language'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 3.0 on 2019-12-10 14:10 | ||
|
||
from django.db import migrations | ||
|
||
def transfer_lang(apps, schema_editor): | ||
Corpus = apps.get_model("explore", "Corpus") | ||
Language = apps.get_model("explore", "Language") | ||
for corpus in Corpus.objects.all(): | ||
language, _ = Language.objects.get_or_create(name=corpus.language) | ||
corpus.language_link = language | ||
corpus.save() | ||
language.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("explore", "0005_auto_20191210_1410"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(transfer_lang), | ||
migrations.RemoveField( | ||
model_name="corpus", | ||
name="language" | ||
), | ||
migrations.RenameField( | ||
model_name="corpus", | ||
old_name="language_link", | ||
new_name="language", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 3.0 on 2019-12-11 15:01 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('explore', '0006_transfer_language'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='corpus', | ||
name='date', | ||
field=models.DateField(blank=True, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='corpus', | ||
name='desc', | ||
field=models.TextField(blank=True, default=''), | ||
), | ||
migrations.AlterField( | ||
model_name='corpus', | ||
name='initial_query', | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='corpus', | ||
name='initial_table', | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='corpus', | ||
name='url', | ||
field=models.URLField(blank=True, max_length=255, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.0 on 2019-12-11 15:15 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('explore', '0007_auto_20191211_1501'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='corpus', | ||
name='parsed', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,57 @@ | ||
from django.shortcuts import render | ||
from django.shortcuts import render, redirect | ||
from explorer.parts.main import app, load_layout | ||
from django import forms | ||
from explore.models import Corpus | ||
from explorer.parts.strings import _slug_from_name | ||
|
||
def _make_path(slug): | ||
return f"storage/{slug}" | ||
|
||
def _store_corpus_file(corpus_file, slug): | ||
""" | ||
store the corpus file sent by the user | ||
in the local storage. fails if a corpus with | ||
the same slug already exists. | ||
""" | ||
path = _make_path(slug) | ||
with open(_make_path(slug), "xb") as storage: | ||
for chunk in corpus_file.chunks(): | ||
storage.write(chunk) | ||
return path | ||
|
||
def _start_parse_corpus_job(corpus): | ||
# todo: implement this function | ||
pass | ||
|
||
def explore(request, slug): | ||
app = load_layout(slug) | ||
return render(request, 'explore/explore.html') | ||
return render(request, "explore/explore.html") | ||
|
||
def upload_corpus(request): | ||
class UploadCorpusForm(forms.ModelForm): | ||
class Meta: | ||
model = Corpus | ||
fields = ["name", "desc", "language", "date", "url"] | ||
corpus_file = forms.FileField() | ||
|
||
if request.method == "POST": | ||
form = UploadCorpusForm(request.POST, request.FILES) | ||
if form.is_valid(): | ||
slug = _slug_from_name(form.cleaned_data["name"]) | ||
try: | ||
path = _store_corpus_file(request.FILES["corpus_file"], slug) | ||
except: | ||
# TODO: was not able to store corpus file. possibly duplicate slug. handle gracefully | ||
raise | ||
corpus = form.save(commit=False) | ||
corpus.slug = slug | ||
corpus.path = path | ||
corpus.save() | ||
_start_parse_corpus_job(corpus) | ||
return redirect("/") | ||
else: | ||
form = UploadCorpusForm() | ||
|
||
return render(request, "explore/upload_corpus.html", { | ||
"form": form, | ||
}) |
Empty file.