コード例 #1
0
ファイル: views.py プロジェクト: wtahler/churchDownloads
def uploadSermon(request):
    context = {}
    context.update(csrf(request))
    context['sermonFileForm'] = SermonFileForm()
    if request.method == 'POST':
        sermonForm = SermonFileForm(request.POST,request.FILES)
        if sermonForm.is_valid():
            newSermon = sermonForm.save(commit=False)
            newSermon.owner = request.user
            newSermon.save()
            return HttpResponseRedirect(reverse(uploadSermon))
        else:
            context['sermonFileForm'] = sermonForm
            context['error'] = "Correct the errors before submitting"
    return render_to_response('sermonForm.html',context,context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: wtahler/churchDownloads
def editSermon(request,id=False):
    context = {}
    context.update(csrf(request))
    if request.method == 'POST':
        sermonForm = SermonFileForm(request.POST,request.FILES)
        if sermonForm.is_valid() and not id:
            newSermon = sermonForm.save(commit=False)
            newSermon.owner = request.user
            if id:
                newSermon.pk = id
            newSermon.save()
            return HttpResponseRedirect(reverse(viewFolder,args=[False]))
        elif id:
            newSermon = SermonFileForm(request.POST,request.FILES,instance=SermonFile.objects.get(pk=id)).save(commit=False)
            newSermon.owner = request.user
            newSermon.save()
            return HttpResponseRedirect(reverse(viewFolder,args=[False]))
        else:
            context['sermonFileForm'] = sermonForm
            context['error'] = "Correct the errors before submitting"
    elif id:
        context['currID'] = id
        context['sermonFileForm'] = SermonFileForm(instance=SermonFile.objects.get(pk=id))
    else:
        context['sermonFileForm'] = SermonFileForm()
        
    return render_to_response('sermonForm.html',context,context_instance=RequestContext(request))