Example #1
0
def admin_delete(request, key_id):
    if request.method == 'POST':
        gram = GramPhoto.get_by_id(key_id)
        if gram:
            gram.pre_delete()
        gram.key.delete()
    return redirect(url_for('gram/admin/index'))
Example #2
0
def admin_index(request):
    photos = GramPhoto.query().order(-GramPhoto.add_time)
    url = blobstore.create_upload_url(url_for('gram/admin/add'))
    return render_to_response(
        'gram/admin/index.html', {
            'photos': photos,
            'url': url
        })
Example #3
0
def admin_add(request):
    if request.method == 'POST':
        upload_files = get_uploads(request, 'file')
        if len(upload_files):
            blob_info = upload_files[0]
            if blob_info.size:
                image = GramPhoto.create(blob_info.key())
                image.put()
            else:
                blob_info.delete()
    return redirect(url_for('gram/admin/index'))
Example #4
0
def load(request, offset):
    offset = int(offset)
    if offset <= 0:
        return render_to_response('empty.html')
    grams = GramPhoto.query().order(-GramPhoto.add_time)
    length = grams.count()
    if offset >= length:
        return render_to_response('empty.html')
    limit = 8
    is_end = False
    if offset + limit >= length:
        limit = length - offset
        is_end = True
    grams = grams.fetch(limit, offset=offset-1)
    return render_to_response('gram/load.html', {'grams': grams, 'is_end': is_end})
Example #5
0
def index(request):
    grams = GramPhoto.query().order(-GramPhoto.add_time).fetch(4)
    return render_to_response('page/index.html', {'grams': grams})