Beispiel #1
0
def delete_image(image_id):
    """Delete an image object"""
    image = ImageModel.get_by_id(image_id)
    parent_id = image.category_id
    try:
        # delete image from blobstore
        image.delete_images()
        # delete tha data entry
        image.delete()
        flash(u'Image %s successfully deleted.' % image_id, 'success')
    except CapabilityDisabledError:
        flash(u'App Engine Datastore is currently in read-only mode.', 'info')
    return redirect(url_for('admin_images_in_category', parent_id=parent_id))
Beispiel #2
0
def get_images_for_category(category_id):
    ''' 
        Retrieves images for a given category
    '''
    # FIXME lorempixum
    n = Random().randint(8, 20);
    contents = []
    for i in range(0, n):
        c = ImageModel()
        c.title = get_random_text(Random().randint(5, 25)).replace('\n', '').replace('\r', '')
        c.description = get_random_text(Random().randint(45, 325))
        c.height = MAX_HEIGHT
        c.width = Random().randint(300, MAX_WIDTH)
        c.image_blob_key = 'pixum'
        c = c.jsond()
        c['id'] = i
        contents += [c]
        pass
#    contents = [c.jsond() for c in ImageModel.all().filter('category_id', category_id).filter('visible', True)]
    return contents 
    pass
Beispiel #3
0
def admin_images(parent_id= -1):
    """
        List all images from within a category
    """
    category_id = parent_id
    form = ImageForm(prefix='image')
    if form.validate_on_submit():
        is_new = False
        if len(form.key_id.data) > 0 and long(form.key_id.data) > 0:
            image = ImageModel.get_by_id(long(form.key_id.data))
        else:
            image = ImageModel()
            is_new = True
        v2m(form, image)
        category_id = long(form.category_id.data)
        if type(form.image.data) == FileStorage and (is_new or form.update_image.data):
            blob_key = form.image.data.mimetype_params['blob-key']
            #create a small
            (image.image_thumb_blob_key, image.width, image.height) = create_thumbnail(blob_key, 50, 50)
            #and a slightly larger version 
            (image.image_blob_key, image.width, image.height) = create_thumbnail(blob_key)
            #delete the uploaded (possibly 'uge file)
            blobstore.delete(blob_key)
        elif not is_new and form.update_image.data: # we set to update with an empty image so we delete the one in the db
            image.delete_images()
            image.image_blob_key = ''
            image.image_thumb_blob_key = ''
            image.width = 0
            image.height = 0
        try:
            image.put()
            image_id = image.key().id()
            flash(u'Image %s successfully saved.' % image_id, 'success')
            return redirect(url_for('admin_images_in_category', parent_id=category_id))
        except CapabilityDisabledError:
            image.delete_images()
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('admin_images_in_category', parent_id=category_id))
        pass
    elif form.is_submitted():
        category_id = long(form.category_id.data)  
    images = sorted(ImageModel.all().filter('category_id', category_id), key=lambda i: i.order)
    (categories, category_path, all_categories) = CategoryModel.get_categories_info(category_id)
    form.category_id.data = category_path[-1].key().id()
    return render_template('image/admin_images.html', images=images,
                           form=form,
                           categories=categories,
                           category_path=category_path,
                           current_category=category_path[-1],
                           all_categories=all_categories,
                           reset_image=ImageModel(category_id=category_id),
                           upload_url=blobstore.create_upload_url(url_for('admin_images')))
Beispiel #4
0
def move_image(image_id, parent_id=ROOT_CAT_ID):
    cat = ImageModel.get_by_id(image_id)
    cat.category_id = parent_id
    cat.put()
    return redirect(url_for('admin_images_in_category', parent_id=parent_id), 302)
    pass