예제 #1
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('required', formal.String(required=True))
     form.addField('oneString', formal.String(),
             formal.widgetFactory(formal.SelectChoice, options=strings))
     form.addField('anotherString', formal.String(),
             formal.widgetFactory(formal.SelectChoice, options=data_strings))
     form.addField('oneMoreString', formal.String(required=True),
             formal.widgetFactory(formal.RadioChoice, options=data_strings))
     form.addField('oneDate', formal.Date(),
             formal.widgetFactory(formal.SelectChoice, options=dates))
     form.addField('multipleStrings', formal.Sequence(formal.String()),
             formal.widgetFactory(formal.CheckboxMultiChoice,
                 options=data_strings))
     form.addField('multipleDates', formal.Sequence(formal.Date()),
             formal.widgetFactory(formal.CheckboxMultiChoice, options=dates))
     form.addField('differentNoneSelect', formal.String(),
             formal.widgetFactory(formal.SelectChoice, options=strings,
                 noneOption=differentNone))
     form.addField('differentNoneRadios', formal.String(),
             formal.widgetFactory(formal.RadioChoice, options=data_strings,
                 noneOption=differentNone))
     form.addField('selectOther', formal.String(),
             formal.widgetFactory(formal.SelectOtherChoice, options=['Mr',
                 'Mrs']))
     form.addField('selectOtherCustomOther', formal.String(),
             formal.widgetFactory(formal.SelectOtherChoice, options=['Mr',
                 'Mrs'], otherOption=('...','Other (Please Enter)')))
     form.addField('selectOtherRequired', formal.String(required=True),
             formal.widgetFactory(formal.SelectOtherChoice, options=['Mr',
                 'Mrs']))
     form.addField('multiselect', formal.String(),
             formal.widgetFactory(formal.MultiselectChoice, options=strings))
     form.addAction(self.submitted)
     return form
예제 #2
0
 def testDate(self):
     self.assertEquals(formal.Date().validate(None), None)
     self.assertEquals(formal.Date().validate(date(2005, 1, 1)),
                       date(2005, 1, 1))
     self.assertEquals(
         formal.Date(missing=date(2005, 1, 2)).validate(None),
         date(2005, 1, 2))
     self.assertEquals(
         formal.Date(missing=date(2005, 1, 2)).validate(date(2005, 1, 1)),
         date(2005, 1, 1))
     self.assertRaises(formal.FieldValidationError,
                       formal.Date(required=True).validate, None)
예제 #3
0
    def form_searchForm(self, d):
        form = formal.Form()

        form.addField('to', formal.String(), label="To Address Contains")
        form.addField('from',
                      formal.String(),
                      label="From Address Contains",
                      description=["Between Dates"])
        form.addField('fromdate', formal.Date(), label="")
        form.addField('todate', formal.Date(), label="")

        form.addAction(self.submitForm)
        return form
예제 #4
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('isoFormatDate', formal.Date(), formal.TextInput)
     form.addField('monthFirstDate', formal.Date(), formal.DatePartsInput)
     form.addField(
         'dayFirstDate', formal.Date(),
         formal.widgetFactory(formal.DatePartsInput, dayFirst=True))
     form.addField('monthYearDate', formal.Date(),
                   formal.MMYYDatePartsInput)
     form.addField(
         'twoCharYearDate', formal.Date(),
         formal.widgetFactory(formal.DatePartsInput, twoCharCutoffYear=70))
     form.addField('time', formal.Time())
     form.addAction(self.submitted)
     return form
예제 #5
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('aString', formal.String())
     form.addField('aInteger', formal.Integer())
     form.addField('aFloat', formal.Float())
     if haveDecimal:
         form.addField('aDecimal', formal.Decimal())
     form.addField('aBoolean', formal.Boolean())
     form.addField('aDate', formal.Date())
     form.addField('aTime', formal.Time())
     form.addAction(self.submitted)
     return form
예제 #6
0
 def makePersonGroup(name):
     person = formal.Group(name, cssClass=name)
     person.add(formal.Field('name', formal.String(required=True)))
     person.add(formal.Field('dateOfBirth', formal.Date(required=True)))
     person.add(makeAddressGroup('address'))
     return person
예제 #7
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('aString', formal.String(missing='<nothing>'))
     form.addField('aDate', formal.Date(missing=date(2005, 8, 1)))
     form.addAction(self.submitted)
     return form
