# -*- coding: utf-8 -*-

import dabo.lib.datanav as datanav

class Base(datanav.Bizobj):

	def afterInit(self):
		super(Base, self).afterInit()
		self.setBaseSQL()


	def setBaseSQL(self):
		"""Hook for subclasses to set the base sql, using self.addField(), etc."""
		pass


	def addFieldsFromDataStructure(self):
		"""Call addField() for each field listed in self.DataStructure."""
		# The max_fill stuff has to do with getting the sql looking pretty, by
		# lining up the "as" keyword horizontally.
		max_fill = 0
		for field in self.DataStructure:
			fill = len("%s.%s" % (field[3], field[4]))
			max_fill = max(max_fill, fill)
		for field in self.DataStructure:
			fill = " " * (max_fill - len("%s.%s" % (field[3], field[4])))
			self.addField("%s.%s %sas %s" % (field[3], field[4], fill, field[0]))
