A simple example

Here's a simple example of how we could use Albatross Forms to collect a username and password from the user.

We need to define a model class to hold the data:

   1 import pwd, crypt
   2 
   3 class Login:
   4     def __init__(self, username, password):
   5         self.username = username
   6         self.password = password
   7 
   8     def is_password_valid(self):
   9         crypted_passwd = pwd.getpwent(self.username).pw_passwd
  10         crypted_passwd = pwd.getpwnam(username)[1]
  11         return (crypt.crypt(self.password, crypted_passwd) == crypted_passwd)

Next, we need to define a form to display the fields:

   1 from albatross.form import *
   2 
   3 class LoginForm(FieldsetForm):
   4     def __init__(self, login):
   5         elements = Fieldset((
   6             TextField('Username', 'username'),
   7             PasswordField('Password', 'password'),
   8         ))
   9         FieldsetForm.__init__(self, 'User login', (elements, ))
  10         
  11         self.load(login)

Create the form in page_enter

XXX need a login button

Render the form using alx-form