예제 #1
0
파일: admins.py 프로젝트: gmist/solostyle
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
    )
예제 #2
0
파일: admins.py 프로젝트: gmist/solostyle
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)