Esempio n. 1
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
    )
Esempio n. 2
0
def index():
    investment_info = InvestmentInfo.get_master_db()
    investments = Investment.query(Investment.is_public == True).order(Investment.order_id)
    tenancy_info = TenancyInfo.get_master_db()
    tenancies = Tenancy.query(Tenancy.is_public == True).order(Tenancy.order_id)
    employees = Employee.query(Employee.is_investment == True)
    return render_template(
        'investment/index.html',
        html_class='services_page',
        investment_info=investment_info,
        investments=investments,
        tenancy_info=tenancy_info,
        tenancies=tenancies,
        employees=employees,
        active_element='investment'
    )
Esempio n. 3
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
    )
Esempio n. 4
0
def inv_list():
    investments = Investment.query().order(Investment.order_id)
    return render_template(
        'investment/admin/list.html',
        investments=investments
    )