Example #1
0
	def updateGood(self, good_key, json):
		session = models.getSession()
		good = session.query(models.Good).filter_by(key=good_key).first()
		if good:
			models.updateObjectWithJSON(good, json, ['key', 'application_key'])
			session.commit()
		return good
Example #2
0
	def setApplication(self, application_key, json):
		session = models.getSession()
		application = session.query(models.Application).filter_by(key=application_key).first()
		if application:
			models.updateObjectWithJSON(application, json, ['key'])
			session.commit()
		return application
Example #3
0
	def setABTest(self, application_key, json):
		session = models.getSession()

		abtest = self.getABTest(application_key)

		if abtest:

			newABTest = models.ABTest()
			newABTest.application_key = abtest.application_key
			newABTest.countryWhiteList = abtest.countryWhiteList
			newABTest.countryBlackList = abtest.countryBlackList
			newABTest.modulus = abtest.modulus
			newABTest.modulusLimit = abtest.modulusLimit
			newABTest.groupAPrices_key = abtest.groupAPrices_key
			newABTest.groupBPrices_key = abtest.groupBPrices_key

			# Check price foreign keys manually
			for prices in ['groupAPrices_key', 'groupBPrices_key']:
				if prices in json and json[prices] != None:
					count = session.query(models.Prices).join(models.Application).filter(models.Application.key == newABTest.application_key).filter(models.Prices.key==json[prices]).count()
					if count == 1:
						pass
					else:
						del json[prices]
			
			models.updateObjectWithJSON(newABTest, json, ['key'])
			session.add(newABTest)
			session.commit()

			return newABTest 
Example #4
0
	def setCurrency(self, application_key, json):
		session = models.getSession()
		currencies = session.query(models.Currencies).join(models.Application).filter_by(key=application_key).first()

		if currencies:
			models.updateObjectWithJSON(currencies, json, ['key'])
			session.commit()
		return currencies
Example #5
0
	def setMetrics(self, application_key, json):
		session = models.getSession()

		metrics = session.query(models.Metrics).join(models.Application).filter(models.Application.key == application_key).first()
		if metrics:
			models.updateObjectWithJSON(metrics, json, ['key'])
			session.commit()
		return metrics 
Example #6
0
    def updateGood(self, good_key, json):
        session = models.getSession()
        good = session.query(models.Good).filter_by(key=good_key).first()
        if good:
            models.updateObjectWithJSON(good, json, ['key', 'application_key'])
            session.commit()

        cacheObject(good)
        session.close()

        return good
Example #7
0
    def setApplication(self, application_key, json):
        session = models.getSession()
        application = session.query(
            models.Application).filter_by(key=application_key).first()
        if application:
            models.updateObjectWithJSON(application, json, ['key'])
            session.commit()

        cacheObject(application)
        session.close()

        return application
Example #8
0
    def setCurrency(self, application_key, json):
        session = models.getSession()
        currencies = session.query(models.Currencies).join(
            models.Application).filter_by(key=application_key).first()

        if currencies:
            models.updateObjectWithJSON(currencies, json, ['key'])
            session.commit()

        cacheObject(currencies)
        session.close()

        return currencies
Example #9
0
    def setMetrics(self, application_key, json):
        session = models.getSession()

        metrics = session.query(models.Metrics).join(
            models.Application).filter(
                models.Application.key == application_key).first()
        if metrics:
            models.updateObjectWithJSON(metrics, json, ['key'])
            session.commit()
            cacheObject(metrics)

        session.close()

        return metrics
Example #10
0
    def setABTest(self, application_key, json):
        session = models.getSession()

        abtest = self.getABTest(application_key)

        if abtest:

            newABTest = models.ABTest()
            newABTest.application_key = abtest.application_key
            newABTest.countryWhiteList = abtest.countryWhiteList
            newABTest.countryBlackList = abtest.countryBlackList
            newABTest.modulus = abtest.modulus
            newABTest.modulusLimit = abtest.modulusLimit
            newABTest.groupAPrices_key = abtest.groupAPrices_key
            newABTest.groupBPrices_key = abtest.groupBPrices_key

            # Check price foreign keys manually
            for prices in ['groupAPrices_key', 'groupBPrices_key']:
                if prices in json and json[prices] != None:
                    count = session.query(models.Prices).join(
                        models.Application).filter(
                            models.Application.key == newABTest.application_key
                        ).filter(models.Prices.key == json[prices]).count()
                    if count == 1:
                        pass
                    else:
                        del json[prices]

            models.updateObjectWithJSON(newABTest, json, ['key'])
            session.add(newABTest)
            session.commit()

            cacheObject(newABTest)

        session.close()

        return newABTest