def _new_subscription_record(userId, subscription_id, subscription_key, subscription_type, inobj): our_result = Subscription(subscription_id=subscription_id, userId=userId, subscription_key=subscription_key, subscription_type=subscription_type) our_result.update(inobj) return our_result
def add(userId, subscription_key, subscription_type, inobj, session=None): if not session: session = db.Session # prep the input object if not inobj: inobj = {} subscription_id = hashlib.md5('+'.join( [userId, subscription_key, subscription_type]).encode('utf-8')).hexdigest() inobj['subscription_id'] = subscription_id inobj.pop('userId', None) inobj.pop('last_updated', None) inobj.pop('created_at', None) our_result = session.query(Subscription).filter_by( subscription_id=subscription_id, userId=userId, subscription_key=subscription_key, subscription_type=subscription_type).first() if not our_result: our_result = Subscription(subscription_id=subscription_id, userId=userId, subscription_key=subscription_key, subscription_type=subscription_type) our_result.update(inobj) session.add(our_result) else: our_result.update(inobj) return (True)