Show form elements for templates and folders

This commit adds:
- checkboxes to let you select a template or folder
- radio buttons to let you select where to move those template(s) and/or
  folder(s) to

It only does the `get` part of this work; handling the `post` and
calling API will be done in a subsequent commit.
This commit is contained in:
Chris Hill-Scott
2018-11-08 11:56:29 +00:00
parent 921de47164
commit 2743216519
10 changed files with 215 additions and 31 deletions

View File

@@ -22,6 +22,7 @@ from wtforms import (
IntegerField,
PasswordField,
RadioField,
SelectMultipleField,
StringField,
TextAreaField,
ValidationError,
@@ -30,6 +31,7 @@ from wtforms import (
)
from wtforms.fields.html5 import EmailField, SearchField, TelField
from wtforms.validators import URL, DataRequired, Length, Optional, Regexp
from wtforms.widgets import CheckboxInput, ListWidget
from app.main.validators import (
Blacklist,
@@ -102,6 +104,11 @@ def get_next_days_until(until):
]
class MultiCheckboxField(SelectMultipleField):
widget = ListWidget(prefix_label=False)
option_widget = CheckboxInput()
def email_address(label='Email address', gov_user=True):
validators = [
Length(min=5, max=255),
@@ -1111,3 +1118,41 @@ class ReturnedLettersForm(StripWhitespaceForm):
class TemplateFolderForm(StripWhitespaceForm):
name = StringField('Folder name', validators=[DataRequired(message='Cant be empty')])
class TemplateAndFoldersSelectionForm(Form):
ALL_TEMPLATES_FOLDER = {
'name': 'All templates',
'id': None,
}
def __init__(
self,
service,
template_type,
current_folder_id,
*args,
**kwargs
):
super().__init__(*args, **kwargs)
self.templates_and_folders.choices = self.ids_and_names(
service.get_template_folders_and_templates(template_type, current_folder_id)
)
self.move_to.choices = self.ids_and_names(
[self.ALL_TEMPLATES_FOLDER] + service.all_template_folders,
exclude=current_folder_id,
)
@staticmethod
def ids_and_names(items, exclude=None):
return [
(item['id'], item['name']) for item in items
if item['id'] != exclude
]
templates_and_folders = MultiCheckboxField('Choose templates or folders')
move_to = RadioField('Choose a folder')