コード例 #1
0
ファイル: views.py プロジェクト: wwq0327/open-lab
def prj_create(request):
    if request.method == 'POST':
        form = ProjectsForm(request.POST, request.FILES)
        if form.is_valid():
            model = form.save(commit=False)
            model.creater = request.user
            model.save()
            return HttpResponseRedirect(model.get_absolute_url())
    else:
        form = ProjectsForm()

    return render_to_response('projects/prj_create.html',
                              {'form': form},
                              context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: wwq0327/open-lab
def prj_edit(request, prj_pk):
    '''project edit
    @param prj_pk: project id
    '''
    prj = get_object_or_404(Projects, pk=prj_pk)
    if request.user != prj.creater:
        return HttpResponseForbidden()
    if request.method == 'POST':
        form = ProjectsForm(request.POST, request.FILES, instance=prj)
        if form.is_valid():
            o = form.save(commit=False)
            o.creater = request.user
            o.save()
            return HttpResponseRedirect(o.get_absolute_url())
    else:
        form = ProjectsForm(instance=prj)

    return render_to_response('projects/prj_create.html',
                              {'form': form},
                              context_instance=RequestContext(request))