Beispiel #1
0
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)
Beispiel #2
0
def product_upload_image(key_id):
    product = Product.retrieve_by_id(key_id)
    if not product:
        return jsonify({"success": False, "msg": "Product id:%s not found" % key_id})

    upload_files = get_uploads(request, "image")
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size and ProductImage.is_image_type(blob_info.content_type):
            img = ProductImage.create(
                blob_info.key(),
                size=blob_info.size,
                filename=os.path.basename(blob_info.filename.replace("\\", "/")),
                content_type=blob_info.content_type,
            )
            if not len(product.images_list):
                img.is_master = True
            if img.get_cached_url():
                product.images_list.append(img)
                product.put()
        else:
            file_size = blob_info.size
            content_type = blob_info.content_type
            blob_info.delete()
            return jsonify(
                {"success": False, "msg": "Unknown error. File size: %s. File type: %s" % (file_size, content_type)}
            )
    else:
        return jsonify({"success": False, "msg": "Upload image not found."})
    return jsonify({"success": True, "msg": "Upload image complete."})
Beispiel #3
0
def upload_price():
    form = PriceFileForm()
    if request.method == 'POST' and form.validate_on_submit():
        upload_files = get_uploads(request, 'attach_file_')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size:
                price_file = PriceFile()
                form.populate_obj(price_file)
                file_ = File.create(
                    blob_info.key(),
                    size=blob_info.size,
                    filename=os.path.basename(blob_info.filename.replace('\\','/')),
                    content_type=blob_info.content_type,
                    is_public=True,
                    description = form.description.data
                )
                file_.put()
                price_file.file = file_.key
                price_file.put()
            else:
                blob_info.delete()
        return redirect(url_for('admin.price.index'))
    prices = PriceFile.query().order(-PriceFile.order_id)
    return render_template(
        'admin/price/index.html',
        prices=prices,
        form=form,
        upload_url=blobstore.create_upload_url(url_for('admin.price.upload_price'))
    )
Beispiel #4
0
def upload_resume(key_id):
    job = Job.retrieve_by_id(key_id)
    if not job or not job.is_public:
        return redirect(url_for('about.jobs'))
    form = ResumeForm()
    if request.method == 'POST' and form.validate_on_submit():
        resume = Resume()
        form.populate_obj(resume)
        resume.vacancy = job.key
        upload_files = get_uploads(request, 'attach_file_')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size:
                file_ = File.create(
                    blob_info.key(),
                    size=blob_info.size,
                    filename=os.path.basename(blob_info.filename.replace('\\','/')),
                    content_type=blob_info.content_type)
                file_.put()
                resume.attach_file = file_.key
            else:
                blob_info.delete()
        resume.put()
        return render_template('about/resume_thanks.html', html_class='about_class')
    upload_url = blobstore.create_upload_url(url_for('about.upload_resume', key_id=key_id))
    return render_template(
        'about/job.html',
        html_class='about_page',
        job=job,
        form=form,
        upload_url=upload_url,
        is_send_form=True
    )
Beispiel #5
0
def add_blob_content():

    response_object = {
      'status': 'success',
      'now': datetime.utcnow().isoformat(),
      'filelink': None,
    }

    folder = Folder.retrieve_by_id(3001)
    if not folder:
        response_object['status'] = 'failure'
        return util.jsonpify(response_object)
    upload_files = get_uploads(flask.request, 'file')
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size:
            f = File.create(
                blob_info.key(),
                size=blob_info.size,
                filename=os.path.basename(blob_info.filename.replace('\\','/')),
                content_type=blob_info.content_type)
            f.put()
            if f.get_cached_url():
                folder.files.append(f.key)
                folder.put()
                response_object['filelink'] = f.get_cached_url()
        else:
            blob_info.delete()
    return util.jsonpify(response_object)
Beispiel #6
0
def add_image(gallery_id):
    gallery = Gallery.get_by_id(gallery_id)
    if not gallery:
       return render_template('empty.html')
    image_form = AddImageForm()
    if image_form.validate_on_submit():
        upload_files = get_uploads(request, 'image')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size and GalleryImage.is_image_type(blob_info.content_type):
                img = GalleryImage.create(
                    blob_info.key(),
                    size=blob_info.size,
                    filename=os.path.basename(blob_info.filename.replace('\\','/')),
                    content_type=blob_info.content_type)
                if not len(gallery.images):
                    img.is_master = True
                if img.get_cached_url():
                    gallery.images.append(img)
                    gallery.put()
            else:
                blob_info.delete()
    else:
        return render_template('empty.html')
    return redirect(url_for('gallery.admin_edit', key_id=gallery_id))
