Esempio n. 1
0
def index():
    coach_info = CoachInfo.get_master_db()
    coaches = Coach.query(Coach.is_public == True).order(-Coach.order_id)
    employees = Employee.query(Employee.is_investment == True)
    return render_template(
        'coach/index.html',
        html_class='services_page',
        coach_info=coach_info,
        coaches=coaches,
        employees=employees,
        active_element='coach'
    )
Esempio n. 2
0
def add_coach():
    form = CoachForm()
    url = blobstore.create_upload_url(
        url_for('coach.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()

            coach = Coach()
            form.populate_obj(coach)
            if file_:
                coach.file = file_.key
            coach.put()
            return redirect(url_for('coach.admin.index'))
    return render_template(
        'coach/admin/add.html',
        form=form,
        url=url
    )
Esempio n. 3
0
def edit_coach(key_id):
    coach = Coach.retrieve_by_id(key_id)
    if not coach:
        return redirect(url_for('coach.admin.index'))
    if request.method == 'POST' and 'delete_coach' in request.form:
        coach.key.delete()
        return redirect(url_for('coach.admin.index'))
    url = blobstore.create_upload_url(
            url_for('coach.admin.edit', key_id=key_id))
    form = CoachForm(obj=coach)
    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(coach)
            if file_:
                if coach.file:
                    coach.file.delete()
                coach.file = file_.key
            coach.put()
            return redirect(url_for('coach.admin.index'))
    return render_template(
        'coach/admin/edit.html',
        form=form,
        url=url,
        coach=coach
    )
Esempio n. 4
0
def inv_list():
    coaches = Coach.query().order(-Coach.order_id)
    return render_template(
        'coach/admin/list.html',
        coaches=coaches
    )