def save_logo(request, logo_id): if not request.user.has_perm('spons.manage_logo'): return render(request, 'alert.html', {'msg':'You dont have permission',}) logo=SponsImageUpload.objects.get(pk=logo_id) if request.method == 'POST': print 'POST' form = AddLogoForm(request.POST or None,request.FILES or None, instance=logo) print form.errors if form.is_valid(): print 'valid' img=form.save(commit=False) img.uploaded_by=request.user img.save() messages.success(request,'Image successfully updated') return redirect('spons_add_logo')
def add_logo(request): if not request.user.has_perm('spons.manage_logo'): return render(request, 'alert.html', {'msg':'You dont have permission',}) form = AddLogoForm(request.POST or None,request.FILES or None) if form.is_valid(): img = form.save(commit=False) img.uploaded_by = request.user img.save() messages.success(request,'Image successfully saved') HttpResponseRedirect(reverse('spons_add_logo')) logos = SponsImageUpload.objects.all().order_by('-priority') to_return = { 'form':form, 'list':logos, } return render(request, 'spons/add_logo.html', to_return)
def edit_logo(request, logo_id): if not request.user.has_perm('spons.manage_logo'): return render(request, 'alert.html', {'msg':'You dont have permission',}) logo=SponsImageUpload.objects.get(pk=logo_id) if request.method == 'POST': form = AddLogoForm(request.POST or None,request.FILES or None) if form.is_valid(): img=form.save(commit=False) img.uploaded_by=request.user img.save() messages.success(request,'Image successfully updated') HttpResponseRedirect(reverse('spons_add_logo')) else: form = AddLogoForm(instance=logo) to_return={ 'logo':logo, 'form': form, } return render(request, 'spons/edit_logo.html', to_return)