예제 #1
0
def publication_add(request):
    if request.method == 'POST':
        publication_form = PublicationForm(request.POST, request.FILES)
        if publication_form.is_valid():
            instance = publication_form.save(user=request.user)
            instance.save()
            publication_form.save_m2m()
            url = instance.get_absolute_url()
            return redirect(url)
            #return HttpResponse(simplejson.dumps({'status':True,'url':url})) 
        """
        else:
            errors = publication_form.errors
            return HttpResponse(simplejson.dumps({'status':False,'errors':errors}))
        """
    else:
        if request.GET.get('theme',False):
            theme_name = request.GET.get('theme')
            theme = get_object_or_404(Theme,slug=theme_name)
            publication_form = PublicationForm(initial={'theme_name':theme.title,'theme_id':theme.id })
        else:
            publication_form = PublicationForm()

    return render(request,
                  "publication/publication_form.html",
                  {'publication_form': publication_form},
                  )
예제 #2
0
def edit_publication(request, theme_slug,publication_slug):
    publication = get_object_or_404(Publication, slug=publication_slug,\
        user=request.user)
    theme = get_object_or_404(Theme,slug=theme_slug)
    if request.method == 'POST':
        publication_form = PublicationForm(request.POST,\
            request.FILES,instance=publication)
        if publication_form.is_valid():
            publication_form.save()
            publication_form.save_m2m()
            return redirect('website:publication_detail', theme_slug=theme.slug,
                publication_slug=publication.slug)

    else:
        publication_form = PublicationForm(instance=publication,\
            initial={'theme_name':theme.title})

    return render(request,"publication/publication_form.html",{
                'publication_form': publication_form,
            })