From 36d3ea2ce02de72ca3a7592633a3557afaa0f412 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch <p.jentsch@uni-bielefeld.de>
Date: Wed, 26 Oct 2022 10:12:54 +0200
Subject: [PATCH] Remove helper comments and add service versions dynamically
 to select.

---
 app/contributions/forms.py | 52 ++++++++++----------------------------
 1 file changed, 14 insertions(+), 38 deletions(-)

diff --git a/app/contributions/forms.py b/app/contributions/forms.py
index 2f9b4a57..d123e6d1 100644
--- a/app/contributions/forms.py
+++ b/app/contributions/forms.py
@@ -2,81 +2,57 @@ from flask_wtf import FlaskForm
 from flask_wtf.file import FileField, FileRequired
 from wtforms import (
     BooleanField,
-    PasswordField,
     StringField,
     SubmitField,
     SelectMultipleField,
-    ValidationError, FieldList, IntegerField
+    IntegerField
 )
-from wtforms.validators import InputRequired, Email, EqualTo, Length, Regexp
-from app.models import User
+from wtforms.validators import InputRequired, Length
+from app.services import SERVICES
 
 
 class ContributionForm(FlaskForm):
-
-    # The id field will be generated on insert.
-    # The user_id will be retrieved from the user who is performing this operation.
-
-    # title = db.Column(db.String(64))
     title = StringField(
         'Title',
         validators=[InputRequired(), Length(max=64)]
     )
-
-    # description = db.Column(db.String(255))
     description = StringField(
         'Description',
         validators=[InputRequired(), Length(max=255)]
     )
-
-    # version = db.Column(db.String(16))
     version = StringField(
         'Version',
         validators=[InputRequired(), Length(max=16)]
     )
-
-    # compatible_service_versions = db.Column(ContainerColumn(list, 255))
     compatible_service_versions = SelectMultipleField(
-        'Compatible Service Versions',
-        choices=["asd", "blub", "bla"]
+        'Compatible service versions'
     )
-
-    # publisher = db.Column(db.String(128))
     publisher = StringField(
         'Publisher',
         validators=[InputRequired(), Length(max=128)]
     )
-
-    # publisher_url = db.Column(db.String(512))
     publisher_url = StringField(
         'Publisher URL',
         validators=[InputRequired(), Length(max=512)]
     )
-
-    # publishing_url = db.Column(db.String(512))
     publishing_url = StringField(
         'Publishing URL',
         validators=[InputRequired(), Length(max=512)]
     )
-
-    # publishing_year = db.Column(db.Integer)
     publishing_year = IntegerField(
         'Publishing year',
         validators=[InputRequired()]
     )
-
-    # shared = db.Column(db.Boolean, default=False)
-    shared = BooleanField(
-        'Shared',
-        validators=[InputRequired()]
-    )
-
-    # file upload
-    file = FileField(
-        'File',
-        validators=[FileRequired()]
-    )
-
+    shared = BooleanField('Shared', validators=[InputRequired()])
+    model_file = FileField('File',validators=[FileRequired()])
     submit = SubmitField()
 
 
+    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 = ''
-- 
GitLab