def get(self, request, *args, **kwargs): form = GalleryForm() gallery = Gallery.objects.all().order_by('created_at') return render(request, 'dashboard/gallery-management.html', { 'form': form, 'gallery': gallery })
def gallery_edit(request, *args, **kwargs): if request.POST: owner_id = kwargs.get('owner_id', None) owner = get_object_or_404(User, pk=owner_id) gallery = Gallery(owner=owner, creation_date=datetime.datetime.now()) form = GalleryForm(request.POST, instance=gallery) if form.is_valid(): form.save() redirect_url = reverse('owner', args=(owner_id,)) return HttpResponseRedirect(redirect_url) else: form = GalleryForm() context = {'form': form} return render(request, 'gallery/gallery_edit.html', context)
def post(self, request, id=0, *args, **kwargs): data = {} gallery = get_object_or_404(Gallery, id=id) if request.method == 'POST': form = GalleryForm(request.POST or None, request.FILES or None, instance=gallery) if form.is_valid(): edit = form.save(commit=False) edit.save() date = datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d') Gallery.objects.filter(pk=id).update(is_updated=True, updated_at=date) data['form_is_valid'] = True else: data['form_is_valid'] = False return JsonResponse(data)
def get(self, request, id=0, *args, **kwargs): data = {} gallery = get_object_or_404(Gallery, id=id) form = GalleryForm(instance=gallery) context = {'form': form} data['html_form'] = render_to_string( 'dashboard/gallery-parts/gallery-update.html', context, request=request) return JsonResponse(data)
def addgallery(request): if request.method == 'POST': form = GalleryForm(request.POST) if form.is_valid(): gallery = form.save() gfunc.create_folder(gallery.slug) else: form = GalleryForm() return render(request, 'gallery/addgallery.html', {'form': form})
def gallery_edit(request, *args, **kwargs): if request.POST: owner_id = kwargs.get('owner_id', None) owner = get_object_or_404(User, pk=owner_id) gallery = Gallery(owner=owner, creation_date=datetime.datetime.now()) form = GalleryForm(request.POST, instance=gallery) if form.is_valid(): form.save() redirect_url = reverse('owner', args=(owner_id, )) return HttpResponseRedirect(redirect_url) else: form = GalleryForm() context = {'form': form} return render(request, 'gallery/gallery_edit.html', context)
def post(self, request, *args, **kwargs): bindform = GalleryForm(request.POST) post = bindform.save(commit=False) post.user = request.user post.save() return HttpResponseRedirect('/gallery/list')
def post(self, request, *args, **kwargs): if request.method == 'POST': form = GalleryForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponse()