示例#1
0
def edit_proj(request, project_slug):
    proj = get_object_or_404(Projet, slug=project_slug)
    if proj.user != request.user:
        return HttpResponseForbidden()
    else:
        images = ImageProject.objects.get(project=proj)
    if request.POST:
        form_projet = ProjetForm(request.POST, instance=proj, prefix="projet")
        form = ImageForm(request.POST, request.FILES, prefix="images", instance=images)
        import ipdb;ipdb.set_trace()
        if form.is_valid() and form_projet.is_valid():
            form.save()
            proj = form_projet.save(commit=False)
            proj.slug = slugify(proj.title)
            proj.save()
            # If the save was successful, redirect to another page
            redirect_url = reverse('tracking.views.dashboard', kwargs={'projet_slug': proj.slug})
            return HttpResponseRedirect(redirect_url)

    else:
        form = ImageForm(prefix="images", instance=images)
        form_projet = ProjetForm(prefix="projet", instance=proj)
    return render(request, 'projet/edit.html', {
        'form': form,
        'form_projet': form_projet,
        'proj': proj,
        })
示例#2
0
def createproj(request):
    if request.method == 'POST':
        form = ImageForm(request.POST, request.FILES, prefix="images")
        form_projet = ProjetForm(request.POST, prefix="projet")
        if form.is_valid() and form_projet.is_valid():
            form.save(commit=False)
            projet = form_projet.save(commit=False)
            title = projet.title
            projet.slug = slugify(title)
            projet.user = request.user
            projet.meta_description = projet.content
            projet.meta_keywords = projet.content.split()
            projet.save()
            images = form.save(commit=False)
            images.project = projet
            images.save()
            success_url = reverse('projet.views.success_create', args=[str(projet.slug)])
            return HttpResponseRedirect(success_url)
    else:
        form = ImageForm(prefix="images")
        form_projet = ProjetForm(prefix="projet")
    return render(request, 'projet/creation.html', {
        'form': form,
        'form_projet': form_projet,
        })