def admin_categories(parent_id=ROOT_CAT_ID): """List all categories""" form = CategoryForm(prefix='category') if form.validate_on_submit(): if len(form.key_id.data) > 0 and long(form.key_id.data) > 0: category = CategoryModel.get_by_id(long(form.key_id.data)); else: category = CategoryModel() v2m(form, category) try: category.put() category_id = category.key().id() flash(u'Category %s successfully saved.' % category_id, 'success') return redirect(url_for('admin_category', parent_id=category.parent_id)) except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return redirect(url_for('admin_category', parent_id=category.parent_id)) except CircularCategoryException as cce: flash(cce.message, 'error') return redirect(url_for('admin_category', parent_id=category.parent_id)) pass elif form.is_submitted(): parent_id = long(form.parent_id.data) (categories, category_path, all_categories) = CategoryModel.get_categories_info(parent_id) form.parent_id.data = category_path[-1].key().id() reset_category = CategoryModel() reset_category.parent_id = parent_id return render_template('category/admin_categories.html', categories=categories, form=form, category_path=category_path, current_category=category_path[-1], all_categories=all_categories, reset_category=reset_category)
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')))
def admin_categories(parent_id=ROOT_CAT_ID): """List all categories""" form = CategoryForm(prefix='category') if form.validate_on_submit(): if len(form.key_id.data) > 0 and long(form.key_id.data) > 0: category = CategoryModel.get_by_id(long(form.key_id.data)) else: category = CategoryModel() v2m(form, category) try: category.put() category_id = category.key().id() flash(u'Category %s successfully saved.' % category_id, 'success') return redirect( url_for('admin_category', parent_id=category.parent_id)) except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return redirect( url_for('admin_category', parent_id=category.parent_id)) except CircularCategoryException as cce: flash(cce.message, 'error') return redirect( url_for('admin_category', parent_id=category.parent_id)) pass elif form.is_submitted(): parent_id = long(form.parent_id.data) (categories, category_path, all_categories) = CategoryModel.get_categories_info(parent_id) form.parent_id.data = category_path[-1].key().id() reset_category = CategoryModel() reset_category.parent_id = parent_id return render_template('category/admin_categories.html', categories=categories, form=form, category_path=category_path, current_category=category_path[-1], all_categories=all_categories, reset_category=reset_category)