def item_create_admin(request): category_form = AbstractFactory.upsert(request, CategoryAdminForm) item_form = AbstractFactory.upsert(request, ItemAdminForm) if item_form.is_valid(): messages.success(request, _("You have create a new item")) return redirect('wishlist:item_list_admin') return render(request, 'wishlist/admin/item/form.html', {'form': item_form, 'category_form': category_form, 'action': _("Create")})
def item_clone_admin(request, item_id): item = get_object_or_404(Item, id=item_id) item_form = AbstractFactory.upsert(request, ItemAdminForm, item) category_form = AbstractFactory.upsert(request, CategoryAdminForm) if item_form.is_valid(): messages.success(request, _("You have clone item : " + item.title)) return redirect('wishlist:item_list_admin') return render(request, 'wishlist/admin/item/form.html', {'form': item_form, 'category_form': category_form, 'action': _("Clone")})
def item_update_admin(request, item_id): item = get_object_or_404(Item, id=item_id) item_form = AbstractFactory.upsert(request, ItemAdminForm, item) category_form = AbstractFactory.upsert(request, CategoryAdminForm) if item_form.is_valid(): messages.success(request, _("You have update item : " + item.title)) return redirect('wishlist:item_list_admin') historical_items = Item.history.filter(id=item_id).order_by('-history_id') return render(request, 'wishlist/admin/item/form.html', {'form': item_form, 'category_form': category_form, 'historical_items': historical_items, 'action': _("Update")})
def category_revert_admin(request, item_id, history_id): category = get_object_or_404(Category, id=item_id) historical_category = Category.history.get(history_id=history_id) category_form = AbstractFactory.upsert(request, CategoryAdminForm, category, historical_category) if category_form.is_valid(): messages.success(request, _("You have revert category : " + category.title)) return redirect('wishlist:category_list_admin') return render(request, 'wishlist/admin/item/form.html', {'form': category_form, 'action': _("Revert")})
def category_update_admin(request, category_id): category = get_object_or_404(Category, id=category_id) category_form = AbstractFactory.upsert(request, CategoryAdminForm, category) if category_form.is_valid(): messages.success(request, _("You have update category : " + category.title)) return redirect('wishlist:category_list_admin') historical_items = Category.history.filter(id=category_id).order_by('-history_id') return render(request, 'wishlist/admin/category/form.html', {'form': category_form, 'historical_items': historical_items, 'action': _("Update")})