def project_activity_year_options():
 db = current.db
 table = current.s3db.project_activity
 query = (table.deleted == False)
 min_field = table.date.min()
 start_date_min = db(query).select(min_field, orderby=min_field, limitby=(0, 1)).first()[min_field]
 if start_date_min:
  start_year = start_date_min.year
 else:
  start_year = None
 max_field = table.end_date.max()
 end_date_max = db(query).select(max_field, orderby=max_field, limitby=(0, 1)).first()[max_field]
 if end_date_max:
  end_year = end_date_max.year
 else:
  end_year = None
 if ((not start_year) or (not end_year)):
  return ({start_year: start_year} or {end_year: end_year})
 years = {}
 for year in xrange(start_year, (end_year + 1)):
  years[year] = year
 return years

def project_activity_year_options ( ) : db = current . db table = current . s3db . project_activity query = ( table . deleted == False ) min_field = table . date . min ( ) start_date_min = db ( query ) . select ( min_field , orderby = min_field , limitby = ( 0 , 1 ) ) . first ( ) [ min_field ] if start_date_min : start_year = start_date_min . year else : start_year = None max_field = table . end_date . max ( ) end_date_max = db ( query ) . select ( max_field , orderby = max_field , limitby = ( 0 , 1 ) ) . first ( ) [ max_field ] if end_date_max : end_year = end_date_max . year else : end_year = None if ( ( not start_year ) or ( not end_year ) ) : return ( { start_year : start_year } or { end_year : end_year } ) years = { } for year in xrange ( start_year , ( end_year + 1 ) ) : years [ year ] = year return years
returns a dict of the options for the year virtual field used by the search widget orderby needed for postgres @todo: migrate to stats_year_options() .