-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from davewalker5/export-life-list
Added ability to export life list
- Loading branch information
Showing
18 changed files
with
252 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
FROM python:3.10-slim-bullseye AS runtime | ||
|
||
COPY naturerecorderpy-1.0.15.0 /opt/naturerecorderpy-1.0.15.0 | ||
COPY naturerecorderpy-1.0.16.0 /opt/naturerecorderpy-1.0.16.0 | ||
|
||
WORKDIR /opt/naturerecorderpy-1.0.15.0 | ||
WORKDIR /opt/naturerecorderpy-1.0.16.0 | ||
|
||
RUN apt-get update -y | ||
RUN pip install -r requirements.txt | ||
RUN pip install nature_recorder-1.0.15-py3-none-any.whl | ||
RUN pip install nature_recorder-1.0.16-py3-none-any.whl | ||
|
||
ENV NATURE_RECORDER_DATA_FOLDER=/var/opt/naturerecorderpy-1.0.15.0 | ||
ENV NATURE_RECORDER_DB=/var/opt/naturerecorderpy-1.0.15.0/naturerecorder.db | ||
ENV NATURE_RECORDER_DATA_FOLDER=/var/opt/naturerecorderpy-1.0.16.0 | ||
ENV NATURE_RECORDER_DB=/var/opt/naturerecorderpy-1.0.16.0/naturerecorder.db | ||
|
||
ENTRYPOINT [ "python" ] | ||
CMD [ "-m", "naturerec_web" ] |
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
5 changes: 5 additions & 0 deletions
5
docs/source/naturerec_model/data_exchange/life_list_export_helper.rst
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,5 @@ | ||
life_list_export_helper.py | ||
========================== | ||
|
||
.. automodule:: naturerec_model.data_exchange.life_list_export_helper | ||
:members: |
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
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
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,10 +1,12 @@ | ||
from .status_import_helper import StatusImportHelper | ||
from .sightings_import_helper import SightingsImportHelper | ||
from .sightings_export_helper import SightingsExportHelper | ||
from .life_list_export_helper import LifeListExportHelper | ||
|
||
|
||
__all__ = [ | ||
"StatusImportHelper", | ||
"SightingsImportHelper", | ||
"SightingsExportHelper" | ||
"SightingsExportHelper", | ||
"LifeListExportHelper" | ||
] |
49 changes: 49 additions & 0 deletions
49
src/naturerec_model/data_exchange/life_list_export_helper.py
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,49 @@ | ||
""" | ||
This module implements a helper that will export a life list to a CSV format file on a background thread | ||
""" | ||
|
||
import csv | ||
import os | ||
from .data_exchange_helper_base import DataExchangeHelperBase | ||
from ..model import get_data_path | ||
from ..logic.sightings import life_list | ||
|
||
|
||
class LifeListExportHelper(DataExchangeHelperBase): | ||
JOB_NAME = "Life List export" | ||
COLUMN_NAMES = ["Category", "Species"] | ||
|
||
def __init__(self, filename, category_id): | ||
super().__init__(self.export) | ||
self._filename = filename | ||
self._category_id = category_id | ||
self.create_job_status() | ||
|
||
def __repr__(self): | ||
return f"{type(self).__name__}(" \ | ||
f"filename={self._filename!r}, " \ | ||
f"category_id={self._category_id!r})" | ||
|
||
def export(self): | ||
""" | ||
Retrieve the life list matching the criteria passed to the init method and write it to file in CSV format | ||
""" | ||
with open(self.get_file_export_path(), mode='wt', newline='', encoding="UTF-8") as f: | ||
writer = csv.writer(f) | ||
writer.writerow(self.COLUMN_NAMES) | ||
|
||
species = life_list(self._category_id) | ||
for species in species: | ||
writer.writerow([species.category.name, species.name]) | ||
|
||
def get_file_export_path(self): | ||
""" | ||
Construct and return the full path to the export file | ||
:return: Full path to the export file | ||
""" | ||
export_folder = os.path.join(get_data_path(), "exports") | ||
if not os.path.exists(export_folder): | ||
os.makedirs(export_folder) | ||
|
||
return os.path.join(export_folder, self._filename) |
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 "layout.html" %} | ||
{% block title %}Export Life List{% endblock %} | ||
|
||
{% block content %} | ||
<form method="post"> | ||
<h1>Life List</h1> | ||
<div class="filter-criteria"> | ||
<div class="form-group"> | ||
<label>Filename</label> | ||
<input class="form-control" name="filename" id="filename" | ||
placeholder="CSV file name e.g. birds_life_list.csv" required> | ||
</div> | ||
{% include "category_selector.html" with context %} | ||
<div class="button-bar"> | ||
<button type="submit" value="filter" class="btn btn-primary">Export Life List</button> | ||
</div> | ||
</div> | ||
{% include "message.html" with context %} | ||
</form> | ||
{% 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
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,19 +1,11 @@ | ||
<div class="filter-criteria"> | ||
<div class="form-group"> | ||
<label>Category</label> | ||
<select class="form-control" name="category" id="category" required> | ||
<option value="">Please select ...</option> | ||
{% for category in categories %} | ||
<option value="{{ category.id }}" {% if category.id == category_id %}selected{% endif %}> | ||
{{ category.name }} | ||
</option> | ||
{% endfor %} | ||
</select> | ||
</div> | ||
<div class="button-bar"> | ||
<button type="submit" value="filter" class="btn btn-light">List Species</button> | ||
<button type="button" class="btn btn-primary"> | ||
<a href="{{ url_for('species.edit') }}">Add Species</a> | ||
</button> | ||
</div> | ||
<div class="form-group"> | ||
<label>Category</label> | ||
<select class="form-control" name="category" id="category" required> | ||
<option value="">Please select ...</option> | ||
{% for category in categories %} | ||
<option value="{{ category.id }}" {% if category.id == category_id %}selected{% endif %}> | ||
{{ category.name }} | ||
</option> | ||
{% endfor %} | ||
</select> | ||
</div> |
Oops, something went wrong.