Beispiel #7
0
def upload_price():
    form = PriceFileForm()
    if request.method == 'POST' and form.validate_on_submit():
        upload_files = get_uploads(request, 'attach_file_')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size:
                price_file = PriceFile()
                form.populate_obj(price_file)
                file_ = File.create(blob_info.key(),
                                    size=blob_info.size,
                                    filename=os.path.basename(
                                        blob_info.filename.replace('\\', '/')),
                                    content_type=blob_info.content_type,
                                    is_public=True,
                                    description=form.description.data)
                file_.put()
                price_file.file = file_.key
                price_file.put()
            else:
                blob_info.delete()
        return redirect(url_for('admin.price.index'))
    prices = PriceFile.query().order(-PriceFile.order_id)
    return render_template('admin/price/index.html',
                           prices=prices,
                           form=form,
                           upload_url=blobstore.create_upload_url(
                               url_for('admin.price.upload_price')))
Beispiel #8
0
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)
Beispiel #9
0
def employee_add():
    form = EmployeeForm(request.form)

    upload_files = get_uploads(request, 'photo_file')
    file_ = None
    if len(upload_files):
        blob_info = upload_files[0]
    else:
        blob_info = None

    if form.validate_on_submit():
        if blob_info:
            blob_info = blobstore.BlobInfo.get(blob_info.key())
            if blob_info.size:
                file_ = File.create(
                    blob_key=blob_info.key(),
                    title=form.name.data,
                    description=form.description.data,
                    is_public=form.is_public.data,
                    filename=os.path.basename(blob_info.filename.replace('\\', '/')),
                    size=blob_info.size,
                    content_type=blob_info.content_type)
                file_.put()
            else:
                blob_info.delete()

        employee = Employee()
        employee.name = form.name.data
        employee.post = form.post.data
        employee.description = form.description.data
        employee.is_public = form.is_public.data

        employee.telephone = form.telephone.data
        employee.telephone_m = form.telephone_m.data
        employee.email = form.email.data
        employee.icq = form.icq.data
        employee.skype = form.skype.data

        employee.country = form.country.data
        employee.city = form.city.data
        employee.address = form.address.data

        if file_:
            employee.photo_key = file_.key
        employee.put()
        return redirect(url_for('about.admins.employee'))

    else:
        if blob_info:
            blob_info.delete()

    add_url = blobstore.create_upload_url(url_for('about.admins.employee_add'))
    return render_template(
        'about/admins/employee/add.html',
        form=form,
        add_url=add_url
    )
Beispiel #10
0
def admin_add(request):
    if request.method == 'POST':
        upload_files = get_uploads(request, 'file')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size:
                image = GramPhoto.create(blob_info.key())
                image.put()
            else:
                blob_info.delete()
    return redirect(url_for('gram/admin/index'))
Beispiel #11
0
def price_uplader(request):
    upload_files = get_uploads(request, 'file')
    if not len(upload_files):
        return redirect(url_for('admin/add_price'))
    blob_info = upload_files[0]
    bl = BlobInfo.get(blob_info.key())
    filename = os.path.basename(bl.filename.replace('\\','/'))
    price = Price(name=filename,
        file_key=str(blob_info.key()), length=blob_info.size)
    price.put()
    return redirect(url_for('admin/prices'))
Beispiel #12
0
def employee_upload(key_id):
    employee = Employee.retrieve_by_id(key_id)
    if not employee:
        return redirect(url_for('about.admins.employee'))

    if 'delete_contact' in request.form:
        employee.key.delete()
        return redirect(url_for('about.admins.employee'))

    upload_files = get_uploads(request, 'photo_file')
    file_ = None
    if len(upload_files):
        blob_info = upload_files[0]
    else:
        blob_info = None

    form = EmployeeForm()
    if form.validate_on_submit():
        if blob_info:
            blob_info = blobstore.BlobInfo.get(blob_info.key())
            if blob_info.size:
                file_ = File.create(
                    blob_key=blob_info.key(),
                    title=form.name.data,
                    description=form.description.data,
                    is_public=form.is_public.data,
                    filename=os.path.basename(blob_info.filename.replace('\\', '/')),
                    size=blob_info.size,
                    content_type=blob_info.content_type)
                file_ = file_.put_async()
            else:
                blob_info.delete()

        form.populate_obj(employee)
        if employee.photo_key and file_:
            employee.photo_key.delete_async()
            employee.photo_key = file_.get_result()
        employee.put_async()
        return redirect(url_for('about.admins.employee'))
    else:
        if blob_info:
            blob_info.delete()

    edit_url = blobstore.create_upload_url(url_for('about.admins.employee_update', key_id=key_id))
    return render_template(
        'about/admins/employee/edit.html',
        employee=employee,
        form=form,
        edit_url=edit_url)
