Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Allow for txt reports to be uploaded #148

Merged
merged 3 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ __pycache__
!.gitkeep
db.sqlite3
*.pem
.vscode/

# pyenv
.python-version
Expand Down
6 changes: 6 additions & 0 deletions src/tram/tram/ml/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def _extract_text(self, document):
text = self._extract_docx_text(document)
elif suffix == ".html":
text = self._extract_html_text(document)
elif suffix == '.txt':
emmanvg marked this conversation as resolved.
Show resolved Hide resolved
text = self._extract_plain_text(document)
else:
raise ValueError("Unknown file suffix: %s" % suffix)

Expand Down Expand Up @@ -228,6 +230,10 @@ def _extract_docx_text(self, document):
text = " ".join([paragraph.text for paragraph in parsed_docx.paragraphs])
return text

def _extract_plain_text(self, document):
text = document.docfile.read().decode('UTF-8')
emmanvg marked this conversation as resolved.
Show resolved Hide resolved
return text

def process_job(self, job):
name = self._get_report_name(job)
text = self._extract_text(job.document)
Expand Down
2 changes: 1 addition & 1 deletion src/tram/tram/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h1 style="color: white">
<label for="id-upload" class="btn btn btn-outline-light" title="Upload File">
<i class="fas fa-upload"></i>
</label>
<input type="file" id="id-upload" style="display: none; height: max-content;" accept=".pdf,.docx,.html,.json">
<input type="file" id="id-upload" style="display: none; height: max-content;" accept=".pdf,.docx,.html,.json,.txt">
</form>
</li>
<li class="navbar-item me-1">
Expand Down
1 change: 1 addition & 0 deletions src/tram/tram/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def upload(request):
"application/pdf", # .pdf files
"text/html", # .html files
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", # .docx files
"text/plain", # .txt files
):
DocumentProcessingJob.create_from_file(request.FILES["file"])
elif file_content_type in ("application/json",): # .json files
Expand Down