freeipa/ipa-server/ipa-gui/ipagui/forms/user.py
2007-10-03 13:53:14 -07:00

152 lines
6.1 KiB
Python

import turbogears
from turbogears import validators, widgets
class UserFields():
givenname = widgets.TextField(name="givenname", label="Given Name")
sn = widgets.TextField(name="sn", label="Family Name")
cn = widgets.TextField(name="cn", label="Common Names")
title = widgets.TextField(name="title", label="Title")
displayname = widgets.TextField(name="displayname", label="Display Name")
initials = widgets.TextField(name="initials", label="Initials")
uid = widgets.TextField(name="uid", label="Login")
userpassword = widgets.PasswordField(name="userpassword", label="Password")
userpassword_confirm = widgets.PasswordField(name="userpassword_confirm",
label="Confirm Password")
uidnumber = widgets.TextField(name="uidnumber", label="UID")
gidnumber = widgets.TextField(name="gidnumber", label="GID")
homedirectory = widgets.TextField(name="homedirectory", label="Home Directory")
loginshell = widgets.TextField(name="loginshell", label="Login Shell")
gecos = widgets.TextField(name="gecos", label="GECOS")
mail = widgets.TextField(name="mail", label="E-mail Address")
telephonenumber = widgets.TextField(name="telephonenumber", label="Work Number")
facsimiletelephonenumber = widgets.TextField(name="facsimiletelephonenumber",
label="Fax Number")
mobile = widgets.TextField(name="mobile", label="Cell Number")
pager = widgets.TextField(name="pager", label="Pager Number")
homephone = widgets.TextField(name="homephone", label="Home Number")
street = widgets.TextField(name="street", label="Street Address")
l = widgets.TextField(name="l", label="City")
st = widgets.TextField(name="st", label="State")
postalcode = widgets.TextField(name="postalcode", label="ZIP")
ou = widgets.TextField(name="ou", label="Org Unit")
businesscategory = widgets.TextField(name="businesscategory", label="Tags")
description = widgets.TextField(name="description", label="Description")
employeetype = widgets.TextField(name="employeetype", label="Employee Type")
manager = widgets.TextField(name="manager", label="Manager")
roomnumber = widgets.TextField(name="roomnumber", label="Room Number")
secretary = widgets.TextField(name="secretary", label="Secretary")
carlicense = widgets.TextField(name="carlicense", label="Car License")
labeleduri = widgets.TextField(name="labeleduri", label="Home Page")
nsAccountLock = widgets.SingleSelectField(name="nsAccountLock",
label="Account Status",
options = [("", "active"), ("true", "inactive")])
uid_hidden = widgets.HiddenField(name="uid")
uidnumber_hidden = widgets.HiddenField(name="uidnumber")
gidnumber_hidden = widgets.HiddenField(name="gidnumber")
krbPasswordExpiration_hidden = widgets.HiddenField(name="krbPasswordExpiration")
editprotected_hidden = widgets.HiddenField(name="editprotected")
user_orig = widgets.HiddenField(name="user_orig")
user_groups_data = widgets.HiddenField(name="user_groups_data")
dn_to_info_json = widgets.HiddenField(name="dn_to_info_json")
class UserNewValidator(validators.Schema):
uid = validators.PlainText(not_empty=True)
userpassword = validators.String(not_empty=False)
userpassword_confirm = validators.String(not_empty=False)
givenname = validators.String(not_empty=True)
sn = validators.String(not_empty=True)
mail = validators.Email(not_empty=True)
chained_validators = [
validators.FieldsMatch('userpassword', 'userpassword_confirm')
]
class UserNewForm(widgets.Form):
params = ['user']
hidden_fields = [
UserFields.dn_to_info_json,
]
validator = UserNewValidator()
def __init__(self, *args, **kw):
super(UserNewForm,self).__init__(*args, **kw)
(self.template_c, self.template) = widgets.meta.load_kid_template("ipagui.templates.usernewform")
self.user = UserFields
def update_params(self, params):
super(UserNewForm,self).update_params(params)
class UserEditValidator(validators.Schema):
userpassword = validators.String(not_empty=False)
userpassword_confirm = validators.String(not_empty=False)
givenname = validators.String(not_empty=True)
sn = validators.String(not_empty=True)
mail = validators.Email(not_empty=True)
uidnumber = validators.Int(not_empty=False)
gidnumber = validators.Int(not_empty=False)
pre_validators = [
validators.RequireIfPresent(required='uidnumber', present='editprotected'),
validators.RequireIfPresent(required='gidnumber', present='editprotected'),
]
chained_validators = [
validators.FieldsMatch('userpassword', 'userpassword_confirm')
]
class UserEditForm(widgets.Form):
params = ['user']
hidden_fields = [
UserFields.uid_hidden, UserFields.user_orig,
UserFields.krbPasswordExpiration_hidden,
UserFields.editprotected_hidden,
UserFields.user_groups_data,
UserFields.dn_to_info_json,
]
validator = UserEditValidator()
def __init__(self, *args, **kw):
super(UserEditForm,self).__init__(*args, **kw)
(self.template_c, self.template) = widgets.meta.load_kid_template("ipagui.templates.usereditform")
self.user = UserFields
# TODO - add dynamic field retrieval:
# myfields=[]
# schema = ipa.rpcclient.get_add_schema ()
#
# # FIXME: What if schema is None or an error is thrown?
#
# for s in schema:
# required=False
#
# if (s['type'] == "text"):
# field = widgets.TextField(name=s['name'],label=s['label'])
# elif (s['type'] == "password"):
# field = widgets.PasswordField(name=s['name'],label=s['label'])
#
# if (s['required'] == "true"):
# required=True
#
# if (s['validator'] == "text"):
# field.validator=validators.PlainText(not_empty=required)
# elif (s['validator'] == "email"):
# field.validator=validators.Email(not_empty=required)
# elif (s['validator'] == "string"):
# field.validator=validators.String(not_empty=required)
#
# myfields.append(field)