Beispiel #13
0
def tenancy_edit(key_id):
    tenancy = Tenancy.retrieve_by_id(key_id)
    if not tenancy:
        return redirect(url_for('tenancy.admin.tenancy'))
    if request.method == 'POST' and 'delete_tenancy' in request.form:
        tenancy.key.delete()
        return redirect(url_for('tenancy.admin.tenancy'))
    url = blobstore.create_upload_url(
        url_for('tenancy.admin.edit', key_id=key_id)
    )
    form = TenancyForm(obj=tenancy)
    if request.method == 'POST':
        upload_files = get_uploads(request, 'attach_file')
        file_ = None
        if len(upload_files):
            blob_info = upload_files[0]
        else:
            blob_info = None

        if form.validate_on_submit():
            if blob_info:
                blob_info = blobstore.BlobInfo.get(blob_info.key())
                if blob_info.size:
                    file_ = File.create(
                        blob_key=blob_info.key(),
                        title=form.name.data,
                        description=form.description.data,
                        is_public=form.is_public.data,
                        filename=os.path.basename(blob_info.filename.replace('\\', '/')),
                        size=blob_info.size,
                        content_type=blob_info.content_type)
                    file_.put()
                else:
                    blob_info.delete()

        form.populate_obj(tenancy)
        if file_:
            if tenancy.file:
                tenancy.file.delete()
            tenancy.file = file_.key
        tenancy.put()
        return redirect(url_for('tenancy.admin.tenancy'))

    return render_template(
        'tenancy/admin/tenancy_edit.html',
        tenancy=tenancy,
        form=form,
        url=url
    )
Beispiel #14
0
def admin_add_image(request, uid):
    if request.method == 'POST':
        showcase = Showcase.get_by_id(uid)
        if not showcase:
            return render_to_response('empty.html')
        upload_files = get_uploads(request, 'file')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size:
                image = ShowcaseImage(showcase_key=showcase.key(),
                    image_key=str(blob_info.key()))
                image.cached_url = image.get_cached_url()
                image.put()
            else:
                 blob_info.delete()
        return admin_images(request, uid)
    return render_to_response('empty.html')
Beispiel #15
0
def tenancy_add():
    form = TenancyForm()
    url = blobstore.create_upload_url(
        url_for('tenancy.admin.add')
    )
    if request.method == 'POST':
        upload_files = get_uploads(request, 'attach_file')
        file_ = None
        if len(upload_files):
            blob_info = upload_files[0]
        else:
            blob_info = None

        if form.validate_on_submit():
            if blob_info:
                blob_info = blobstore.BlobInfo.get(blob_info.key())
                if blob_info.size:
                    file_ = File.create(
                        blob_key=blob_info.key(),
                        title=form.name.data,
                        description=form.description.data,
                        is_public=form.is_public.data,
                        filename=os.path.basename(blob_info.filename.replace('\\', '/')),
                        size=blob_info.size,
                        content_type=blob_info.content_type)
                    file_.put()
                else:
                    blob_info.delete()

        tenancy = Tenancy()
        form.populate_obj(tenancy)
        if file_:
            tenancy.file = file_.key
        tenancy.put()
        return redirect(url_for('tenancy.admin.tenancy'))

    tenancies = Tenancy.query()
    return render_template(
        'tenancy/admin/add.html',
        add_active='active',
        form=form,
        tenancies=tenancies,
        url=url
    )
Beispiel #16
0
def edit_investment(key_id):
    investment = Investment.retrieve_by_id(key_id)
    if not investment:
        return redirect(url_for('investment.admin.index'))
    if request.method == 'POST' and 'delete_investment' in request.form:
        investment.key.delete()
        return redirect(url_for('investment.admin.index'))
    url = blobstore.create_upload_url(
            url_for('investment.admin.edit', key_id=key_id))
    form = InvestmentForm(obj=investment)
    if request.method == 'POST':
        upload_files = get_uploads(request, 'attach_file')
        file_ = None
        if len(upload_files):
            blob_info = upload_files[0]
        else:
            blob_info = None

        if form.validate_on_submit():
            if blob_info:
                blob_info = blobstore.BlobInfo.get(blob_info.key())
                if blob_info.size:
                    file_ = File.create(
                        blob_key=blob_info.key(),
                        filename=os.path.basename(blob_info.filename.replace('\\', '/')),
                        size=blob_info.size,
                        content_type=blob_info.content_type)
                    file_.put()
                else:
                    blob_info.delete()

            form.populate_obj(investment)
            if file_:
                if investment.file:
                    investment.file.delete()
                investment.file = file_.key
            investment.put()
            return redirect(url_for('investment.admin.index'))
    return render_template(
        'investment/admin/edit.html',
        form=form,
        url=url,
        investment=investment
    )
