def __init__(self): self.fields = ( oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True, validator_list=[ validators.isAlphaNumeric, self.isValidUsername ]), oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), oldforms.PasswordField( field_name='password2', length=30, max_length=60, is_required=True, validator_list=[ validators.AlwaysMatchesOtherField( 'password1', _("The two password fields didn't match.")) ]), )
def __init__(self, user): self.user = user self.fields = ( oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), oldforms.PasswordField( field_name='password2', length=30, max_length=60, is_required=True, validator_list=[ validators.AlwaysMatchesOtherField( 'password1', _("The two password fields didn't match.")) ]), )
def __init__(self, request=None): """ If request is passed in, the manipulator will validate that cookies are enabled. Note that the request (a HttpRequest object) must have set a cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before running this validator. """ self.request = request self.fields = [ oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True, validator_list=[self.isValidUser, self.hasCookiesEnabled]), oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True), ] self.user_cache = None
def __init__(self, user): self.user = user self.fields = ( oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True, validator_list=[self.isValidOldPassword]), oldforms.PasswordField( field_name="new_password1", length=30, max_length=30, is_required=True, validator_list=[ validators.AlwaysMatchesOtherField( 'new_password2', _("The two 'new password' fields didn't match.")) ]), oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True), )
def _selectWidget(self, field, wikidpage) : """Select the appropriate widget for a wikidpage field.""" data = field.data # Try to get the context for this page wikidpageContext = None if wikidpage.context : wikidpageContexts = wikidbase.core.context.getContexts() nContext = wikidbase.core.normaliseTerm(wikidpage.context) if nContext in wikidpageContexts : wikidpageContext = wikidpageContexts[nContext] # If there is no data to guess the widget from, look in the context of this page. if not data and wikidpageContext : if field.nName in wikidpageContext.dataFieldContexts : try : data = wikidpageContext.dataFieldContexts[field.nName].representativeData.stack[0] except : pass dataObject = datatype.convert(data, mode=datatype.TO_PYTHON) debugOutput("field %s, data: %s, dataObject: %s, type: %s" % (field.nName, data, dataObject, type(dataObject))) formField = None # TODO: # # if date - > date # if bdolean -> checkbox # if multiline data # if not list -> text area # else -> multiselect # if date - > date # if boolean -> checkbox # else (if just single line text) # if mlist -> multiselect # if slist -> select # else : # single text field. # Load the context state. widgetType = wikidbase.core.context.AUTO_WIDGET listSort = wikidbase.core.context.SORT_MOST_COMMON listChoices = [] if wikidpage.context : nContext = wikidbase.core.context.normaliseTerm(wikidpage.context) nFieldName = field.nName contextFieldState = wikidbase.core.state.getContextFieldState(nContext, nFieldName) try : widgetType = contextFieldState[wikidbase.core.context.LIST_STYLE] listSort = contextFieldState[wikidbase.core.context.LIST_SORT] listChoices = contextFieldState[wikidbase.core.context.LIST_CHOICES].splitlines() except : pass debugOutput("widgetType %s, listSort %s, listChoices %s" % (widgetType, listSort, listChoices)) # Compute selection choices. if wikidpageContext and field.nName in wikidpageContext.dataFieldContexts : choices = [choice for choice in wikidpageContext.dataFieldContexts[field.nName].selectionSet] else : choices = [] # Append field state choices choices[0:0] = listChoices if data : # Note, we interpret lines as multiple selections. dataLines = data.splitlines() for dataItem in dataLines : if dataItem not in choices : choices[0:0] = [dataItem] # Remove duplicates - could be more efficient. uniqueChoices = [] for choice in choices : if choice not in uniqueChoices : uniqueChoices.append(choice) choices = uniqueChoices # Sort choices if listSort == wikidbase.core.context.SORT_ASCEND : choices.sort() elif listSort == wikidbase.core.context.SORT_DESCEND : choices.sort(reverse=True) choices = [[choice, choice] for choice in choices] # TODO: We should be able to add hooks here so people can add widgets . # In wikidbase, there are two ways to choose a widget for a field: # * Explicit: the user sets the widget to single-select/multi-select list, textarea, etc. # * Implicit: the widget is chosen based on data or on context data for that field if empty (e.g. date string -> cal widget). if widgetType == wikidbase.core.context.TEXTAREA : formField = widgets.LargeTextFieldExtra(field_name=field.name, is_required=False, rows=6,cols=40) # TODO: Should we use WP_MULTILINE_FIELD to choose widget now? elif data and (field.type == wikidbase.core.pagecontent.WP_MULTILINE_FIELD or "\n" in data) : if widgetType == wikidbase.core.context.AUTO_WIDGET : formField = widgets.LargeTextFieldExtra(field_name=field.name, is_required=False, rows=6,cols=40) else : formField = forms.SelectMultipleField(field_name=field.name, is_required=False, choices=choices) elif type(dataObject) == datetime.date : formField = widgets.NickDatetimeField(field_name=field.name, is_required=False, showsTime=False) elif type(dataObject) == datetime.datetime : formField = widgets.NickDatetimeField(field_name=field.name, is_required=False, showsTime=True) elif type(dataObject) == datetime.time : formField = widgets.NickDatetimeField(field_name=field.name, is_required=False, showsTime=True, inputDate=False) elif type(dataObject) == bool : formField = forms.CheckboxField(field_name=field.name) else : if widgetType == wikidbase.core.context.MS_LIST : formField = forms.SelectMultipleField(field_name=field.name, is_required=False, choices=choices) elif widgetType == wikidbase.core.context.SS_LIST : formField = widgets.EditableSelectField(field_name=field.name, is_required=False, choices=choices) elif field.nName in ["password"] : formField = forms.PasswordField(field_name=field.name, is_required=False) else : formField = widgets.TextFieldExtra(field_name=field.name, is_required=False) return formField