mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
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:
@@ -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='Can’t 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')
|
||||
|
||||
Reference in New Issue
Block a user