Beispiel #17
0
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)
Beispiel #18
0
def add_file(key_id):
    folder = Folder.retrieve_by_id(key_id)
    if not folder:
        return flask.redirect(flask.url_for('admin.file.index'))
    upload_files = get_uploads(flask.request, 'file')
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size:
            file = File.create(
                blob_info.key(),
                size=blob_info.size,
                filename=os.path.basename(blob_info.filename.replace('\\','/')),
                content_type=blob_info.content_type)
            file.put()
            if file.get_cached_url():
                folder.files.append(file.key)
                folder.put()
        else:
            blob_info.delete()
    return flask.redirect(flask.url_for('admin.file.edit_folder', key_id=key_id))
Beispiel #19
0
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})
Beispiel #20
0
def r_info_add_image(request, uid):
    if request.method == 'POST':
        news = RetailInfo.get_by_id(uid)
        if not news:
            return render_json_response({'api':{'success':False}})
        upload_files = get_uploads(request, 'file')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size:
                image = RetailInfoImage.create(blob_info.key())
                news = RetailInfo.get_by_id(uid)
                images = RetailInfoImage.query(RetailInfoImage.news_ref == news.key)
                if not images.count:
                    image.is_master = True
                image.news_ref = news.key
                image.cached_url = image.get_cached_url()
                image.put()
            else:
                blob_info.delete()
        return r_info_images(request, uid)
    return render_to_response('empty.html')
Beispiel #21
0
def add_newsletter_file(request, key):
    newsletter = Newsletter.get(key)
    url = blobstore.create_upload_url(url_for("admin/add_newsletter_file", key=key))
    form = NewsletterFileForm(action=url)
    form.csrf_protected = False
    if request.method == "POST" and form.validate(request.form):
        upload_files = get_uploads(request, "file")
        if not len(upload_files):
            return redirect(url_for("admin/add_newsletter_file", key=key))
        blob_info = upload_files[0]
        bl = blobstore.BlobInfo.get(blob_info.key())
        filename = os.path.basename(bl.filename.replace("\\", "/"))
        file_ = File(
            filename=filename, content_type=blob_info.content_type, blob_key=str(blob_info.key()), length=blob_info.size
        )
        file_.put()
        newsletter.n_price_list.append(str(file_.key()))
        newsletter.put()
        return redirect(url_for("admin/edit_newsletter", key=key))
    return render_to_response(
        "postman/admin/newsletters/add_file.html", {"form": form.as_widget(), "newsletter": newsletter, "key": key}
    )
Beispiel #22
0
def add_image(key_id):
    product = Product.retrieve_by_id(key_id)
    if not product:
        return redirect('pages.catalogue')

    upload_files = get_uploads(request, 'image')
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size and ProductImage.is_image_type(blob_info.content_type):
            img = ProductImage.create(
                blob_info.key(),
                size=blob_info.size,
                filename=os.path.basename(blob_info.filename.replace('\\','/')),
                content_type=blob_info.content_type)
            if not len(product.images_list):
                img.is_master = True
            if img.get_cached_url():
                product.images_list.append(img)
                product.put()
        else:
            blob_info.delete()
    return redirect(url_for('admin.product.edit_images', key_id=key_id))
Beispiel #23
0
def add_investment():
    form = InvestmentForm()
    url = blobstore.create_upload_url(
        url_for('investment.admin.add'))
    if request.method == 'POST':
        upload_files = get_uploads(request, 'attach_file')
        file_ = None
        if len(upload_files):
            blob_info = upload_files[0]
        else:
            blob_info = None

        if form.validate_on_submit():
            if blob_info:
                blob_info = blobstore.BlobInfo.get(blob_info.key())
                if blob_info.size:
                    file_ = File.create(
                        blob_key=blob_info.key(),
                        title=form.name.data,
                        description=form.description.data,
                        is_public=form.is_public.data,
                        filename=os.path.basename(blob_info.filename.replace('\\', '/')),
                        size=blob_info.size,
                        content_type=blob_info.content_type)
                    file_.put()
                else:
                    blob_info.delete()

            investment = Investment()
            form.populate_obj(investment)
            if file_:
                investment.file = file_.key
            investment.put()
            return redirect(url_for('investment.admin.index'))
    return render_template(
        'investment/admin/add.html',
        form=form,
        url=url
    )