예제 #8
0
    def form_editForm(self, data):

        domains = []
        if self.avatarId.isAdmin:
            for i in self.flatFil:
                thisdom = i.split('dm=')[-1].split(',')[0]
                if not thisdom in domains:
                    domains.append(thisdom)

        # Form population

        userData = self.lc.getUser(self.cid)

        devList = []
        #extList = []
        rouList = []
        UserExtForm = []
        fkeyForm = []
        if Settings.sambaDN and self.domain == Settings.defaultDomain and PBXUtils.enabled(
        ):
            includeList = []
            includeList = self.sysconf.PBXExtensions.get(
                userData['uid'][0], {'extensions': []})['extensions']
            devIncList = self.sysconf.PBXExtensions.get(
                userData['uid'][0], {'devices': []})['devices']
            extList = PBXUtils.getAvaExtenNumSelect(True, includeList)
            #for ext in PBXUtils.getAvailibleExtensions():
            #    extList.append((str(ext), str(ext)))
            for dev in PBXUtils.getAllAvaExtDeviceEndPoints(devIncList):
                devList.append((str(dev), str(dev)))
            queueList = [
                (queue, queue)
                for queue in self.sysconf.PBX.get('queues', {}).keys()
            ]

            rouList = self.sysconf.PBXRouters.keys()

            extensionWidget = formal.widgetFactory(formal.SelectChoice,
                                                   options=extList)
            deviceWidget = formal.widgetFactory(formal.SelectChoice,
                                                options=devList)
            #queueWidget = formal.widgetFactory(formal.SelectChoice, options = queueList)

            userExtensions = PBXUtils.getExtensionSelect()

            queueOptions = formal.widgetFactory(formal.SelectChoice,
                                                options=[(1, "Level 1 Member"),
                                                         (2, "Level 2 Member"),
                                                         (3, "Level 3 Member")
                                                         ])
            queues = []
            for queue in self.sysconf.PBX.get('queues', {}).keys()[0:-1]:
                queues.append(
                    formal.Field('queue%s' % queue,
                                 formal.Integer(),
                                 queueOptions,
                                 label="Queue %s" % queue))

            try:
                queue = self.sysconf.PBX.get('queues', {}).keys()[-1]
            except:
                queue = None

            if queue:
                queues.append(
                    formal.Field(
                        'queue%s' % queue,
                        formal.Integer(),
                        queueOptions,
                        label="Queue %s" % queue,
                        description=
                        "Each extension may be part of many queues, each queue membersip has a specific weighting. The weighting determines the order in which calls may be seeded. Level 2 members only get calls seeded to them once Level 1 has been saturated etc."
                    ))

            fKeyOptions = formal.widgetFactory(formal.SelectChoice,
                                               options=userExtensions)
            fKeys = []
            maxKeys = 54

            for i in range(maxKeys):
                fKeys.append(
                    formal.Field('fkeys%s' % i,
                                 formal.String(),
                                 fKeyOptions,
                                 label="Key %s" % i))

            fKeys.append(
                formal.Field(
                    'fkeys%s' % maxKeys,
                    formal.String(),
                    fKeyOptions,
                    label="Key %s" % maxKeys,
                    description=
                    "Select the extensions for the function keys above"))

            userExtFormContent = [
                formal.Field('userExtEnabled',
                             formal.Boolean(),
                             label=self.text.userFormLabelExtEnabled),
                formal.Field('userExtOutbound',
                             formal.Sequence(formal.String()),
                             formal.widgetFactory(formal.CheckboxMultiChoice,
                                                  options=[(i, i)
                                                           for i in rouList]),
                             label=self.text.userFormLabelOutbound,
                             description=self.text.userFormDescOutbound),
                #formal.Field('userExtQueues', formal.Sequence(formal.String()),
                #    formal.widgetFactory(formal.CheckboxMultiChoice,
                #        options = queueList),
                #    label = self.text.userFormLabelQueues,
                #    description = self.text.userFormDescQueues),
            ]
            userExtFormContent.extend(queues)

            userExtFormContent.extend([
                formal.Field(
                    'userLowBW',
                    formal.Boolean(),
                    label="Low Bandwidth",
                    description=
                    'Indicates that the devices(if applicable) should use a low bandwidth codec'
                ),
                formal.Field(
                    'userExtTimeout',
                    formal.Integer(),
                    label="Timeout",
                    description=
                    "How many seconds should we wait before giving up on this extension, note that setting this to 0 will force the extension to use the default timeout"
                ),
                formal.Field(
                    'userExtqTimeout',
                    formal.Integer(),
                    label="Queue Timeout",
                    description=
                    "How many seconds should we wait before giving up on this queue member, 0 will indicate to use the default"
                ),
                formal.Field('userExtCallerID',
                             formal.String(),
                             label=self.text.userFormLabelCallID),
                formal.Field('userExtNumber0',
                             formal.String(),
                             extensionWidget,
                             label=self.text.userFormLabelExtNumber),
                formal.Field('userExtNumber1',
                             formal.String(),
                             extensionWidget,
                             label=""),
                formal.Field('userExtNumber2',
                             formal.String(),
                             extensionWidget,
                             label=""),
                formal.Field('userExtNumber3',
                             formal.String(),
                             extensionWidget,
                             label=""),
                formal.Field('userExtNumber4',
                             formal.String(),
                             extensionWidget,
                             label=""),
                formal.Field('userExtNumber5',
                             formal.String(),
                             extensionWidget,
                             label=""),
                formal.Field('userExtNumber6',
                             formal.String(),
                             extensionWidget,
                             label=""),
                formal.Field('userExtNumber7',
                             formal.String(),
                             extensionWidget,
                             label=""),
                formal.Field('userExtNumber8',
                             formal.String(),
                             extensionWidget,
                             label=""),
                formal.Field('userExtNumber9',
                             formal.String(),
                             extensionWidget,
                             label=""),
                tags.div(_class="userLine")[tags.a(
                    href="#",
                    onclick="addExten();")[self.text.userFormLabelAddExt]],
                #formal.Field('userExtFwdUA', formal.String(), label = self.text.userFormLabelRedNoAnswer,
                #    description = self.text.userFormDescRedNoAnswer),
                formal.Field('userExtDev0',
                             formal.String(),
                             deviceWidget,
                             label=self.text.userFormLabelDev),
                formal.Field('userExtDev1',
                             formal.String(),
                             deviceWidget,
                             label=""),
                formal.Field('userExtDev2',
                             formal.String(),
                             deviceWidget,
                             label=""),
                formal.Field('userExtDev3',
                             formal.String(),
                             deviceWidget,
                             label=""),
                formal.Field('userExtDev4',
                             formal.String(),
                             deviceWidget,
                             label=""),
                formal.Field('userExtDev5',
                             formal.String(),
                             deviceWidget,
                             label=""),
                formal.Field('userExtDev6',
                             formal.String(),
                             deviceWidget,
                             label=""),
                formal.Field('userExtDev7',
                             formal.String(),
                             deviceWidget,
                             label=""),
                formal.Field('userExtDev8',
                             formal.String(),
                             deviceWidget,
                             label=""),
                formal.Field('userExtDev9',
                             formal.String(),
                             deviceWidget,
                             label=""),
                tags.div(_class="userLine")[tags.a(
                    href="#",
                    onclick="addExtDev();")[self.text.userFormLabelAddDev]],
                formal.Field('userExtVoiceMail',
                             formal.Boolean(),
                             label=self.text.userFormLabelVoiceMail),
                formal.Field('userExtVoiceMailPin',
                             formal.String(),
                             label=self.text.userFormLabelVoiceMailPin),
            ])
            UserExtForm = formal.Group('userExtension')[userExtFormContent]
            fkeyForm = formal.Group('userFKeys')[fKeys]

        form = formal.Form(
            self.submitForm
        )[formal.Group('userSettings')[tags.div(_class="field")[
            tags.label[self.text.userFormLabelEmailAddress],
            tags.div(id="emailAd", _class="inputs")["%s@%s" %
                                                    (self.cid, self.domain)]],
                                       formal.Field('uid',
                                                    formal
                                                    .String(required=True,
                                                            validators=Base
                                                            .UserNameValidators),
                                                    label=self.text.
                                                    userFormLabelUsername),
                                       formal.Field('givenName',
                                                    formal.String(
                                                        required=True),
                                                    label=self.text.
                                                    userFormLabelName),
                                       formal.Field('sn',
                                                    formal.String(),
                                                    label=self.text.
                                                    userFormLabelSurname),
                                       formal.Field('userPassword',
                                                    formal.String(),
                                                    formal.CheckedPassword,
                                                    label=self.text.
                                                    userFormLabelPass), ],
          formal.Group('mailSettings')
          [formal.Field('mailForwardingAddress0',
                        formal.String(),
                        label=self.
                        text.userFormLabelForward),
           formal.Field('mailForwardingAddress1', formal.String(), label=""),
           formal.Field('mailForwardingAddress2', formal.String(), label=""),
           formal.Field('mailForwardingAddress3', formal.String(), label=""),
           formal.Field('mailForwardingAddress4', formal.String(), label=""),
           formal.Field('mailForwardingAddress5', formal.String(), label=""),
           formal.Field('mailForwardingAddress6', formal.String(), label=""),
           formal.Field('mailForwardingAddress7', formal.String(), label=""),
           formal.Field('mailForwardingAddress8', formal.String(), label=""),
           formal.Field('mailForwardingAddress9', formal.String(), label=""),
           tags.div(
               _class="userLine")[tags.a(href="#", onclick="addForward();"
                                         )[self.text.userFormLabelAddline]],
           formal.Field('mailAlternateAddress0',
                        formal.String(),
                        label=self.text.userFormLabelAlias),
           formal.Field('mailAlternateAddress1', formal.String(), label=""),
           formal.Field('mailAlternateAddress2', formal.String(), label=""),
           formal.Field('mailAlternateAddress3', formal.String(), label=""),
           formal.Field('mailAlternateAddress4', formal.String(), label=""),
           formal.Field('mailAlternateAddress5', formal.String(), label=""),
           formal.Field('mailAlternateAddress6', formal.String(), label=""),
           formal.Field('mailAlternateAddress7', formal.String(), label=""),
           formal.Field('mailAlternateAddress8', formal.String(), label=""),
           formal.Field('mailAlternateAddress9', formal.String(), label=""),
           tags.div(
               _class="userLine")[tags.a(href="#", onclick="addAlias();"
                                         )[self.text.userFormLabelAddline]],
           formal.Field('vacen',
                        formal.Boolean(),
                        label=self.text.userFormLabelVacationActive,
                        description=self.text.userFormTextVacationNote),
           formal.Field('vacation',
                        formal.String(),
                        formal.TextArea,
                        label=self.text.userFormLabelVacation),
           formal.Field('vacvalidity',
                        formal.Date(),
                        label="Valid until",
                        description=
                        "Disable the vacation note automatically on this date"
                        )],
          formal.Group('userPermissions')[
              formal.Field('employeeType',
                           formal.Boolean(),
                           label=self.text.userFormLabelWeb),
              formal.Field('accountStatus',
                           formal.Boolean(),
                           label=self.text.userFormLabelEmail),
              formal.Field('tumsAdmin',
                           formal.Boolean(),
                           label=self.text.userFormLabelAdmin),
              formal.Field('tumsUser',
                           formal.Sequence(formal.String()),
                           formal.widgetFactory(formal.CheckboxMultiChoice, [(
                               i, i) for i in domains]),
                           label=self.text.userFormLabelDomainAdmin),
              formal.Field('tumsReports',
                           formal.Boolean(),
                           label=self.text.userFormLabelReports),
              formal.Field('copyto',
                           formal.String(),
                           label=self.text.userFormLabelCopy,
                           description=self.text.userFormTextCopy)],
          formal.Group('userAccess')[
              formal.Field('vpnEnabled',
                           formal.Boolean(),
                           label=self.text.userFormLabelVPN,
                           description=self.text.userFormTextVPN),
              formal.Field('ftpEnabled',
                           formal.Boolean(),
                           label=self.text.userFormLabelFTP,
                           description=self.text.userFormTextFTP),
              formal.Field('ftpGlobal',
                           formal.Boolean(),
                           label=self.text.userFormLabelGlobalFTP,
                           description=self.text.userFormTextGlobal)],
          UserExtForm, fkeyForm]

        form.addAction(self.submitForm)

        tData = copy.deepcopy(userData)
        tData['userSettings.uid'] = tData['uid'][0]
        tData['userSettings.givenName'] = tData.get('givenName', [""])[0]
        tData['userSettings.sn'] = tData.get('sn', [""])[0]

        if tData.get('loginShell'):
            if '/bin/bash' in tData['loginShell']:
                tData['userAccess.ftpEnabled'] = True

        if self.sysconf.FTP.get('globals'):
            if tData['uid'][0] in self.sysconf.FTP['globals']:
                tData['userAccess.ftpGlobal'] = True

        tData['userSettings.userPassword'] = ''  # Strip password
        address = "%s@%s" % (tData['uid'][0], self.domain)

        for i in os.listdir('/etc/openvpn/keys/'):
            if "%s.%s" % (self.cid, self.domain) in i and "key" in i:
                tData['userAccess.vpnEnabled'] = True

        if self.sysconf.Mail.get('copys', []):
            for addr, dest in self.sysconf.Mail['copys']:
                if addr == address:
                    tData['userPermissions.copyto'] = dest

        if userData.get('accountStatus', False):
            tData['userPermissions.accountStatus'] = True
        else:
            tData['userPermissions.accountStatus'] = False

        if userData.get('mailForwardingAddress', False):
            for cnt, address in enumerate(userData['mailForwardingAddress']):
                tData['mailSettings.mailForwardingAddress%s' % cnt] = address

        if userData.get('mailAlternateAddress', False):
            for cnt, address in enumerate(userData['mailAlternateAddress']):
                tData['mailSettings.mailAlternateAddress%s' % cnt] = address

        emp = userData.get('employeeType', [False])

        if 'squid' in emp:
            tData['userPermissions.employeeType'] = True
        else:
            tData['userPermissions.employeeType'] = False

        if 'tumsAdmin' in emp:
            tData['userPermissions.tumsAdmin'] = True
        else:
            tData['userPermissions.tumsAdmin'] = False

        if 'tumsReports' in emp:
            tData['userPermissions.tumsReports'] = True
        else:
            tData['userPermissions.tumsReports'] = False

        if emp[0]:
            for i in emp:
                if 'tumsUser[' in i:
                    tData['userPermissions.tumsUser'] = i.split('[')[-1].split(
                        ']')[0].split(',')

        try:
            vac = open(
                "/var/spool/mail/vacation/%s@%s.txt" % (self.cid, self.domain),
                'r')
            tData['mailSettings.vacation'] = vac.read()
            tData['mailSettings.vacen'] = True
        except:
            pass  # No vacation note

        try:
            vac = open(
                "/var/spool/mail/vacation/DISABLED%s@%s.txt" %
                (self.cid, self.domain), 'r')
            tData['mailSettings.vacation'] = vac.read()
            tData['mailSettings.vacen'] = False
        except:
            pass  # No disabled note either.

        if os.path.exists('/var/spool/mail/vacation/%s@%s.validity' %
                          (self.cid, self.domain)):
            n = open('/var/spool/mail/vacation/%s@%s.validity' %
                     (self.cid, self.domain)).read().strip('\n')
            d = datetime.date(*[int(i) for i in n.split('-')])
            tData['mailSettings.vacvalidity'] = d

        #Populate Userextension Data
        if PBXUtils.enabled():
            ext = self.sysconf.PBXExtensions.get(
                tData['uid'][0], {
                    'enabled': False,
                    'lowbw': False,
                    'outbound': [],
                    'callerID': "",
                    'voiceMail': False,
                    'voiceMailPin': '',
                    'fkeys': [],
                    'extensions': [],
                    'devices': [],
                    'queues': {}
                })
            tData['userExtension.userExtEnabled'] = ext['enabled']
            tData['userExtension.userExtOutbound'] = ext['outbound']
            tData['userExtension.userExtTimeout'] = ext.get('timeout', 0)
            tData['userExtension.userExtqTimeout'] = ext.get('qtimeout', 0)
            #tData['userExtension.userExtQueues'] = ext.get('queues', [])
            queueSettings = ext.get('queues', {})
            if type(queueSettings) == list:
                n = {}
                for queue in queueSettings:
                    n[queue] = 1
                queueSettings = n
            for queue in self.sysconf.PBX.get('queues', {}).keys():
                tData['userExtension.queue%s' % queue] = queueSettings.get(
                    queue, None)
            tData['userExtension.userExtCallerID'] = ext['callerID']
            tData['userExtension.userExtVoiceMail'] = ext['voiceMail']
            tData['userExtension.userExtVoiceMailPin'] = ext['voiceMailPin']
            tData['userExtension.userLowBW'] = ext.get('lowbw', False)
            for i in range(0, 9):
                try:
                    tData['userExtension.userExtNumber%s' %
                          i] = ext['extensions'][i]
                except:
                    pass
                try:
                    tData['userExtension.userExtDev%s' % i] = ext['devices'][i]
                except:
                    pass
            for i in range(54):
                try:
                    tData['userFKeys.fkeys%s' % i] = ext['fkeys'][i]
                except:
                    pass

        form.data = tData
        return form
