From f4ec47ad579a11f6b21bbe584367e58bf0b90f8d Mon Sep 17 00:00:00 2001 From: Inga Kirschnick Date: Thu, 17 Nov 2022 12:48:19 +0100 Subject: [PATCH] Share toggle update & fix --- app/contributions/forms.py | 29 +++++++++++++------ app/contributions/routes.py | 4 +-- app/static/js/Utils.js | 2 +- .../spacy_nlp_pipeline_model.html.j2 | 3 ++ .../tesseract_ocr_pipeline_model.html.j2 | 3 ++ 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/contributions/forms.py b/app/contributions/forms.py index b30c578e..2c22f56e 100644 --- a/app/contributions/forms.py +++ b/app/contributions/forms.py @@ -42,6 +42,9 @@ class ContributionBaseForm(FlaskForm): 'Publishing year', validators=[InputRequired()] ) + compatible_service_versions = SelectMultipleField( + 'Compatible service versions' + ) shared = BooleanField( 'Shared' ) @@ -53,10 +56,7 @@ class CreateTesseractOCRPipelineModelForm(ContributionBaseForm): 'File', validators=[FileRequired()] ) - compatible_service_versions = SelectMultipleField( - 'Compatible service versions' - ) - + def validate_tesseract_model_file(self, field): current_app.logger.warning(field.data.filename) if not field.data.filename.lower().endswith('.traineddata'): @@ -77,9 +77,6 @@ class CreateSpaCyNLPPipelineModelForm(ContributionBaseForm): 'File', validators=[FileRequired()] ) - compatible_service_versions = SelectMultipleField( - 'Compatible service versions' - ) pipeline_name = StringField( 'Pipeline name', validators=[InputRequired(), Length(max=64)] @@ -103,9 +100,15 @@ class CreateSpaCyNLPPipelineModelForm(ContributionBaseForm): class EditContributionBaseForm(ContributionBaseForm): pass - class EditTesseractOCRPipelineModelForm(EditContributionBaseForm): - pass + def __init__(self, *args, **kwargs): + service_manifest = SERVICES['tesseract-ocr-pipeline'] + super().__init__(*args, **kwargs) + self.compatible_service_versions.choices = [('', 'Choose your option')] + self.compatible_service_versions.choices += [ + (x, x) for x in service_manifest['versions'].keys() + ] + self.compatible_service_versions.default = '' class EditSpaCyNLPPipelineModelForm(EditContributionBaseForm): @@ -113,3 +116,11 @@ class EditSpaCyNLPPipelineModelForm(EditContributionBaseForm): 'Pipeline name', validators=[InputRequired(), Length(max=64)] ) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + service_manifest = SERVICES['spacy-nlp-pipeline'] + self.compatible_service_versions.choices = [('', 'Choose your option')] + self.compatible_service_versions.choices += [ + (x, x) for x in service_manifest['versions'].keys() + ] + self.compatible_service_versions.default = '' diff --git a/app/contributions/routes.py b/app/contributions/routes.py index cd9cdb4b..6ced5eed 100644 --- a/app/contributions/routes.py +++ b/app/contributions/routes.py @@ -127,7 +127,7 @@ def create_tesseract_ocr_pipeline_model(): ) @bp.route('/tesseract-ocr-pipeline-models//toggle-public-status', methods=['POST']) -def share_tesseract_ocr_pipeline_model(tesseract_ocr_pipeline_model_id): +def toggle_public_status_tesseract_ocr_pipeline_model(tesseract_ocr_pipeline_model_id): tesseract_ocr_pipeline_model = TesseractOCRPipelineModel.query.get_or_404(tesseract_ocr_pipeline_model_id) if not (tesseract_ocr_pipeline_model.user == current_user or current_user.is_administrator()): abort(403) @@ -223,7 +223,7 @@ def create_spacy_nlp_pipeline_model(): ) @bp.route('/spacy-nlp-pipeline-models//toggle-public-status', methods=['POST']) -def share_spacy_nlp_pipeline_model(spacy_nlp_pipeline_model_id): +def toggle_public_status_spacy_nlp_pipeline_model(spacy_nlp_pipeline_model_id): spacy_nlp_pipeline_model = SpaCyNLPPipelineModel.query.get_or_404(spacy_nlp_pipeline_model_id) if not (spacy_nlp_pipeline_model.user == current_user or current_user.is_administrator()): abort(403) diff --git a/app/static/js/Utils.js b/app/static/js/Utils.js index 6de95033..31c89087 100644 --- a/app/static/js/Utils.js +++ b/app/static/js/Utils.js @@ -429,7 +429,7 @@ class Utils { } else { msg = `Model "${tesseractOCRPipelineModel.title}" is now private`; } - fetch(`/contributions/spacy-nlp-pipeline-models/${tesseractOCRPipelineModel.id}/toggle-public-status`, {method: 'POST', headers: {Accept: 'application/json'}}) + fetch(`/contributions/tesseract-ocr-pipeline-models/${tesseractOCRPipelineModel.id}/toggle-public-status`, {method: 'POST', headers: {Accept: 'application/json'}}) .then( (response) => { app.flash(msg, 'corpus'); diff --git a/app/templates/contributions/spacy_nlp_pipeline_model.html.j2 b/app/templates/contributions/spacy_nlp_pipeline_model.html.j2 index 951b12a6..718fe7de 100644 --- a/app/templates/contributions/spacy_nlp_pipeline_model.html.j2 +++ b/app/templates/contributions/spacy_nlp_pipeline_model.html.j2 @@ -41,6 +41,9 @@
{{ wtf.render_field(form.version, material_icon='apps') }}
+
+ {{ wtf.render_field(form.compatible_service_versions) }} +


diff --git a/app/templates/contributions/tesseract_ocr_pipeline_model.html.j2 b/app/templates/contributions/tesseract_ocr_pipeline_model.html.j2 index c979f3ab..ae2432dc 100644 --- a/app/templates/contributions/tesseract_ocr_pipeline_model.html.j2 +++ b/app/templates/contributions/tesseract_ocr_pipeline_model.html.j2 @@ -38,6 +38,9 @@
{{ wtf.render_field(form.version, material_icon='apps') }}
+
+ {{ wtf.render_field(form.compatible_service_versions) }} +