Source

DJFacet / demoproject / facetspecs.py

Full commit
from religions.models import *



##################
#  
#  RESULT_TYPES and FACET_GROUPS
#
##################



facetslist = []




#	label = interface name / uniquename = internal name / infospace: a Model or a QuerySet instance
result_types	 = [{	'label' : 'Religions', 
						'uniquename' : 'religions', 
						'infospace' : Religion	,
						'isdefault' : True
						   },
						
					 {	'label' : 'Countries', 
						'uniquename' : 'country',  
						'infospace' : Country,
							},

					]
			 

facet_groups =		[{	'label':	'Place facets', 
						'position': 1,
						'uniquename' :	'countrygroup', 
						'default' : True  , 
						'bkcolor' : 'FFEEFF' } ,
						
					{	'label':	'Religion facets', 
						'position': 2,
						'uniquename' :	'religiongroup', 
						'default' : True   ,
						'bkcolor' : "EEFFFF"} ,
					]






##################
#  
#  FACETS
#
##################


facetslist +=	[ 

			{	'appearance' : {'label' : 'Region name' , 
								'uniquename' : 'regionname',
								'model' : Region , 
								'dbfield' : "name", 
								'displayfield' : "name", 
								'explanation': "no explanation yet", # TODO: add explanations to all of them!
								'grouping'	: ['countrygroup'],
								'ordering' : 'name',
								# 'hierarchy' : {'alpha': True, }, 
								} ,
				'behaviour' :  [{'resulttype' : 'religions',
								 'querypath' : 'country__inregion__name', 
								 'inversepath' : None,
								 'explanation' : "showing all...." },
								{'resulttype' : 'country',
								 'querypath' : 'inregion__name', 
								 'inversepath' : None,
								 'explanation' : "showing all...." },
								]
						 },
									


			{	'appearance' : {'label' : 'Region idbname' , 
								'uniquename' : 'regionidbname',
								'model' : Region , 
								'dbfield' : "idbname", 
								'displayfield' : "idbname", 
								'explanation': "no explanation yet", # TODO: add explanations to all of them!
								'grouping'	: ['countrygroup'],
								'ordering' : 'idbname',
								# 'hierarchy' : {'alpha': True, }, 
								} ,
				'behaviour' :  [{'resulttype' : 'religions',
								 'querypath' : 'country__inregion__idbname', 
								 'inversepath' : None,
								 'explanation' : "showing all...." },
								{'resulttype' : 'country',
								 'querypath' : 'inregion__idbname', 
								 'inversepath' : None,
								 'explanation' : "showing all...." },
								]
						 },

			{	'appearance' : {'label' : 'Country name' , 
								'uniquename' : 'countryname',
								'model' : Country , 
								'dbfield' : "name", 
								'displayfield' : "name", 
								'explanation': "no explanation yet", # TODO: add explanations to all of them!
								'grouping'	: ['countrygroup'],
								'ordering' : 'name',
								# 'hierarchy' : {'alpha': True, }, 
								} ,
				'behaviour' :  [{'resulttype' : 'religions',
								 'querypath' : 'country__name', 
								 'inversepath' : None,
								 'explanation' : "showing all...." },
								
								# NOTE THAT THIS FACET WILL NOT WORK WITH COUNTRIES!
								# ...if it did.. it could look like this:
								
								# {'resulttype' : 'country',
								#  'querypath' : 'name', 
								#  'inversepath' : None,
								#  'explanation' : "showing all...." },
								]
						 },
						
						
				# THIS IS AN MPTT/HIERARCHICAL FACET		

				{	'appearance' : {'label' : 'Religion name' , 
									'uniquename' : 'religionname',
									'model' : Religion , 
									'dbfield' : "name", 
									'displayfield' : "name", 
									'explanation': "no explanation yet", # TODO: add explanations to all of them!
									'grouping'	: ['religiongroup'],
									'ordering' : 'name',
									'mptt' : True
									# 'hierarchy' : {'alpha': True, }, 
									} ,
					'behaviour' :  [{'resulttype' : 'religions',
									 'querypath' : 'name', 
									 'inversepath' : None,
									 'explanation' : "showing all...." },
									{'resulttype' : 'country',
									 'querypath' : 'religions__name', 
									 'inversepath' : None,
									 'explanation' : "showing all...." },
									]
							 },



				# NOW LET'S DEFINE A CUSTOM FACET (NOT WORKING YET):

				# {	'appearance' : {'label' : 'My Religions' , 
				# 					'uniquename' : 'myreligions',
				# 					'model' : Religion , 
				# 					'dbfield' : "name", 
				# 					'displayfield' : "name", 
				# 					'explanation': "no explanation yet", # TODO: add explanations to all of them!
				# 					'grouping'	: ['religiongroup'],
				# 					'ordering' : 'name',
				# 					'customvalues' :	{
				# 						'religions I am interested in' : 
				# 							{'id__in' : [172, 158, 48],},
				# 						'religions I already know' : 
				# 							{'id__in' : [54, 59],} 
				# 							}
				# 				   } ,
				# 				
				# 	'behaviour' :  [{'resulttype' : 'religions',
				# 					 'querypath' : 'name', 
				# 					 'inversepath' : None,
				# 					 'explanation' : "showing all...." },
				# 					{'resulttype' : 'country',
				# 					 'querypath' : 'religions__name', 
				# 					 'inversepath' : None,
				# 					 'explanation' : "showing all...." },
				# 					]
				# 			 },		
		
		
						
						#	end of facet_list
								]






