Ejemplo n.º 1
0
def project(request, project_id):
    p = get_object_or_404(Project, user=request.user, id=project_id)
    if request.method == 'POST':
        a = request.POST['attr']
        if a in ['name', 'description']:
            setattr(p, a, request.POST['text'])
            p.save()
            return HttpResponse("")
        elif a == 'color':
            p.color = abbr2color(request.POST['abbrev'])
            p.save()
            return HttpResponse("")
        else:
            return HttpResponseForbidden()

    return render(request, 'project.html', {
        'project': p})
Ejemplo n.º 2
0
def create(request):
    if 'color' in request.GET:
        color = abbr2color(request.GET['color'])
    else:
        color = None
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            p = form.save(commit=False)
            p.user = request.user
            p.save()
            if 'back' in request.GET:
                return redirect(request.GET['back'] + '?pid=%s' % p.id)
            else:
                return redirect('project', p.id)
    else:
        if color is not None:
            form = ProjectForm(initial={'color': color})
        else:
            form = ProjectForm()
    return render(request, 'add.html', {'form': form,
                                        'action': request.get_full_path})