Exemplo n.º 1
0
def employee_edit(key_id):
    employee = Employee.retrieve_by_id(key_id)
    if not employee:
        return redirect(url_for('about.admins.employee'))
    form = EmployeeForm(obj=employee)
    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)
Exemplo n.º 2
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)