def create(user): email = user.email existing_user = index_api.get_one(User, 'email', email) if existing_user: raise DuplicateDataError("User with email '%s' already exists!" % (email)) return data_api.add(user)
def create(article): link = article.link existing_article = index_api.get_one(Article, 'link', link) if existing_article: raise DuplicateDataError("Article with link '%s' already exists!" % (link)) return data_api.add(article)
def create(company): name = company.name existing_company = index_api.get_one(Company, 'name', name) if existing_company: raise DuplicateDataError("Company with name '%s' already exists!" % (name)) return data_api.add(company)
def create(user_subscription): user_id = user_subscription.user_id existing_user_subscription = index_api.get_one(UserSubscription, 'user_id', user_id, is_list=False) if existing_user_subscription: raise DuplicateDataError( "User subscription for user '%s' already exists!" % (user_id)) return data_api.add(user_subscription)
def create(user_bucket): user_id = user_bucket.user_id existing_user_bucket = index_api.get_one(UserBucket, 'user_id', user_id, is_list=False) if existing_user_bucket: raise DuplicateDataError( "User bucket for user '%s' already exists!" % (user_id)) return data_api.add(user_bucket)