def edit(self): request = self.request action = request.matchdict.get('action') is_add = action == 'add' ID = None if not is_add: validator = validators.IntID(not_empty=not is_add) try: ID = validator.to_python(request.params.get('ID')) except validators.Invalid: raise ErrorPage('Update Enhancement', 'Invalid ID') edit_info = self._get_edit_info(ID, is_add) if not is_add: data = self.model_state.form.data = get_row_dict( edit_info['enhancement']) data['Keywords'] = [ unicode(x.KEYWORD_ID) for x in edit_info['keywords'] if x.IS_SELECTED ] data['Modules'] = [ unicode(x.MODULE_ID) for x in edit_info['modules'] if x.IS_SELECTED ] data['Releases'] = [ unicode(x.RELEASE_ID) for x in edit_info['releases'] if x.IS_SELECTED ] data['SeeAlso'] = [unicode(x.ID) for x in edit_info['see_alsos']] return edit_info
def __call__(self): request = self.request validator = validators.IntID(not_empty=True) try: enh_id = validator.to_python(request.matchdict['id']) except validators.Invalid, e: # Change template? self.model_state.add_error_for('*', 'Invalid Enhancement: ' + e.message) return {}
class UserDataSchema(Schema): allow_extra_fields = True filter_extra_fields = True if_key_missing = None Email = All(validators.MaxLength(50), validators.Email(not_empty=True)) Member = validators.IntID() Agency = validators.AgencyCode() OrgName = validators.String(max=150) FirstName = validators.String(max=50) LastName = validators.String(max=50)
def getenhancement(self): request = self.request ID = None validator = validators.IntID(not_empty=True) try: ID = validator.to_python(request.params.get('ID')) except validators.Invalid: return {'success': False, 'errmsg': 'Invalid ID'} with request.connmgr.get_connection() as conn: result = conn.execute( 'SELECT ID, Title FROM Enhancement WHERE ID=?', ID).fetchone() if not result: return {'success': False, 'errmsg': 'No enhancemnt with given ID'} return {'success': True, 'ID': result.ID, 'Title': result.Title}
class SearchSchema(Schema): allow_extra_fields = True filter_extra_fields = True if_key_missing = None Terms = validators.UnicodeString(max=100) Keyword = validators.IntID() Module = validators.String(max=1) UserPriority = validators.IntID() SysPriority = validators.IntID() Estimate = validators.Int(min=0, max=32767) IncludeClosed = validators.Bool() CreatedInTheLastXDays = validators.Int(min=1, max=32767) ModifiedInTheLastXDays = validators.Int(min=1, max=32767) Release = validators.IntID() Funder = validators.Int(min=-1, max=32767) Status = validators.IntID() ID = validators.IntID()
class EnhancementSchema(Schema): if_key_missing = None allow_extra_fields = True filter_extra_fields = True Title = validators.String(max=255, not_empty=True) SYS_PRIORITY = validators.IntID(not_empty=True) SYS_ESTIMATE = validators.Int(min=0, max=15, not_empty=True) SYS_STATUS = validators.IntID(max=7, not_empty=True) SYS_FUNDER = validators.IntID() BasicDescription = validators.String(max=8000) AdditionalNotes = validators.String(max=2000) SYS_SOURCETYPE = validators.IntID() SourceDetail = validators.String(max=255) Modules = ForEach(validators.String(min=1, max=1)) Keywords = ForEach(validators.IntID()) Releases = ForEach(validators.IntID()) SeeAlso = ForEach(validators.IntID()) chained_validators = [validators.ForceRequire('Modules', 'Keywords')]
def save(self): request = self.request user = request.user action = request.matchdict.get('action') is_add = action == 'add' extra_validators = {} model_state = request.model_state if not is_add: extra_validators['ID'] = validators.IntID(not_empty=True) model_state.schema = EnhancementSchema(**extra_validators) if model_state.validate(): if not is_add: ID = model_state.value('ID') else: ID = None args = [ID, user.Email] args.extend( model_state.value(k) for k in [ 'Title', 'BasicDescription', 'AdditionalNotes', 'SYS_ESTIMATE', 'SYS_FUNDER', 'SYS_PRIORITY', 'SYS_STATUS', 'SYS_SOURCETYPE', 'SourceDetail' ]) args.extend( ','.join(map(str, model_state.value(k))) for k in ['Modules', 'Keywords', 'Releases', 'SeeAlso']) with request.connmgr.get_connection() as conn: sql = '''DECLARE @RC int, @ErrMsg nvarchar(500), @EnhID int SET @EnhID = ? EXEC @RC = sp_Enhancement_Update @EnhID OUTPUT, %s, @ErrMsg OUTPUT SELECT @RC AS [Return], @ErrMsg AS ErrMsg, @EnhID AS [ID]''' % ','.join( '?' * (len(args) - 1)) result = conn.execute(sql, args).fetchone() if not result.ErrMsg: raise HTTPFound(location=request.current_route_url( action='edit', _query=[('ID', result.ID)])) model_state.add_error_for('*', result.ErrMsg) else: if not is_add and model_state.is_error('ID'): raise ErrorPage('Update Enhancement', 'Invalid ID') edit_info = self._get_edit_info( model_state.value('ID'), is_add, ','.join(request.POST.getall('SeeAlso'))) data = model_state.form.data data['Keywords'] = request.POST.getall('Keywords') data['Modules'] = request.POST.getall('Modules') data['Releases'] = request.POST.getall('Releases') data['SeeAlso'] = request.POST.getall('SeeAlso') return edit_info
class UserPrioritySchema(Schema): id = validators.IntID(not_empty=True) enhancements = ForEach(validators.IntID())