예제 #9
0
파일: Edit.py 프로젝트: calston/tums
    def form_editForm(self, data):

        domains = []
        if self.avatarId.isAdmin:
            for i in self.flatFil:
                thisdom = i.split('dm=')[-1].split(',')[0]
                if not thisdom in domains:
                    domains.append(thisdom)

        # Form population

        userData = self.lc.getUser(self.cid)

        devList = []
        #extList = []
        rouList = []
        UserExtForm = []
        fkeyForm = [] 
        if Settings.sambaDN and self.domain==Settings.defaultDomain and PBXUtils.enabled():
            includeList = []
            includeList = self.sysconf.PBXExtensions.get(userData['uid'][0], {'extensions':[]})['extensions']
            extList = PBXUtils.getAvaExtenNumSelect(True, includeList)
            #for ext in PBXUtils.getAvailibleExtensions():
            #    extList.append((str(ext), str(ext)))
            for dev in PBXUtils.getAllAvaExtDeviceEndPoints():
                devList.append((str(dev), str(dev)))
            queueList = [(queue, queue) for queue in self.sysconf.PBX.get('queues', {}).keys()]
                
            rouList = self.sysconf.PBXRouters.keys()

            extensionWidget = formal.widgetFactory(formal.SelectChoice, options = extList)
            deviceWidget = formal.widgetFactory(formal.SelectChoice, options = devList)
            #queueWidget = formal.widgetFactory(formal.SelectChoice, options = queueList)

            userExtensions = PBXUtils.getExtensionSelect()

            
            fKeyOptions = formal.widgetFactory(formal.SelectChoice, options = userExtensions)
            fKeys = []
            maxKeys = 11
            for i in range(maxKeys):
                fKeys.append(formal.Field('fkeys%s' % i, formal.String(), fKeyOptions, label = "Key %s" % i))

            fKeys.append(formal.Field('fkeys%s'%maxKeys, formal.String(), fKeyOptions, label = "Key %s"%maxKeys, 
                description = "Select the extensions for the function keys above"))


            UserExtForm = formal.Group('userExtension')[
                formal.Field('userExtEnabled', formal.Boolean(), label = self.text.userFormLabelExtEnabled),
                formal.Field('userExtOutbound', formal.Sequence(formal.String()),
                    formal.widgetFactory(formal.CheckboxMultiChoice,
                        options=[(i,i) for i in rouList]),
                    label = self.text.userFormLabelOutbound,
                    description = self.text.userFormDescOutbound),
                formal.Field('userExtQueues', formal.Sequence(formal.String()),
                    formal.widgetFactory(formal.CheckboxMultiChoice,
                        options = queueList),
                    label = self.text.userFormLabelQueues,
                    description = self.text.userFormDescQueues),
                formal.Field('userExtCallerID', formal.String(), label = self.text.userFormLabelCallID),
                formal.Field('userExtNumber0', formal.String(), extensionWidget, label = self.text.userFormLabelExtNumber),
                formal.Field('userExtNumber1', formal.String(), extensionWidget,label = ""),
                formal.Field('userExtNumber2', formal.String(), extensionWidget,label = ""),
                formal.Field('userExtNumber3', formal.String(), extensionWidget,label = ""),
                formal.Field('userExtNumber4', formal.String(), extensionWidget,label = ""),
                formal.Field('userExtNumber5', formal.String(), extensionWidget,label = ""),
                formal.Field('userExtNumber6', formal.String(), extensionWidget,label = ""),
                formal.Field('userExtNumber7', formal.String(), extensionWidget,label = ""),
                formal.Field('userExtNumber8', formal.String(), extensionWidget,label = ""),
                formal.Field('userExtNumber9', formal.String(), extensionWidget,label = ""),
                tags.div(_class="userLine")[tags.a(href="#", onclick="addExten();")[self.text.userFormLabelAddExt]],
                formal.Field('userExtFwdUA', formal.String(), label = self.text.userFormLabelRedNoAnswer,
                    description = self.text.userFormDescRedNoAnswer),
                formal.Field('userExtDev0', formal.String(), deviceWidget,label = self.text.userFormLabelDev),
                formal.Field('userExtDev1', formal.String(), deviceWidget,label = ""),
                formal.Field('userExtDev2', formal.String(), deviceWidget,label = ""),
                formal.Field('userExtDev3', formal.String(), deviceWidget,label = ""),
                formal.Field('userExtDev4', formal.String(), deviceWidget,label = ""),
                formal.Field('userExtDev5', formal.String(), deviceWidget,label = ""),
                formal.Field('userExtDev6', formal.String(), deviceWidget,label = ""),
                formal.Field('userExtDev7', formal.String(), deviceWidget,label = ""),
                formal.Field('userExtDev8', formal.String(), deviceWidget,label = ""),
                formal.Field('userExtDev9', formal.String(), deviceWidget,label = ""),
                tags.div(_class="userLine")[tags.a(href="#", onclick="addExtDev();")[self.text.userFormLabelAddDev]],
                formal.Field('userExtVoiceMail', formal.Boolean(), label = self.text.userFormLabelVoiceMail),
                formal.Field('userExtVoiceMailPin', formal.String(), label = self.text.userFormLabelVoiceMailPin),
            ]
            fkeyForm = formal.Group('userFKeys')[fKeys]

        form = formal.Form(self.submitForm)[
            formal.Group('userSettings')[
                tags.div(_class="field")[
                    tags.label[self.text.userFormLabelEmailAddress],
                    tags.div(id="emailAd", _class="inputs")[
                        "%s@%s"% (self.cid, self.domain)
                    ]
                ],
                formal.Field('uid', formal.String(required=True), label = self.text.userFormLabelUsername),
                formal.Field('givenName', formal.String(required=True), label = self.text.userFormLabelName),
                formal.Field('sn', formal.String(), label = self.text.userFormLabelSurname),
                formal.Field('userPassword', formal.String(), formal.CheckedPassword, label= self.text.userFormLabelPass),
            ],
            formal.Group('mailSettings')[

                formal.Field('mailForwardingAddress0', formal.String(), label=self.text.userFormLabelForward),
                formal.Field('mailForwardingAddress1', formal.String(), label=""),
                formal.Field('mailForwardingAddress2', formal.String(), label=""),
                formal.Field('mailForwardingAddress3', formal.String(), label=""),
                formal.Field('mailForwardingAddress4', formal.String(), label=""),
                formal.Field('mailForwardingAddress5', formal.String(), label=""),
                formal.Field('mailForwardingAddress6', formal.String(), label=""),
                formal.Field('mailForwardingAddress7', formal.String(), label=""),
                formal.Field('mailForwardingAddress8', formal.String(), label=""),
                formal.Field('mailForwardingAddress9', formal.String(), label=""),

                tags.div(_class="userLine")[tags.a(href="#", onclick="addForward();")[self.text.userFormLabelAddline]],
                formal.Field('mailAlternateAddress0', formal.String(), label=self.text.userFormLabelAlias),
                formal.Field('mailAlternateAddress1', formal.String(), label=""),
                formal.Field('mailAlternateAddress2', formal.String(), label=""),
                formal.Field('mailAlternateAddress3', formal.String(), label=""),
                formal.Field('mailAlternateAddress4', formal.String(), label=""),
                formal.Field('mailAlternateAddress5', formal.String(), label=""),
                formal.Field('mailAlternateAddress6', formal.String(), label=""),
                formal.Field('mailAlternateAddress7', formal.String(), label=""),
                formal.Field('mailAlternateAddress8', formal.String(), label=""),
                formal.Field('mailAlternateAddress9', formal.String(), label=""),
                tags.div(_class="userLine")[tags.a(href="#", onclick="addAlias();")[self.text.userFormLabelAddline]],

                formal.Field('vacen', formal.Boolean(), label = self.text.userFormLabelVacationActive, description=self.text.userFormTextVacationNote),
                formal.Field('vacation', formal.String(), formal.TextArea, label=self.text.userFormLabelVacation),
                formal.Field('vacvalidity', formal.Date(), label = "Valid until", description="Disable the vacation note automatically on this date")
            ],
            formal.Group('userPermissions')[
                formal.Field('employeeType', formal.Boolean(), label = self.text.userFormLabelWeb),
                formal.Field('accountStatus', formal.Boolean(), label = self.text.userFormLabelEmail),
                formal.Field('tumsAdmin', formal.Boolean(), label = self.text.userFormLabelAdmin),
                formal.Field('tumsUser', formal.Sequence(formal.String()), formal.widgetFactory(formal.CheckboxMultiChoice, [(i,i) for i in domains]),
                    label = self.text.userFormLabelDomainAdmin),
                formal.Field('tumsReports', formal.Boolean(), label = self.text.userFormLabelReports),
                formal.Field('copyto', formal.String(), label = self.text.userFormLabelCopy,
                    description = self.text.userFormTextCopy)
            ],
            formal.Group('userAccess')[
                formal.Field('vpnEnabled', formal.Boolean(), label = self.text.userFormLabelVPN,
                    description = self.text.userFormTextVPN),
                formal.Field('ftpEnabled', formal.Boolean(), label = self.text.userFormLabelFTP,
                    description = self.text.userFormTextFTP),
                formal.Field('ftpGlobal', formal.Boolean(), label = self.text.userFormLabelGlobalFTP,
                    description = self.text.userFormTextGlobal)
            ],
            UserExtForm,
            fkeyForm
        ]


        form.addAction(self.submitForm)

       
        tData = copy.deepcopy(userData)
        tData['userSettings.uid'] = tData['uid'][0]
        tData['userSettings.givenName'] = tData.get('givenName', [""])[0]
        tData['userSettings.sn']  = tData.get('sn', [""])[0]

        if tData.get('loginShell'):
            if '/bin/bash' in tData['loginShell']:
                tData['userAccess.ftpEnabled'] = True

        if self.sysconf.FTP.get('globals'):
            if tData['uid'][0] in self.sysconf.FTP['globals']:
                tData['userAccess.ftpGlobal'] = True

        tData['userSettings.userPassword'] = '' # Strip password
        address = "%s@%s" % (tData['uid'][0], self.domain)

        for i in os.listdir('/etc/openvpn/keys/'):
            if "%s.%s" % (self.cid, self.domain) in i and "key" in i:
                tData['userAccess.vpnEnabled'] = True

        if self.sysconf.Mail.get('copys', []):
            for addr, dest in self.sysconf.Mail['copys']:
                if addr == address:
                    tData['userPermissions.copyto'] = dest

        if userData.get('accountStatus', False):
            tData['userPermissions.accountStatus'] = True
        else: 
            tData['userPermissions.accountStatus'] = False

        if userData.get('mailForwardingAddress', False):
            for cnt,address in enumerate(userData['mailForwardingAddress']):
                tData['mailSettings.mailForwardingAddress%s' % cnt] = address

        if userData.get('mailAlternateAddress', False):
            for cnt,address in enumerate(userData['mailAlternateAddress']):
                tData['mailSettings.mailAlternateAddress%s' % cnt] = address

        emp = userData.get('employeeType', [False])
        
        if 'squid' in emp:
            tData['userPermissions.employeeType'] = True
        else:
            tData['userPermissions.employeeType'] = False
    
        if 'tumsAdmin' in emp:
            tData['userPermissions.tumsAdmin'] = True
        else:
            tData['userPermissions.tumsAdmin'] = False

        if 'tumsReports' in emp:
            tData['userPermissions.tumsReports'] = True
        else:
            tData['userPermissions.tumsReports'] = False

        if emp[0]:
            for i in emp:
                if 'tumsUser[' in i:
                    tData['userPermissions.tumsUser'] = i.split('[')[-1].split(']')[0].split(',')

        try:
            vac = open("/var/spool/mail/vacation/%s@%s.txt" % (self.cid, self.domain), 'r')
            tData['mailSettings.vacation'] = vac.read()
            tData['mailSettings.vacen'] = True
        except:
            pass # No vacation note

        try:
            vac = open("/var/spool/mail/vacation/DISABLED%s@%s.txt" % (self.cid, self.domain), 'r')
            tData['mailSettings.vacation'] = vac.read()
            tData['mailSettings.vacen'] = False
        except:
            pass # No disabled note either.

        if os.path.exists('/var/spool/mail/vacation/%s@%s.validity' % (self.cid, self.domain)):
            n = open('/var/spool/mail/vacation/%s@%s.validity'% (self.cid, self.domain)).read().strip('\n')
            d = datetime.date(*[int(i) for i in n.split('-')])
            tData['mailSettings.vacvalidity'] = d

        #Populate Userextension Data
        if PBXUtils.enabled():
            ext = self.sysconf.PBXExtensions.get(tData['uid'][0], {
                'enabled': False,
                'outbound': [],
                'callerID': "",
                'voiceMail': False,
                'voiceMailPin': '',
                'fkeys': [],
                'extensions': [],
                'devices': [],
                'queues': []
            }) 
            tData['userExtension.userExtEnabled'] = ext['enabled']
            tData['userExtension.userExtOutbound'] = ext['outbound']
            tData['userExtension.userExtQueues'] = ext.get('queues', [])
            tData['userExtension.userExtCallerID'] = ext['callerID']
            tData['userExtension.userExtVoiceMail'] = ext['voiceMail']
            tData['userExtension.userExtVoiceMailPin'] = ext['voiceMailPin']
            for i in range(0,9):
                try: 
                    tData['userExtension.userExtNumber%s'%i]=ext['extensions'][i]
                except:
                    pass
                try: 
                    tData['userExtension.userExtDev%s'%i]=ext['devices'][i]
                except:
                    pass
            for i in range(12):
                try:
                    tData['userFKeys.fkeys%s'%i] = ext['fkeys'][i]
                except:
                    pass

        form.data = tData
        return form