Esempio n. 1
0
def admin_files_add():
    form = AboutFileForm()
    files = AboutFile.query()
    upload_url = blobstore.create_upload_url(url_for('about.admin_files_upload'))
    return render_template(
        'about/admins/add_file.html',
        form=form,
        files=files,
        upload_url=upload_url)
Esempio n. 2
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'))
Esempio n. 3
0
def admin_files_edit(file_id):
    a_file = AboutFile.retrieve_by_id(file_id)
    if a_file is None or not a_file.file:
        return redirect(url_for('about.admin_files'))
    if request.method == 'POST' and 'delete_file' in request.form:
        a_file.key.delete()
        return redirect(url_for('about.admin_files'))
    form = AboutFileEditForm(obj=a_file.file)
    if request.method == 'POST' and form.validate_on_submit():
        a_file.file.title = form.title.data
        a_file.file.description = form.description.data
        a_file.file.is_public = form.is_public.data
        a_file.file.put()
        a_file.put()
        return redirect(url_for('about.admin_files'))
    return render_template(
        'about/admins/edit_file.html',
        form=form,
        file=a_file.file)
Esempio n. 4
0
def show_files():
    files = AboutFile.query().order(-AboutFile.created)
    return render_template(
        'about/files.html',
        html_class='about_page',
        files=files)
Esempio n. 5
0
def admin_files():
    files = AboutFile.query()
    return render_template(
        'about/admins/files.html',
        files=files
    )