ผลต่างระหว่างรุ่นของ "CuneiForm"

จาก คูนิฟ็อกซ์ วิกิ
ไม่มีความย่อการแก้ไข
บรรทัดที่ 8: บรรทัดที่ 8:
<syntaxhighlight lang="python" line="1">
<syntaxhighlight lang="python" line="1">
class LoginForm(FlaskForm, CuneiForm):
class LoginForm(FlaskForm, CuneiForm):
     company = StringField(lazy_gettext("Company"), validators=[InputRequired(lazy_gettext("Required!"))])
     company = StringField("Company", validators=[InputRequired("Required!")])
     username = StringField(lazy_gettext("Username"), validators=[InputRequired(lazy_gettext("Required!"))])
     username = StringField("Username", validators=[InputRequired("Required!")])
     password = PasswordField(lazy_gettext("Password"), validators=[InputRequired(lazy_gettext("Required!"))])
     password = PasswordField("Password", validators=[InputRequired("Required!")])
     clear_session = BoolField(lazy_gettext("Log-out of other sessions"), default=True)
     clear_session = BoolField("Log-out of other sessions", default=True)
     submit = SubmitField(lazy_gettext("Log-in"))
     submit = SubmitField("Log-in")


     def validate_company(self, company):
     def validate_company(self, company):
บรรทัดที่ 22: บรรทัดที่ 22:
</syntaxhighlight>
</syntaxhighlight>


'' Developers might find uses of {{code|BoolField}} and {{code|IntField}} in CuneiFox code base unfamiliar. This convention is to avoid name conflict betweem WTForm and Peewee.''
=== Special Value Types ===
This feature plays a crucial role in ensuring consistent value formatting for client-side output. While it originated as a solution to address browser formatting inconsistencies, it has evolved to serve several other purposes within the CuneiFox framework.
==== Original Intentions ====
Reading through the CuneiFox code base, one is sure to notice the excessive use of StringFields where one would expect DateFields, TimeFields, FloatFields, and IntegerFields as supported by WTForms. This design choice stems was made to address a challenging browser behaviour. Modern browsers tend to enforce formatting of fields marked as certain types based on the user's locale setting, which can be tied to either the operating system or the browser itself. This automatic formatting can be difficult to override or reverse, leading to inconsistencies and confusion on the user's part especially when switching workstations.
To address this issue, CuneiFox developed its own value typing. Our approach applies our custom-made JavaScript code on unformatted and untyped (as far as the browser is aware) fields. This way, the formatting rendered on the client-side perfectly obeys the company's specific preferences within the CuneiFox system.


== Initiate ==
== Initiate ==

รุ่นแก้ไขเมื่อ 13:23, 5 เมษายน 2567

CuneiForm type objects are powered by WTForms engine. However, this object type also introduce a handful of additional variables and attributes to strike a sweet balance between ease of development and flexibility.

Define

Defining a CuneiForm is essentially similar to declaring a WTForm. There are no differences in declaring fields, validations, render keywords, and validating functions. (There exist a few special functions that can dynamically generate some common fields, but we'll leave that to a later section.)

Let's first have a quick look at a very basic CuneiForm:

class LoginForm(FlaskForm, CuneiForm):
    company = StringField("Company", validators=[InputRequired("Required!")])
    username = StringField("Username", validators=[InputRequired("Required!")])
    password = PasswordField("Password", validators=[InputRequired("Required!")])
    clear_session = BoolField("Log-out of other sessions", default=True)
    submit = SubmitField("Log-in")

    def validate_company(self, company):
        # Validation goes here
    def validate_username(self, username):
        # Validation goes here
    def validate_password(self, password):
        # Validation goes here

Developers might find uses of BoolField and IntField in CuneiFox code base unfamiliar. This convention is to avoid name conflict betweem WTForm and Peewee.

Special Value Types

This feature plays a crucial role in ensuring consistent value formatting for client-side output. While it originated as a solution to address browser formatting inconsistencies, it has evolved to serve several other purposes within the CuneiFox framework.

Original Intentions

Reading through the CuneiFox code base, one is sure to notice the excessive use of StringFields where one would expect DateFields, TimeFields, FloatFields, and IntegerFields as supported by WTForms. This design choice stems was made to address a challenging browser behaviour. Modern browsers tend to enforce formatting of fields marked as certain types based on the user's locale setting, which can be tied to either the operating system or the browser itself. This automatic formatting can be difficult to override or reverse, leading to inconsistencies and confusion on the user's part especially when switching workstations.

To address this issue, CuneiFox developed its own value typing. Our approach applies our custom-made JavaScript code on unformatted and untyped (as far as the browser is aware) fields. This way, the formatting rendered on the client-side perfectly obeys the company's specific preferences within the CuneiFox system.

Initiate

Design & Pre-made Scripts

Notable Sub-routines