Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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))