##################
#  2010-07-29
#  how to use the specs format: 
#
##################





# { 'label' : 'person name' ,	==>	 THE LABEL DISPLAYED ON THE FACET PANEL
#  'uniquename' :	'troupegroup',	 ==> a unique name used for internal purposes
#	'model' : Person ,		==> THE MAIN MODEL WE GET THE FACET VALUES FROM 
#	'displayfield' : "pretty_name",	 ==> THE MODEL ATTR USED FOR DISPLAYING FACET VALUES
#	'dbfield' : "name",	  ==> THE MODEL ATTR USED FOR GETTING THE ACTUAL FACET VALUES. IMP: THIS IS ALSO USED FOR BEHAVIOUR WHEN THIS 
#							  IS LEFT BLANK BELOW, EG WHEN THE RESULT TYPE MODEL IS EQUAL TO FACET MODEL 
#	'explanation': "some explanation", ==> SOME EXPLANATION OF THE FACET AS A WHOLE
#	'grouping'	: ['documentgroup'], ==> WHAT GROUP THE FACET GOES INTO IN THE INTERFACE
#	'hierarchy' : {'alpha': True, },	==> IF WE WANT FACET VALUES TO BE ORDERED HIERARCHICALLY
#	 'mask'	  :	   TODO
#  'behaviour' : [ {'resulttype' : 'people',  ==> FOR EACH RESULT TYPE (REFERENCED VIA UNIQUENAMES) PASS THE DJANGO QUERY-PATH AS A STRING
#				   'querypath' : "",	 ===> if expressed as a tuple ('path1', 'path2') it is transformed into an OR
#					'inversepath' : None, ===> if None, the inverse path is calculated automatically
										# ====> if "string" or ("tuple",) it is passed as it is....
#										 ===> if {"GENERIC" : True}, means that the result type in question is the owner of the facet property
#												(although in some case the facet is calculated based on another one) 
#												eg 'revision' or 'edited record' fields, which are present on all Models
#				 'explanation' : "showing all people with selected surname " } , ==> AN EXPLANATION OF THE QUERY
#				{'resulttype' : 'people', 
#				 'querypath' : "",
#				 'inversepath' : None, ===> if None, the inverse path is calculated
#				 'explanation' : "showing all people with selected surname " }
#				]
#			 },