Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@


class BaseDataSourceWebNodeForm(BaseForm):
source_url = forms.TextInputField('source url', required=True)
selector = forms.TextInputField('knowledge selector', required=False,default_value="body")
source_url = forms.TextInputField(_('Web source url'), required=True)
selector = forms.TextInputField(_('Web knowledge selector'), required=False,attrs={'placeholder': _('The default is body, you can enter .classname/#idname/tagname')})


def get_collect_handler():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To address the provided Python code snippet, I have the follow points:

  1. Translation: The gettext function is used to translate placeholder texts, which improves readability and maintainability.

Optimizations

  1. Placeholder Text: For better clarity, it's good practice to provide meaningful placeholders directly within Django form fields instead of setting them in attributes outside the field definition.

Here's an optimized version of the code:

@@ -19,8 +19,6 @@
 
 class BaseDataSourceWebNodeForm(forms.Form):
     # Title translation using gettext
     title_translated = _("Base DataSource Web Node Form")
     
     source_url = forms.CharField(
         label=_("Web source url"),
         max_length=512,
         required=True,
     )
 
     selector = forms.CharField(
         label=_("Web knowledge selector"),
         max_length=255,
         required=False,
         placeholder=_("Default is 'body'; enter '.classname/#idname/tagname'"),
     )

def get_collect_handler():

In this updated version:

  • A general title for the form (title_translated) is added for context when dealing with multiple similar forms in templates.
  • Placeholder text is included directly within the widget configuration without needing additional attribute settings.

Expand Down
9 changes: 9 additions & 0 deletions apps/locales/en_US/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8784,4 +8784,13 @@ msgid "SAML2 SSO"
msgstr ""

msgid "Workflow"
msgstr ""

msgid "Web source url"
msgstr ""

msgid "Web knowledge selector"
msgstr ""

msgid "The default is body, you can enter .classname/#idname/tagname"
msgstr ""
9 changes: 9 additions & 0 deletions apps/locales/zh_CN/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8911,3 +8911,12 @@ msgstr "SAML2 单点登录"

msgid "Workflow"
msgstr "工作流"

msgid "Web source url"
msgstr "Web 根地址"

msgid "Web knowledge selector"
msgstr "选择器"

msgid "The default is body, you can enter .classname/#idname/tagname"
msgstr "默认为 body,可输入 .classname/#idname/tagname"
11 changes: 10 additions & 1 deletion apps/locales/zh_Hant/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8910,4 +8910,13 @@ msgid "SAML2 SSO"
msgstr "SAML2 單點登入"

msgid "Workflow"
msgstr "工作流"
msgstr "工作流"

msgid "Web source url"
msgstr "Web 根地址"

msgid "Web knowledge selector"
msgstr "選擇器"

msgid "The default is body, you can enter .classname/#idname/tagname"
msgstr "默認為 body,可輸入 .classname/#idname/tagname"
Loading