arterm-sedov commited on
Commit
a31ac81
·
1 Parent(s): 9b847bf

Externalized common form fields schema

Browse files
tools/models.py CHANGED
@@ -143,6 +143,33 @@ class CommonGetAttributeFields(BaseModel):
143
  return v
144
 
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  def normalize_operation_archive_unarchive(value: str) -> str:
147
  """
148
  Normalize operation values for archive/unarchive operations.
 
143
  return v
144
 
145
 
146
+ class CommonFormFields(BaseModel):
147
+ """
148
+ Common definitions for form schemas.
149
+
150
+ Provides standardized fields to work with form models.
151
+ """
152
+ application_system_name: str = Field(
153
+ description="System name of the application. RU: Системное имя приложения",
154
+ )
155
+ template_system_name: str = Field(
156
+ description="System name of the template. RU: Системное имя шаблона",
157
+ )
158
+ form_system_name: str = Field(
159
+ description="System name of the form. RU: Системное имя формы",
160
+ )
161
+
162
+ @field_validator(
163
+ "application_system_name",
164
+ "template_system_name",
165
+ "form_system_name",
166
+ mode="before",
167
+ )
168
+ def non_empty_str(cls, v: Any) -> Any: # type: ignore[override]
169
+ if isinstance(v, str) and v.strip() == "":
170
+ raise ValueError("must be a non-empty string")
171
+ return v
172
+
173
  def normalize_operation_archive_unarchive(value: str) -> str:
174
  """
175
  Normalize operation values for archive/unarchive operations.
tools/templates_tools/tools_form.py CHANGED
@@ -1,31 +1,11 @@
1
  from ..tool_utils import *
 
2
 
3
  FORM_ENDPOINT = "webapi/Form"
4
 
5
 
6
- class GetFormSchema(BaseModel):
7
- application_system_name: str = Field(
8
- description="System name of the application. RU: Системное имя приложения",
9
- )
10
- template_system_name: str = Field(
11
- description="System name of the template. RU: Системное имя шаблона",
12
- )
13
- form_system_name: str = Field(
14
- description="System name of the form. RU: Системное имя формы",
15
- )
16
-
17
- @field_validator(
18
- "application_system_name",
19
- "template_system_name",
20
- "form_system_name",
21
- mode="before",
22
- )
23
- @classmethod
24
- def non_empty_str(cls, v: Any) -> Any:
25
- if isinstance(v, str) and v.strip() == "":
26
- msg = "must be a non-empty string"
27
- raise ValueError(msg)
28
- return v
29
 
30
 
31
  @tool(
@@ -74,7 +54,7 @@ def _normalize_form_terms(data: dict) -> dict:
74
  # Rename 'alias' to 'systemName' (but not 'globalAlias')
75
  if key == "alias":
76
  normalized["systemName"] = value
77
- elif "Alias" in key and not "globalalias" in key.lower():
78
  normalized[key.replace("Alias", "SystemName")] = value
79
  # Rename 'Property' to 'Attribute' in camelCase
80
  elif "Property" in key:
 
1
  from ..tool_utils import *
2
+ from ..models import CommonFormFields
3
 
4
  FORM_ENDPOINT = "webapi/Form"
5
 
6
 
7
+ class GetFormSchema(CommonFormFields):
8
+ pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
 
11
  @tool(
 
54
  # Rename 'alias' to 'systemName' (but not 'globalAlias')
55
  if key == "alias":
56
  normalized["systemName"] = value
57
+ elif "Alias" in key and "globalalias" not in key.lower():
58
  normalized[key.replace("Alias", "SystemName")] = value
59
  # Rename 'Property' to 'Attribute' in camelCase
60
  elif "Property" in key: