def _get_group(group_name, group_lookup, school_urlsafe): """Return a group for the group name passed in. Checks the group cache first if not there then queries by the lower case name. If not there then creates a new group. """ #check for existing group by name if group_name.lower() in group_lookup: logging.debug("group found in cache") error = "group found in cache" create_error_log(error, 'ERR') return group_lookup[group_name.lower()], None from .group import Group school_key = ndb.Key(urlsafe=school_urlsafe) group = Group.query(Group.name_ == group_name, Group.school == school_key, namespace='_x_').get() if group: logging.debug("group found in datastore") error = "group found in datastore" create_error_log(error, 'ERR') group_lookup[group_name.lower()] = group.key return group.key, None logging.debug("No group found for %s, creating a new one", group_name) group = Group(name=group_name) school_key = ndb.Key(urlsafe=school_urlsafe) group.school = school_key future = group.put_async() return group.key, future
def _get_group(group_name, group_lookup, school_urlsafe): """Return a group for the group name passed in. Checks the group cache first if not there then queries by the lower case name. If not there then creates a new group. """ #check for existing group by name if group_name.lower() in group_lookup: logging.debug("group found in cache") error = "group found in cache" create_error_log(error, 'ERR') return group_lookup[group_name.lower()], None from .group import Group school_key = ndb.Key(urlsafe = school_urlsafe) group = Group.query(Group.name_ == group_name, Group.school == school_key, namespace = '_x_').get() if group: logging.debug("group found in datastore") error = "group found in datastore" create_error_log(error, 'ERR') group_lookup[group_name.lower()] = group.key return group.key, None logging.debug("No group found for %s, creating a new one", group_name) group = Group(name=group_name) school_key = ndb.Key(urlsafe = school_urlsafe) group.school = school_key future = group.put_async() return group.key, future