Skip to content

Commit

Permalink
Merge pull request #1415 from Signbank/download_ecv
Browse files Browse the repository at this point in the history
#1411: Allow to download ECV file.
  • Loading branch information
susanodd authored Dec 5, 2024
2 parents 24f5853 + f5978d1 commit ae2b29e
Showing 7 changed files with 35 additions and 11 deletions.
13 changes: 12 additions & 1 deletion signbank/dictionary/models.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
from datetime import datetime, date

from signbank.settings.base import FIELDS, DEFAULT_KEYWORDS_LANGUAGE, \
WRITABLE_FOLDER, DATASET_METADATA_DIRECTORY
WRITABLE_FOLDER, DATASET_METADATA_DIRECTORY, ECV_FOLDER
from signbank.dictionary.translate_choice_list import choicelist_queryset_to_translated_dict


@@ -3240,6 +3240,17 @@ def metadata_url(self):

return goal_string

def get_ecv_path(self, check_existence=True):
"""Returns the path within the writable folder"""

dataset_filename = self.acronym.lower().replace(" ", "_") + ".ecv"
ecv_file_path = os.path.join(WRITABLE_FOLDER, ECV_FOLDER, dataset_filename)
ecv_relative_path = os.path.join(ECV_FOLDER, dataset_filename)
if check_existence and os.path.exists(ecv_file_path):
return ecv_relative_path

return ''

def uploaded_eafs(self):

# this is to move the file system commands out of models.py
20 changes: 16 additions & 4 deletions signbank/dictionary/templates/dictionary/admin_dataset_list.html
Original file line number Diff line number Diff line change
@@ -22,15 +22,16 @@ <h3>{% trans "Available Datasets" %}</h3>
<th style="width:150px;">{% trans "Dataset Acronym" %}</th>
<th style="width:300px;">{% trans "Dataset Name" %}</th>
<th style="width:200px;">{% trans "Languages" %}</th>
<th style="width:255px;">{% trans "Number of Signs" %}</th>
<th style="width:200px;">{% trans "Number of Signs" %}</th>
<th style="width:255px;">{% trans "Number of Public Signs" %}</th>
{% if not user.is_anonymous %}
<th style="width:80px;">{% trans "View Dataset" %}</th>
<th style="width:80px;">{% trans "Change Dataset" %}</th>
<th style="width:300px;">{% trans "Request Access" %}</th>
<th style="width:100px;">{% trans "Request Access" %}</th>

<th style="width:80px;">{% trans "Selected" %}</th>
<th>{% trans "Export Dataset" %}</th>
<th style="width:200px;">{% trans "ECV File" %}</th>
<th style="width:200px;">{% trans "Download" %}</th>
{% endif %}
</tr>
</thead>
@@ -110,11 +111,22 @@ <h3>{% trans "Available Datasets" %}</h3>
<input name='dataset_acronym' class='form-control' value='{{dataset.acronym}}' >
</div>
<div class='btn-group'>
<button id='export_ecv' class='btn btn-primary' type='submit' name='export_ecv' value='ECV'>{% trans "ECV" %}</button>
<button id='export_ecv' class='btn btn-primary' type='submit' name='export_ecv' value='ECV'>{% trans "Refresh" %}</button>
</div>
</form>
{% endif %}
</td>
<td>
<div id='dataset_ecv'>
{% if dataset.get_ecv_path %}
{% url 'dictionary:protected_media' '' as protected_media_url %}
<a download="{{dataset.acronym}}.csv" href="{{protected_media_url}}{{dataset.get_ecv_path}}"
style="font-style: bold;">{{dataset.acronym}}.csv</a>
{% else %}
<p>{% trans "No ECV file found." %}</p>
{% endif %}
</div>
</td>
{% endif %}
</tr>
{% endfor %}
6 changes: 3 additions & 3 deletions signbank/dictionary/tests.py
Original file line number Diff line number Diff line change
@@ -429,7 +429,7 @@ def test_ECV_files_nonempty(self):
# it is not checked whether there is an ecv file for all datasets
# ecv files for non-existing datasets are reported if empty

location_ecv_files = ECV_FOLDER
location_ecv_files = ECV_FOLDER_ABSOLUTE_PATH
print('Checking for empty ECV files in location: ', location_ecv_files)
ecv_folder_exists = os.path.exists(location_ecv_files)
if not ecv_folder_exists:
@@ -518,7 +518,7 @@ def test_DatasetListView_ECV_export_permission_change_dataset(self):
print('Test DatasetListView export_ecv with permission change_dataset')
print('Test Dataset is: ', self.test_dataset.acronym)

location_ecv_files = ECV_FOLDER
location_ecv_files = ECV_FOLDER_ABSOLUTE_PATH
dataset_ecv_folder_exists = os.path.exists(location_ecv_files)
if not dataset_ecv_folder_exists:
print('The ecv folder is missing: ', location_ecv_files)
@@ -563,7 +563,7 @@ def test_DatasetListView_ECV_export_permission_change_dataset(self):
response = client.get(url, follow=True)
self.assertTrue("ECV successfully updated." in str(response.content))

location_ecv_files = ECV_FOLDER
location_ecv_files = ECV_FOLDER_ABSOLUTE_PATH
for filename in os.listdir(location_ecv_files):
if filename == self.test_dataset.acronym.lower() + '.ecv':
filename_path = os.path.join(location_ecv_files, filename)
2 changes: 1 addition & 1 deletion signbank/settings/server_specific/asl_yale.py
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
HANDSHAPE_ETYMOLOGY_FIELDS = []
HANDEDNESS_ARTICULATION_FIELDS = []

ECV_FILE = ECV_FOLDER+'asl.ecv'
ECV_FILE = ECV_FOLDER_ABSOLUTE_PATH+'asl.ecv'
ECV_SETTINGS = {
'CV_ID': 'ASL Signbank lexicon',
'include_phonology_and_frequencies': False,
1 change: 1 addition & 0 deletions signbank/settings/server_specific/default.py
Original file line number Diff line number Diff line change
@@ -202,6 +202,7 @@
#Where the ECV files are
ECV_FOLDER = 'ecv/'
ECV_FILE = 'myecv.ecv'
ECV_FOLDER_ABSOLUTE_PATH = WRITABLE_FOLDER+ECV_FOLDER

#What do you want to include in the ECV file?
ECV_SETTINGS = {
2 changes: 1 addition & 1 deletion signbank/settings/server_specific/global_sb_new_aj.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
INTERFACE_LANGUAGE_SHORT_NAMES = ['EN','NL','官话','עִברִית','عربى']
MODELTRANSLATION_LANGUAGES = ['en','nl','zh-hans','ar','he']

ECV_FILE = ECV_FOLDER+'ngt.ecv'
ECV_FILE = ECV_FOLDER_ABSOLUTE_PATH+'ngt.ecv'
ECV_SETTINGS = {
'include_phonology_and_frequencies': False,

2 changes: 1 addition & 1 deletion signbank/tools.py
Original file line number Diff line number Diff line change
@@ -1954,7 +1954,7 @@ def write_ecv_file_for_dataset(dataset_name):
from django.template.loader import get_template
ecv_template = get_template('dictionary/ecv.xml')
xmlstr = ecv_template.render(context)
ecv_file = os.path.join(ECV_FOLDER, dataset_name.lower().replace(" ","_") + ".ecv")
ecv_file = os.path.join(ECV_FOLDER_ABSOLUTE_PATH, dataset_name.lower().replace(" ","_") + ".ecv")
import codecs
try:
f = codecs.open(ecv_file, "w", "utf-8")

0 comments on commit ae2b29e

Please sign in to comment.