Beispiel #24
0
def product_upload_image(key_id):
    product = Product.retrieve_by_id(key_id)
    if not product:
        return jsonify({
            'success': False,
            'msg': 'Product id:%s not found' % key_id
        })

    upload_files = get_uploads(request, 'image')
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size and \
                ProductImage.is_image_type(blob_info.content_type):
            img = ProductImage.create(blob_info.key(),
                                      size=blob_info.size,
                                      filename=os.path.basename(
                                          blob_info.filename.replace(
                                              '\\', '/')),
                                      content_type=blob_info.content_type)
            if not len(product.images_list):
                img.is_master = True
            if img.get_cached_url():
                product.images_list.append(img)
                product.put()
        else:
            file_size = blob_info.size
            content_type = blob_info.content_type
            blob_info.delete()
            return jsonify({
                'success':
                False,
                'msg':
                "Unknown error. File size: %s. File type: %s" %
                (file_size, content_type)
            })
    else:
        return jsonify({'success': False, 'msg': 'Upload image not found.'})
    return jsonify({'success': True, 'msg': 'Upload image complete.'})
Beispiel #25
0
def admin_files_upload():
    form = AboutFileForm()
    if form.validate_on_submit():
        upload_files = get_uploads(request, 'file')
        if len(upload_files):
            blob_info = upload_files[0]
            blob_info = blobstore.BlobInfo.get(blob_info.key())
            if blob_info.size:
                file_ = File.create(
                    blob_key=blob_info.key(),
                    title=form.title.data,
                    description=form.description.data,
                    is_public=form.is_public.data,
                    # wtf? for fix unicode filenames
                    filename=os.path.basename(blob_info.filename.replace('\\','/')),
                    size=blob_info.size,
                    content_type=blob_info.content_type)
                file_.put()
                about_file = AboutFile(file_key=file_.key)
                about_file.put()
            else:
                blob_info.delete()
    return redirect(url_for('about.admin_files'))
Beispiel #26
0
def change_delivery(request):
    url = blobstore.create_upload_url(url_for('partners/admins/change_delivery'))
    obj = PartnersPage.all().get()
    if obj:
        form = PartnersDeliveryForm(instance=obj, action=url)
    else:
        form = PartnersDeliveryForm(action=url)
    form.csrf_protected = False
    if request.method == 'POST' and form.validate(request.form):
        obj = form.save(commit=False)
        upload_files = get_uploads(request, 'delivery')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size:
                obj.delivery = str(blob_info.key())
            else:
                blob_info.delete()
        else:
            obj.delete_delivery()
        obj.put()
        return redirect(url_for('admin/index'))
    return render_to_response('partners/admins/change.html',
            {'form':form.as_widget()})
Beispiel #27
0
def add_image(key_id):
    product = Product.retrieve_by_id(key_id)
    if not product:
        return redirect('pages.catalogue')

    upload_files = get_uploads(request, 'image')
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size and ProductImage.is_image_type(
                blob_info.content_type):
            img = ProductImage.create(blob_info.key(),
                                      size=blob_info.size,
                                      filename=os.path.basename(
                                          blob_info.filename.replace(
                                              '\\', '/')),
                                      content_type=blob_info.content_type)
            if not len(product.images_list):
                img.is_master = True
            if img.get_cached_url():
                product.images_list.append(img)
                product.put()
        else:
            blob_info.delete()
    return redirect(url_for('admin.product.edit_images', key_id=key_id))
Beispiel #28
0
def index(request):
    url = blobstore.create_upload_url(url_for('price_list/admin'))
    form = PriceListForm(action=url)
    form.csrf_protected = False
    if request.method == 'POST' and form.validate(request.form):
        desc = form['description']
        upload_files = get_uploads(request, 'file')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size:
                file = File(blob=blob_info.key())
                file.name = file.get_name
                file.put()

                price_list = PriceList(file=file.key, description=desc)
                price_list.put()
            else:
                blob_info.delete()

        return redirect(url_for('price_list/admin'))
    prices = PriceList.query()
    return render_to_response('price_list/admins/index.html',
                                {'form': form.as_widget(),
                                'prices': prices})