def createAdvertisement(request): if request.user.sdaeuser.type.name != 'Departamento Escolar': return HttpResponseRedirect('/home/') if request.method != 'POST': pform = PublicationForm() aform = AdvertisementForm() else: pform = PublicationForm(request.POST) aform = AdvertisementForm(request.POST) if pform.is_valid() and aform.is_valid(): saveAdvertisement(aform, pform, request.user) return HttpResponseRedirect('/publications/advertisement') return render(request, 'publications/advertisement_create.html', {'pform':pform, 'aform':aform})
def editAdvertisement(request, advertisementID): publication = get_object_or_404(Publication, pk=advertisementID) if publication.author.user != request.user: return HttpResponseForbidden() advertisement= publication.advertisement if request.method != 'POST': pform = PublicationForm(instance=publication) aform = AdvertisementForm(instance=advertisement) else: pform = PublicationForm(request.POST, instance = publication) aform = AdvertisementForm(request.POST, instance = advertisement) if pform.is_valid() and aform.is_valid(): saveAdvertisement(aform, pform, request.user) return HttpResponseRedirect('/publications/advertisement') return render(request, 'publications/advertisement_create.html', {'aform':aform, 'pform':pform})