Source code for town6.forms.chat

from wtforms.fields import EmailField, HiddenField, SelectField, StringField
from wtforms.fields import BooleanField
from wtforms.validators import InputRequired

from onegov.form import Form
from onegov.town6 import _


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from onegov.town6.request import TownRequest


[docs] class ChatInitiationForm(Form):
[docs] request: 'TownRequest'
[docs] name = StringField( label=_('Name'), validators=[ InputRequired() ], )
[docs] email = EmailField( label=_('E-mail'), validators=[ InputRequired() ], )
[docs] topic = SelectField( label=_('Topic'), choices=[] )
[docs] confirmation = BooleanField( label=_('Confirmation'), description=_( 'I confirm that I am aware that this chat will be saved and the ' 'history will be sent to me by email.'), validators=[ InputRequired() ], )
[docs] def populate_topics(self) -> None: topics = self.request.app.org.chat_topics if topics: self.topic.choices = [(t, t) for t in topics] general = self.request.translate(_('General')) self.topic.choices.append((general, general)) else: self.delete_field('topic')
[docs] def on_request(self) -> None: self.populate_topics()
[docs] class ChatActionsForm(Form):
[docs] chat_id = HiddenField( label=_('Chat ID'), )