MCPcopy Index your code
hub / github.com/hunvreus/devpush / StorageCreateForm

Class StorageCreateForm

app/forms/storage.py:44–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class StorageCreateForm(StarletteForm):
45 type = SelectField(
46 _l("Type"),
47 choices=[
48 ("database", _("Database")),
49 ("volume", _("Volume")),
50 ],
51 )
52 name = StringField(
53 _l("Name"),
54 validators=[
55 DataRequired(),
56 Length(min=1, max=100),
57 Regexp(
58 r"^[A-Za-z0-9][A-Za-z0-9._-]*[A-Za-z0-9]$",
59 message=_l(
60 "Storage names can only contain letters, numbers, hyphens, underscores and dots. They cannot start or end with a dot, underscore or hyphen."
61 ),
62 ),
63 ],
64 )
65 submit = SubmitField(_l("Create storage"))
66 environment_ids = StringField(_l("Environments"), validators=[Optional()])
67
68 def __init__(
69 self,
70 request: Request,
71 *args,
72 db: AsyncSession,
73 team: Team,
74 project: Project | None = None,
75 **kwargs,
76 ):
77 super().__init__(request, *args, **kwargs)
78 self.db = db
79 self.team = team
80 self.project = project
81
82 async def async_validate_name(self, field):
83 if self.db and self.team:
84 result = await self.db.execute(
85 select(Storage).where(
86 func.lower(Storage.name) == field.data.lower(),
87 Storage.team_id == self.team.id,
88 )
89 )
90 if result.scalar_one_or_none():
91 raise ValidationError(
92 _(
93 "A storage with this name already exists in this team or is reserved."
94 )
95 )
96
97 def validate_environment_ids(self, field):
98 if not self.project:
99 return
100 environment_ids = _parse_environment_ids(field.data)
101 if environment_ids is None:

Callers

nothing calls this directly

Calls 1

_Function · 0.50

Tested by

no test coverage detected