def new_f(self, member_id, **kwargs): # @TODO request.params may contain multiple values per key... test & fix formok = True errors = [] try: ParamChecker.checkMode('mode', values=('add', 'edit')) except InvalidParameterFormat as ipf: formok = False errors.append(ipf.message) m = Member() for v in m.str_vars: setattr(m, v, self.request.params.get(v, '')) m.uid = member_id try: m.check() except InvalidParameterFormat as ipf: formok = False errors += ipf.message if self.request.params[ 'mode'] == 'add' or not self.request.params.get( 'userPassword', '') == '': try: ParamChecker.checkPassword('userPassword', 'userPassword2') except InvalidParameterFormat as ipf: formok = False errors.append(ipf.message) if not formok: self.session['errors'] = errors self.session['reqparams'] = {} # @TODO request.params may contain multiple values per key... test & fix for k in self.request.params.iterkeys(): if k == 'fullMember' or k == 'lockedMember': if self.request.params[k] == 'on': self.session['reqparams'][k] = True else: self.session['reqparams'][k] = False else: self.session['reqparams'][k] = self.request.params[k] self.session.save() if self.request.params['mode'] == 'add': raise HTTPRedirect('/members/addMember') else: raise HTTPRedirect( '/members/editMember/?member_id={0}'.format(member_id)) return f(self)
def doEditMember(self): try: if self.request.params['mode'] == 'edit': member = self.mf.getUser(self.request.params['member_id']) else: member = Member() member.uid = self.request.params['member_id'] for v in member.str_vars: if v in self.request.params: setattr(member, v, self.request.params.get(v).lstrip(' ').rstrip(' ')) for v in member.bool_vars: if v in self.request.params: setattr(member, v, True) if not self.request.params.get( 'userPassword', '' ) == '' and self.request.params[ 'userPassword'] == self.request.params['userPassword2']: member.setPassword(self.request.params['userPassword']) ''' fullMember / lockedMember''' if 'fullMember' in self.request.params and not Config.get( 'mematool', 'group_fullmember') in member.groups: member.groups.append(Config.get('mematool', 'group_fullmember')) elif not 'fullMember' in self.request.params and Config.get( 'mematool', 'group_fullmember') in member.groups: member.groups.remove(Config.get('mematool', 'group_fullmember')) if 'lockedMember' in self.request.params and not Config.get( 'mematool', 'group_lockedmember') in member.groups: member.groups.append( Config.get('mematool', 'group_lockedmember')) elif not 'lockedMember' in self.request.params and Config.get( 'mematool', 'group_lockedmember') in member.groups: member.groups.remove( Config.get('mematool', 'group_lockedmember')) self.mf.saveMember(member) self.session['flash'] = _('Member details successfully edited') self.session.save() raise HTTPRedirect('/members/editMember/?member_id={0}'.format( self.request.params['member_id'])) except LookupError: print 'No such user !' # @TODO make much more noise ! raise HTTPRedirect('/members/showAllMembers')
def new_f(self, member_id, **kwargs): # @TODO request.params may contain multiple values per key... test & fix formok = True errors = [] try: ParamChecker.checkMode('mode', values=('add', 'edit')) except InvalidParameterFormat as ipf: formok = False errors.append(ipf.message) m = Member() for v in m.str_vars: setattr(m, v, self.request.params.get(v, '')) m.uid = member_id try: m.check() except InvalidParameterFormat as ipf: formok = False errors += ipf.message if self.request.params['mode'] == 'add' or not self.request.params.get('userPassword', '') == '': try: ParamChecker.checkPassword('userPassword', 'userPassword2') except InvalidParameterFormat as ipf: formok = False errors.append(ipf.message) if not formok: self.session['errors'] = errors self.session['reqparams'] = {} # @TODO request.params may contain multiple values per key... test & fix for k in self.request.params.iterkeys(): if k == 'fullMember' or k == 'lockedMember': if self.request.params[k] == 'on': self.session['reqparams'][k] = True else: self.session['reqparams'][k] = False else: self.session['reqparams'][k] = self.request.params[k] self.session.save() if self.request.params['mode'] == 'add': raise HTTPRedirect('/members/addMember') else: raise HTTPRedirect('/members/editMember/?member_id={0}'.format(member_id)) return f(self)
def doEditMember(self): try: if self.request.params['mode'] == 'edit': member = self.mf.getUser(self.request.params['member_id']) else: member = Member() member.uid = self.request.params['member_id'] for v in member.str_vars: if v in self.request.params: setattr(member, v, self.request.params.get(v).lstrip(' ').rstrip(' ')) for v in member.bool_vars: if v in self.request.params: setattr(member, v, True) if not self.request.params.get('userPassword', '') == '' and self.request.params['userPassword'] == self.request.params['userPassword2']: member.setPassword(self.request.params['userPassword']) ''' fullMember / lockedMember''' if 'fullMember' in self.request.params and not Config.get('mematool', 'group_fullmember') in member.groups: member.groups.append(Config.get('mematool', 'group_fullmember')) elif not 'fullMember' in self.request.params and Config.get('mematool', 'group_fullmember') in member.groups: member.groups.remove(Config.get('mematool', 'group_fullmember')) if 'lockedMember' in self.request.params and not Config.get('mematool', 'group_lockedmember') in member.groups: member.groups.append(Config.get('mematool', 'group_lockedmember')) elif not 'lockedMember' in self.request.params and Config.get('mematool', 'group_lockedmember') in member.groups: member.groups.remove(Config.get('mematool', 'group_lockedmember')) self.mf.saveMember(member) self.session['flash'] = _('Member details successfully edited') self.session.save() raise HTTPRedirect('/members/editMember/?member_id={0}'.format(self.request.params['member_id'])) except LookupError: print 'No such user !' # @TODO make much more noise ! raise HTTPRedirect('/members/showAllMembers')