def choices_from_db(force_reload=False): global BACKGROUND_IMAGES if (BACKGROUND_IMAGES is None) or force_reload: from ui.image import Image objs = Image.gql("WHERE role = :1", "attribute").fetch(MAX_COUNT) BACKGROUND_IMAGES = sorted(map(lambda x: x.name.split("/")[1], objs)) return BACKGROUND_IMAGES
def populars_from_db(): global POPULAR_IMAGES if POPULAR_IMAGES is None: from ui.image import Image objs = Image.gql("WHERE role = :1", "popular").fetch(MAX_COUNT) POPULAR_IMAGES = sorted(map(lambda x: x.name.split("/")[1], objs)) return POPULAR_IMAGES
def send_img(name, role): filename = IMG_PATH + name name = name[:-4] logging.debug("try to send %s" % name) img = Image.gql("WHERE name = :1", name).get() if img is not None: logging.info("image %s exists" % name) return False try: f = open(filename, 'r') except IOError: logging.info("missing file %s" % name) return False data = f.read() f.close() image = Image() image.name = name image.data = db.Blob(data) image.role = role image.put() logging.debug("sent ok") return True