Esempio n. 1
0
	def createGenericModels(self):
		if self.isValidRequest():
			self.generic_models = {}
			if self.format == "JSON" and self.requestObj != None:
				decoder = json.JSONDecoder()
				for select in self.requestObj["selects"]:
					name = select["name"]
					cols = select["cols"]
					lbl = select["label"]
					#gm = GenericModel(name, cols)
					gm = DjangoModel(name, cols)
					j = self.requestObj["joins"]
					for clause in j:
						for key in clause.keys():
							if key != "op":
								if lbl == key.split('.')[0]:
									gm.addFilter( key.split('.')[1], clause["op"], clause[key])
									break

					self.generic_models[lbl] = gm
		return self.generic_models
Esempio n. 2
0
from djangomodel import DjangoModel
import json

locations = DjangoModel("sweetspot.models.Locations", ["locationCode"])
locations.addFilter("locationCode", "eq", "P-004958")
signs = DjangoModel("sweetspot.models.Signs", ["locationCode"])
signs.addFilter("FtFromCurb", "in", [9, 30])
#signs.addFilter("locationCode", "eq", "P-004958")
all = {locations.getModelName().lower():locations, signs.getModelName().lower():signs}

modelIsChanging = True
encoder = json.JSONEncoder();
while modelIsChanging:
	print "Model is changing"
	modelIsChanging = False
	for modelname in all.keys():
		print "Start filtering"
		poppedModel = all[modelname]
		if poppedModel.applyFilter():
			print "Filter applied for ", poppedModel.getModelName()
			modelIsChanging = False
			if poppedModel.dataWasFiltered(): 
				print "Data was filtered for ", poppedModel.getModelName()
				modelIsChanging = True
				related_models = poppedModel.getRelatedModelNames()
				for related_model in related_models:
					related_model_name = related_model.get_accessor_name()[:(len(related_model.get_accessor_name()) - 4)]
					if related_model_name in all.keys():
						x = all[related_model_name]
						x.applyFKs(modelname, poppedModel.getPKs())
					else: