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 index(self): #request = self.request edit_info = self._get_edit_info() if not edit_info['user']: return HTTPFound(location=self.request.route_url('login')) self.model_state.form.data = get_row_dict(edit_info['user']) return edit_info
def index(self): request = self.request user_priorities = [] user_cart = {} with request.connmgr.get_connection() as conn: cursor = conn.execute('EXEC dbo.sp_Search_Page ?', request.user and request.user.Email) keywords = cursor.fetchall() cursor.nextset() modules = cursor.fetchall() cursor.nextset() priorities = cursor.fetchall() cursor.nextset() estimates = cursor.fetchall() cursor.nextset() releases = cursor.fetchall() cursor.nextset() funders = cursor.fetchall() cursor.nextset() statuses = cursor.fetchall() if request.user: cursor.nextset() user_priorities = cursor.fetchall() cursor.nextset() user_cart = get_row_dict(cursor.fetchone()) cursor.close() return dict(keywords=keywords, modules=modules, priorities=priorities, estimates=estimates, user_priorities=user_priorities, releases=releases, funders=funders, statuses=statuses, cart=user_cart)
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 results(self): request = self.request model_state = request.model_state model_state.schema = SearchSchema() model_state.form.method = None if not model_state.validate(): # Validation Error request.override_renderer = 'search.mak' retval = self.index() log.debug('errors: %s', model_state.form.errors) return retval user_priorities = [] user_cart = {} data = model_state.data enhid = data.get('ID') if enhid: return HTTPFound( location=request.route_url('enhancement', id=enhid)) with request.connmgr.get_connection() as conn: args = [request.user and request.user.Email] args.extend(data.get(f) for f in field_order) created_in_the_last_number = data.get('CreatedInTheLastXDays') if created_in_the_last_number: created_in_the_last = date.today() - timedelta( created_in_the_last_number) else: created_in_the_last = None args.append(created_in_the_last) modified_in_the_last_number = data.get('ModifiedInTheLastXDays') if modified_in_the_last_number: modified_in_the_last = date.today() - timedelta( modified_in_the_last_number) else: modified_in_the_last = None args.append(modified_in_the_last) cursor = conn.execute( 'EXEC dbo.sp_Search_Results %s' % ','.join('?' * len(args)), *args) searched_for = cursor.fetchone() cursor.nextset() priorities = cursor.fetchall() cursor.nextset() results = cursor.fetchall() if request.user: cursor.nextset() user_priorities = cursor.fetchall() cursor.nextset() user_cart = get_row_dict(cursor.fetchone()) cursor.close() searched_for = { d[0]: x for d, x in zip(searched_for.cursor_description, searched_for) if x } priority_map = {x[0]: x for x in priorities} include_closed = data.get('IncludeClosed') fulltext_keywords = data.get('Terms') request.session['search_ids'] = [x.ID for x in results] return dict(searched_for=searched_for, priorities=priorities, cart=user_cart, results=results, user_priorities=user_priorities, priority_map=priority_map, include_closed=include_closed, fulltext_keywords=fulltext_keywords, created_in_the_last_number=created_in_the_last_number, modified_in_the_last_number=modified_in_the_last_number)
def results(self): request = self.request model_state = request.model_state model_state.schema = SearchSchema() model_state.form.method = None if not model_state.validate(): # Validation Error request.override_renderer = 'search.mak' retval = self.index() log.debug('errors: %s', model_state.form.errors) return retval user_priorities = [] user_cart = {} data = model_state.data enhid = data.get('ID') if enhid: return HTTPFound(location=request.route_url('enhancement', id=enhid)) with request.connmgr.get_connection() as conn: args = [request.user and request.user.Email] args.extend(data.get(f) for f in field_order) created_in_the_last_number = data.get('CreatedInTheLastXDays') if created_in_the_last_number: created_in_the_last = date.today()-timedelta(created_in_the_last_number) else: created_in_the_last = None args.append(created_in_the_last) modified_in_the_last_number = data.get('ModifiedInTheLastXDays') if modified_in_the_last_number: modified_in_the_last = date.today()-timedelta(modified_in_the_last_number) else: modified_in_the_last = None args.append(modified_in_the_last) cursor = conn.execute('EXEC dbo.sp_Search_Results %s' % ','.join('?' * len(args)), *args) searched_for = cursor.fetchone() cursor.nextset() priorities = cursor.fetchall() cursor.nextset() results = cursor.fetchall() if request.user: cursor.nextset() user_priorities = cursor.fetchall() cursor.nextset() user_cart = get_row_dict(cursor.fetchone()) cursor.close() searched_for = {d[0]: x for d,x in zip(searched_for.cursor_description, searched_for) if x} priority_map = {x[0]: x for x in priorities} include_closed = data.get('IncludeClosed') fulltext_keywords = data.get('Terms') request.session['search_ids'] = [x.ID for x in results] return dict(searched_for=searched_for, priorities=priorities, cart=user_cart, results=results, user_priorities=user_priorities, priority_map=priority_map, include_closed=include_closed, fulltext_keywords=fulltext_keywords, created_in_the_last_number=created_in_the_last_number, modified_in_the_last_number=modified_in_the_last_number)
class Enhancement(ViewBase): 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 {} enhancement = None priorities = [] user_priorities = [] user_cart = {} with request.connmgr.get_connection() as conn: cursor = conn.execute('EXEC dbo.sp_Enhancement_Detail ?, ?', request.user and request.user.Email, enh_id) enhancement = cursor.fetchone() if request.user: cursor.nextset() priorities = cursor.fetchall() cursor.nextset() user_priorities = cursor.fetchall() cursor.nextset() user_cart = get_row_dict(cursor.fetchone()) cursor.close() if enhancement is None: #error condition, change template? self.model_state.add_error_for( '*', 'No enhancement with ID %d' % enh_id) return { 'priorities': priorities, 'user_priorities': user_priorities } enhancement.SysPriority = _priority_xml_to_dict( enhancement.SysPriority) enhancement.UserPriority = _priority_xml_to_dict( enhancement.UserPriority) enhancement.AvgRating = _priority_xml_to_dict(enhancement.AvgRating) enhancement.Modules = _xml_to_dict_list(enhancement.Modules) enhancement.Keywords = _xml_to_dict_list(enhancement.Keywords) enhancement.SeeAlsos = _xml_to_dict_list(enhancement.SeeAlsos) enhancement.Releases = _xml_to_dict_list(enhancement.Releases) enhancement.BasicDescription = _make_html(enhancement.BasicDescription) enhancement.AdditionalNotes = _make_html(enhancement.AdditionalNotes) search_ids = request.session.get('search_ids') enh_nav = [] if search_ids: try: idx = search_ids.index(enhancement.ID) if idx != 0: enh_nav.append(('< prev', search_ids[idx - 1])) if idx != len(search_ids) - 1: enh_nav.append(('next >', search_ids[idx + 1])) except ValueError: pass return { 'enhancement': enhancement, 'enh_nav': enh_nav, 'cart': user_cart, 'priorities': priorities, 'user_priorities': user_priorities }