Added id and .status fields to Employee grid view.
				
					
				
			This commit is contained in:
		
							parent
							
								
									06429a4d05
								
							
						
					
					
						commit
						c6f5df7721
					
				
					 3 changed files with 91 additions and 3 deletions
				
			
		
							
								
								
									
										29
									
								
								rattail/pyramid/grids/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								rattail/pyramid/grids/__init__.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,29 @@ | ||||||
|  | #!/usr/bin/env python | ||||||
|  | # -*- coding: utf-8  -*- | ||||||
|  | ################################################################################ | ||||||
|  | # | ||||||
|  | #  Rattail -- Retail Software Framework | ||||||
|  | #  Copyright © 2010-2012 Lance Edgar | ||||||
|  | # | ||||||
|  | #  This file is part of Rattail. | ||||||
|  | # | ||||||
|  | #  Rattail is free software: you can redistribute it and/or modify it under the | ||||||
|  | #  terms of the GNU Affero General Public License as published by the Free | ||||||
|  | #  Software Foundation, either version 3 of the License, or (at your option) | ||||||
|  | #  any later version. | ||||||
|  | # | ||||||
|  | #  Rattail is distributed in the hope that it will be useful, but WITHOUT ANY | ||||||
|  | #  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||
|  | #  FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for | ||||||
|  | #  more details. | ||||||
|  | # | ||||||
|  | #  You should have received a copy of the GNU Affero General Public License | ||||||
|  | #  along with Rattail.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  | # | ||||||
|  | ################################################################################ | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | ``rattail.pyramid.grids`` -- Grids | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | from rattail.pyramid.grids.search import * | ||||||
							
								
								
									
										41
									
								
								rattail/pyramid/grids/search.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								rattail/pyramid/grids/search.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | ||||||
|  | #!/usr/bin/env python | ||||||
|  | # -*- coding: utf-8  -*- | ||||||
|  | ################################################################################ | ||||||
|  | # | ||||||
|  | #  Rattail -- Retail Software Framework | ||||||
|  | #  Copyright © 2010-2012 Lance Edgar | ||||||
|  | # | ||||||
|  | #  This file is part of Rattail. | ||||||
|  | # | ||||||
|  | #  Rattail is free software: you can redistribute it and/or modify it under the | ||||||
|  | #  terms of the GNU Affero General Public License as published by the Free | ||||||
|  | #  Software Foundation, either version 3 of the License, or (at your option) | ||||||
|  | #  any later version. | ||||||
|  | # | ||||||
|  | #  Rattail is distributed in the hope that it will be useful, but WITHOUT ANY | ||||||
|  | #  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||
|  | #  FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for | ||||||
|  | #  more details. | ||||||
|  | # | ||||||
|  | #  You should have received a copy of the GNU Affero General Public License | ||||||
|  | #  along with Rattail.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  | # | ||||||
|  | ################################################################################ | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | ``rattail.pyramid.grids.search`` -- Grid Search Filters | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | from webhelpers.html import tags | ||||||
|  | 
 | ||||||
|  | from edbob.pyramid.grids.search import SearchFilter | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def EnumSearchFilter(enum): | ||||||
|  |     options = enum.items() | ||||||
|  | 
 | ||||||
|  |     class EnumSearchFilter(SearchFilter): | ||||||
|  |         def value_control(self): | ||||||
|  |             return tags.select(self.name, self.search.config.get(self.name), options) | ||||||
|  | 
 | ||||||
|  |     return EnumSearchFilter | ||||||
|  | @ -29,10 +29,11 @@ | ||||||
| from sqlalchemy import and_ | from sqlalchemy import and_ | ||||||
| 
 | 
 | ||||||
| import edbob | import edbob | ||||||
| from edbob.pyramid.forms import AssociationProxyField | from edbob.pyramid.forms import AssociationProxyField, EnumFieldRenderer | ||||||
| from edbob.pyramid.views import SearchableAlchemyGridView | from edbob.pyramid.views import SearchableAlchemyGridView | ||||||
| 
 | 
 | ||||||
| import rattail | import rattail | ||||||
|  | from rattail.pyramid.grids import EnumSearchFilter | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class EmployeesGrid(SearchableAlchemyGridView): | class EmployeesGrid(SearchableAlchemyGridView): | ||||||
|  | @ -50,18 +51,30 @@ class EmployeesGrid(SearchableAlchemyGridView): | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|     def filter_map(self): |     def filter_map(self): | ||||||
|         return self.make_filter_map( |         kwargs = dict( | ||||||
|             first_name=self.filter_ilike(edbob.Person.first_name), |             first_name=self.filter_ilike(edbob.Person.first_name), | ||||||
|             last_name=self.filter_ilike(edbob.Person.last_name), |             last_name=self.filter_ilike(edbob.Person.last_name), | ||||||
|             phone=self.filter_ilike(rattail.EmployeePhoneNumber.number)) |             phone=self.filter_ilike(rattail.EmployeePhoneNumber.number)) | ||||||
|  |         if self.request.has_perm('employees.edit'): | ||||||
|  |             kwargs.update(dict( | ||||||
|  |                     exact=['id', 'status'])) | ||||||
|  |         return self.make_filter_map(**kwargs) | ||||||
| 
 | 
 | ||||||
|     def filter_config(self): |     def filter_config(self): | ||||||
|         return self.make_filter_config( |         kwargs = dict( | ||||||
|             include_filter_first_name=True, |             include_filter_first_name=True, | ||||||
|             filter_type_first_name='lk', |             filter_type_first_name='lk', | ||||||
|             include_filter_last_name=True, |             include_filter_last_name=True, | ||||||
|             filter_type_last_name='lk', |             filter_type_last_name='lk', | ||||||
|             filter_label_phone="Phone Number") |             filter_label_phone="Phone Number") | ||||||
|  |         if self.request.has_perm('employees.edit'): | ||||||
|  |             kwargs.update(dict( | ||||||
|  |                     filter_label_id="ID", | ||||||
|  |                     include_filter_status=True, | ||||||
|  |                     filter_type_status='is', | ||||||
|  |                     filter_factory_status=EnumSearchFilter(rattail.EMPLOYEE_STATUS), | ||||||
|  |                     status=rattail.EMPLOYEE_STATUS_CURRENT)) | ||||||
|  |         return self.make_filter_config(**kwargs) | ||||||
| 
 | 
 | ||||||
|     def sort_map(self): |     def sort_map(self): | ||||||
|         return self.make_sort_map( |         return self.make_sort_map( | ||||||
|  | @ -82,11 +95,16 @@ class EmployeesGrid(SearchableAlchemyGridView): | ||||||
|         g.append(AssociationProxyField('last_name')) |         g.append(AssociationProxyField('last_name')) | ||||||
|         g.configure( |         g.configure( | ||||||
|             include=[ |             include=[ | ||||||
|  |                 g.id.label("ID"), | ||||||
|                 g.first_name, |                 g.first_name, | ||||||
|                 g.last_name, |                 g.last_name, | ||||||
|                 g.phone.label("Phone Number"), |                 g.phone.label("Phone Number"), | ||||||
|  |                 g.status.with_renderer(EnumFieldRenderer(rattail.EMPLOYEE_STATUS)), | ||||||
|                 ], |                 ], | ||||||
|             readonly=True) |             readonly=True) | ||||||
|  |         if not self.request.has_perm('employees.edit'): | ||||||
|  |             del g.id | ||||||
|  |             del g.status | ||||||
|         return g |         return g | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar