def put(email, name, user_key=None): """Método atualiza um marketplace para o usuário informado através do email.""" # Selecionando key do usuário if user_key is None: user_key = user.user_key(email) logging.debug('Criando/atualizando marketplace (loja) para o usuário %s', email) # Selecionando a marketplace (loja) do usuário marketplaceModel = MarketplaceModel.query(ancestor=user_key).get() # Caso exista, obter o atual if marketplaceModel is None: marketplaceModel = MarketplaceModel(parent=user_key) # Atualizar o nome marketplaceModel.name = name logging.debug('Persistindo no Datastore...') # Persistir a entity marketplaceModel.put() logging.debug('Persistido com sucesso!') # Retornando marketplace (loja) persistida return marketplaceModel
def get(email): """ Get marketplace model by user email. """ # Set memcache key memcache_key = 'email.marktplace.%s' % email # Verify if user marktplace is cached marketplace_cached = memcache.get(memcache_key) # and return cached marketplace if marketplace_cached is not None: logging.debug("Marketplace cached for %s user. Return it.", email) return marketplace_cached # else, query or add new one... # Create user key as parent user_key = user.user_key(email) # Select user marketplace marketplaceModel = MarketplaceModel.query(ancestor=user_key).get() # If not present, create new one if marketplaceModel is None: marketplaceModel = put(email=email, name='Nova Loja', user_key=user_key) logging.debug("Marketplace create sucessfully for %s user", email) # Add to memcache memcache.add(key=memcache_key, value=marketplaceModel, time=3600 * 24) logging.debug("Marketplace cached for %s user", email) # Return marketplace return marketplaceModel
def get(email): """Método retorna um marketplace para o usuário informado através do email. Caso o mesmo não exista, um novo é criado.""" # Selecionando key do usuário user_key = user.user_key(email) # Selecionando a marketplace (loja) do usuário marketplaceModel = MarketplaceModel.query(ancestor=user_key).get() # Caso ainda não exista, uma nova marketplace (loja) é criada para o usuário if marketplaceModel is None: marketplaceModel = put(email=email, name='Nova Loja', user_key=user_key) logging.debug(marketplaceModel) # Criando mensagem de retorno para o endpoint return marketplaceModel
def put(email, name, user_key=None): """ Save a marketplace in the Datastore. """ if user_key is None: user_key = user.user_key(email) marketplaceModel = MarketplaceModel.query(ancestor=user_key).get() if marketplaceModel is None: marketplaceModel = MarketplaceModel(parent=user_key) marketplaceModel.name = name marketplaceModel.put() logging.debug(' Created successfuly marketplace to user %s', email) return marketplaceModel
def put(email, name, user_key=None): """ Save a marketplace in the Datastore. """ if user_key is None: user_key = user.user_key(email) marketplaceModel = MarketplaceModel.query(ancestor=user_key).get() if marketplaceModel is None: marketplaceModel = MarketplaceModel(parent=user_key) marketplaceModel.name = name marketplaceModel.put() logging.debug( ' Created successfuly marketplace to user %s', email) return marketplaceModel