def load_demo_explorations(cls): """Initializes the demo explorations.""" for index, exploration in enumerate(feconf.DEMO_EXPLORATIONS): assert len(exploration) in [3, 4], "Invalid format for demo exploration: %s" % exploration yaml_filename = "%s.yaml" % exploration[0] yaml_file = utils.get_file_contents(os.path.join(feconf.SAMPLE_EXPLORATIONS_DIR, yaml_filename)) title = exploration[1] category = exploration[2] image_filename = exploration[3] if len(exploration) == 4 else None image_id = None if image_filename: with open(os.path.join(feconf.SAMPLE_IMAGES_DIR, image_filename)) as f: raw_image = f.read() image_id = Image.create(raw_image) exploration = cls.create_from_yaml( yaml_file=yaml_file, user=None, title=title, category=category, exploration_id=str(index), image_id=image_id, ) exploration.is_public = True exploration.put()
def add_image(request, name): product_ = Product.get_by_id(name) if not product_: return render_json_response({'api_success':False, 'api_msg':'Product %s not found' % name}, status=400) if request.method == 'POST': try: upload_files = get_uploads(request, 'file') blob_info = upload_files[0] im = Image.create(blob_info.key(), title=product_.title) if not len(product_.images): im.is_master = True if im.get_cached_url(): product_.images.append(im) product_.put() api_upload_img_url = blobstore.create_upload_url( url_for('shop/admin/product/upload_img', name=product_.key.id())) return render_json_response( {'api_success':True, 'api_msg':'Image uploaded', 'api_upload_img_url':api_upload_img_url, 'img': im.to_json()}) else: return render_json_response( {'api_success':False, 'api_msg':'Invalid image'}) except Exception, e: return render_json_response( {'api_success':False, 'api_msg':str(e)}, status=400)
def post(self): """Saves an image uploaded by a content creator.""" raw = self.request.get('image') if raw: image_id = Image.create(raw) self.render_json({'image_id': image_id}) else: raise self.InvalidInputException('No image supplied')
def add(request): if request.method == 'POST': upload_files = get_uploads(request, 'file') blob_info = upload_files[0] im = Image.create(blob_info.key()) headers = {'Location': url_for('image/admin/upload', img_key=im.key())} else: headers = {'Location': url_for('image/admin/upload')} return Response(None, headers=headers, status=302)
def upload_image(request, id): union = Union.get_by_id(id) if not union: return render_json_response({"api": {"success": False, "msg": "Union %s not found" % id}}, status=400) if request.method == "POST": try: upload_files = get_uploads(request, "file") blob_info = upload_files[0] im = Image.create(blob_info.key(), title=union.title) if not len(union.images): im.is_master = True if im.get_cached_url(): union.images.append(im) union.put() return render_json_response({"api_success": True, "api_msg": "Image uploaded", "image": im.to_json()}) else: return render_json_response({"api_success": False, "api_msg": "Invalid image"}) except Exception, e: return render_json_response({"api_success": False, "api_msg": str(e)}, status=400)
def add_image(request, uid): category = Category.get_by_id(uid) if not category: return render_to_response('empty.html') if request.method == 'POST': try: upload_files = get_uploads(request, 'file') if len(upload_files): blob_info = upload_files[0] if blob_info.size: im = Image.create(blob_info.key(), title=category.title) if not len(category.images): im.is_master = True if im.get_cached_url(): category.images.append(im) category.put() return images(request, uid) else: blob_info.delete() except Exception, e: return render_to_response('empty.html', {'msg': msg})