def persist(self, playground, user_info): key = None if playground is not None: curr_playground = None if playground.key is not None: curr_playground = self.get_record(playground.key.id()) #If entry exists for the same playground, udpate the data if curr_playground is not None: self.copy_playground_model(curr_playground, playground) curr_playground.updated_by = user_info.key # change the status to pending approval after every edit, unless the current user is an admin if not user_has_role(user_info, 'admin'): curr_playground.status = 1 #pending_approval status if not user_info.key in curr_playground.owners: curr_playground.owners.append(user_info.key) key = curr_playground.put() else: #create a new playground playground.status = 0 #pending_creation status playground.created_by = user_info.key playground.updated_by = user_info.key playground.review_stats = ReviewStats() playground.review_stats.reviews_count = 0 playground.review_stats.ratings_count = 0 if not user_has_role(user_info, 'admin'): playground.owners = [] playground.owners.append(user_info.key) key = playground.put() logger.debug("Playground persisted in datastore, %s " % key) if key is not None: self.update_search_index(key.id(), playground) #TODO: Make sure all the caches that has this entity is deleted here mc_delete(cache_keys.get_playground_cache_key(key.id())) return key
def persist(self, match, user_info): key = None if match is not None: curr_match = None if match.key is not None: curr_match = self.get_record(match.key.id()) #If entry exists for the same match, udpate the data if curr_match is not None: self.copy_match_model(curr_match, match) match.playground_id = None curr_match.updated_by = user_info.key # change the status to pending approval after every edit, unless the current user is an admin if not user_has_role(user_info, 'admin'): curr_match.status = 1 #pending_approval status if not user_info.key in curr_match.owners: curr_match.owners.append(user_info.key) key = curr_match.put() else: #create a new match match.status = 0 #pending_creation status match.created_by = user_info.key match.updated_by = user_info.key match.playground_id = None if not user_has_role(user_info, 'admin'): match.owners = [] match.owners.append(user_info.key) key = match.put() if key is not None: mc_delete(cache_keys.get_match_cache_key(key.id())) return key
def persist(self, childevent, user_info): key = None if childevent is not None: curr_childevent = None if childevent.key is not None: curr_childevent = self.get_record(childevent.key.id()) #If entry exists for the same childevent, udpate the data if curr_childevent is not None: self.copy_childevent_model(curr_childevent, childevent) curr_childevent.modified_by = user_info.key # change the status to pending approval after every edit, unless the current user is an admin if not user_has_role(user_info, 'admin'): curr_childevent.status = 1 #pending_approval status if not user_info.key in curr_childevent.owners: curr_childevent.owners.append(user_info.key) key = curr_childevent.put() else: childevent.status = 0 #pending_creation status childevent.created_by = user_info.key childevent.modified_by = user_info.key if not user_has_role(user_info, 'admin'): childevent.owners = [] childevent.owners.append(user_info.key) key = childevent.put() if key is not None: mc_delete(get_childevent_cache_key(key.id())) return key
def persist(self, business, user_info): key = None if business is not None: curr_business = None if business.key is not None: curr_business = self.get_record(business.key.id()) #If entry exists for the same business, udpate the data if curr_business is not None: self.copy_business_model(curr_business, business) curr_business.modified_by = user_info.key # change the status to pending approval after every edit, unless the current user is an admin if not user_has_role(user_info, 'admin'): curr_business.status = 1 #pending_approval status if not user_info.key in curr_business.owners: curr_business.owners.append(user_info.key) key = curr_business.put() else: business.status = 0 #pending_creation status business.created_by = user_info.key business.modified_by = user_info.key if not user_has_role(user_info, 'admin'): business.owners = [] business.owners.append(user_info.key) key = business.put() if key is not None: mc_delete(get_business_cache_key(key.id())) return key
def persist(self, team, user_info): key = None if team is not None: curr_team = None if team.key is not None: curr_team = self.get_record(team.key.id()) #If entry exists for the same team, udpate the data if curr_team is not None: self.copy_team_model(curr_team, team) curr_team.updated_by = user_info.key # change the status to pending approval after every edit, unless the current user is an admin if not user_has_role(user_info, 'admin'): curr_team.status = 1 #pending_approval status if not user_info.key in curr_team.owners: curr_team.owners.append(user_info.key) key = curr_team.put() else: #create a new team team.status = 0 #pending_creation status team.created_by = user_info.key team.updated_by = user_info.key if not user_has_role(user_info, 'admin'): team.owners = [] team.owners.append(user_info.key) key = team.put() if key is not None: mc_delete(cache_keys.get_team_cache_key(key.id())) return key
def persist(self, player, user_info): key = None if player is not None: curr_player = None if player.key is not None: curr_player = self.get_record(player.key.id()) #If entry exists for the same player, udpate the data if curr_player is not None: self.copy_player_model(curr_player, player) curr_player.updated_by = user_info.key # change the status to pending approval after every edit, unless the current user is an admin if not user_has_role(user_info, 'admin'): curr_player.status = 1 #pending_approval status if not user_info.key in curr_player.owners: curr_player.owners.append(user_info.key) key = curr_player.put() else: #create a new player if player.name != '': player.status = 0 #pending_creation status player.created_by = user_info.key player.updated_by = user_info.key if not user_has_role(user_info, 'admin'): player.owners = [] player.owners.append(user_info.key) key = player.put() if key is not None: mc_delete(cache_keys.get_player_cache_key(key.id())) return key
def persist(self, bulkdata, user_info): key = None if bulkdata is not None: curr_bulkdata = None if bulkdata.key is not None: curr_bulkdata = self.get_record(bulkdata.key.id()) #If entry exists for the same bulkdata, udpate the data if curr_bulkdata is not None: #self.copy_bulkdata_model(curr_bulkdata, bulkdata) curr_bulkdata.updated_by = user_info.key # change the status to pending approval after every edit, unless the current user is an admin if not user_has_role(user_info, 'admin'): curr_bulkdata.status = 1 #pending_approval status if not user_info.key in curr_bulkdata.owners: curr_bulkdata.owners.append(user_info.key) key = curr_bulkdata.put() else: #create a new bulkdata bulkdata.created_by = user_info.key bulkdata.updated_by = user_info.key key = bulkdata.put() logger.debug("Bulkdata persisted in datastore, %s " % key) if key is not None: #TODO: Make sure all the caches that has this entity is deleted here mc_delete(cache_keys.get_bulkdata_cache_key(key.id())) return key
def status_change(self, event, user_info): key = None if event is not None: if event.key is not None: event.updated_by = user_info.key # change the status from current status if user_has_role(user_info, 'admin'): if event.status == 1: event.status += 1 #active status elif event.status == 2: event.status -= 1 #deactive status else: if event.status == 0: event.status += 1 #enable status else: event.status -= event.status #disable status key = event.put() if key is not None: #update the search index self.update_search_index(key.id(), event) #TODO: Make sure all the caches that has this entity is deleted here mc_delete(cache_keys.get_event_cache_key(key.id())) mc_delete(cache_keys.get_recent_event_cache_key()) mc_delete(cache_keys.get_ongoing_event_cache_key()) mc_delete(cache_keys.get_ongoing_future_event_cache_key()) mc_delete(cache_keys.get_upcoming_event_cache_key()) if event.featured: mc_delete(cache_keys.get_featured_event_cache_key()) return key
def query_by_owner(self, user, status='all'): logger.info('NdbPlaygroundDao:: DBHIT: query_by_owner for %s ' % user.email) owner_query = Playground.query() if not user_has_role(user, 'admin'): owner_query = Playground.query(ndb.OR(Playground.owners == user.key, Playground.created_by == user.key, Playground.updated_by == user.key)) if status != 'all': status_value = STATUS_DICT.get(status) owner_query = owner_query.filter(status == status_value) owner_query = owner_query.order(-Playground.updated_on) return owner_query.fetch()
def persist(self, event, user_info): key = None if event is not None: curr_event = None if event.key is not None: curr_event = self.get_record(event.key.id()) #If entry exists for the same event, udpate the data if curr_event is not None: self.copy_event_model(curr_event, event) event.parent_event_id = None curr_event.updated_by = user_info.key # change the status to pending approval after every edit, unless the current user is an admin if not user_has_role(user_info, 'admin'): curr_event.status = 1 #pending_approval status if not user_info.key in curr_event.owners: curr_event.owners.append(user_info.key) key = curr_event.put() else: # create a new event event.created_by = user_info.key event.updated_by = user_info.key event.parent_event_id = None if not user_has_role(user_info, 'admin'): event.owners = [] event.owners.append(user_info.key) event.status = 0 #pending_creation status else: event.status = 1 #pending_approval status key = event.put() if key is not None: #update the search index self.update_search_index(key.id(), event) #TODO: Make sure all the caches that has this entity is deleted here mc_delete(cache_keys.get_event_cache_key(key.id())) mc_delete(cache_keys.get_recent_event_cache_key()) mc_delete(cache_keys.get_ongoing_event_cache_key()) mc_delete(cache_keys.get_ongoing_future_event_cache_key()) mc_delete(cache_keys.get_upcoming_event_cache_key()) if event.featured: mc_delete(cache_keys.get_featured_event_cache_key()) return key
def query_by_owner(self, user, status='all', no_record=8): logger.info('NdbTeamDao:: DBHIT: query_by_owner for %s ' % user.email) owner_query = Team.query() if not user_has_role(user, 'admin'): owner_query = Team.query(ndb.OR(Team.owners == user.key, Team.created_by == user.key, Team.updated_by == user.key)) if status != 'all': status_value = STATUS_DICT.get(status) owner_query = owner_query.filter(status == status_value) owner_query = owner_query.order(-Team.updated_on) if no_record > -1: return list(owner_query.fetch(no_record)) else: #return all. simulating -1 for app engine return list(owner_query.fetch())
def status_change(self, playground, user_info): key = None if playground is not None: if playground.key is not None: playground.updated_by = user_info.key # change the status from current status if user_has_role(user_info, 'admin'): if playground.status == 1: playground.status += 1 #active status elif playground.status == 2: playground.status -= 1 #deactive status else: if playground.status == 0: playground.status += 1 #enable status else: playground.status -= playground.status #disable status key = playground.put() if key is not None: #update the search index self.update_search_index(key.id(), playground) mc_delete(cache_keys.get_playground_cache_key(key.id())) return key
def is_admin_user(self): if self.user_info: return utils.user_has_role(self.user_info, 'admin') return False
def is_business_user(self): if self.user_info: return utils.user_has_role(self.user_info, 'business') return False