Esempio n. 1
0
def update(request, project):
    data = {}
    project = get_object_or_404(db.Project, label=project)

    if request.method == 'POST':
        if request.user == project.user:
            form = ProjectForm(request.POST, instance=project)
        else:
            form = ProjectSecondaryForm(request.POST, instance=project)

        if form.is_valid():
            project = form.save()
            return redirect(
                reverse('show_project', kwargs={'project': project.label}))
    else:
        if request.user == project.user:
            form = ProjectForm(instance=project)
            form.fields['admin_group'].queryset = request.user.profile\
                                                         .managed_groups.all()
        else:
            form = ProjectSecondaryForm(
                instance=project,
                initial=dict(admin_group=project.admin_group),
            )

    data['form'] = form
    data['project'] = project
    return render(request, 'projects/update.html', data)
Esempio n. 2
0
File: views.py Progetto: derks/dmirr
def create(request):
    data = {}
    if request.method == 'POST':
        if not session_is_owner(request):
            return Http403
            
        form = ProjectForm(request.POST)
        if form.is_valid():
            project = form.save()
            
            return redirect(reverse('show_project',
                                    kwargs={'project': project.label}))                                
    else:
        form = ProjectForm(initial=dict(user=request.user))

    form.fields['admin_group'].queryset = request.user.profile\
                                                 .managed_groups.all()    
    data['form'] = form    
    return render(request, 'projects/create.html', data)
Esempio n. 3
0
File: views.py Progetto: derks/dmirr
def update(request, project):
    data = {}
    project = get_object_or_404(db.Project, label=project)
    
    if request.method == 'POST':
        if request.user == project.user:
            form = ProjectForm(request.POST, instance=project)
        else:
            form = ProjectSecondaryForm(request.POST, instance=project)
            
        if form.is_valid():
            project = form.save()
            return redirect(reverse('show_project',
                                    kwargs={'project': project.label}))                                
    else:
        if request.user == project.user:
            form = ProjectForm(instance=project)
            form.fields['admin_group'].queryset = request.user.profile\
                                                         .managed_groups.all()    
        else:
            form = ProjectSecondaryForm(
                instance=project,            
                initial=dict(admin_group=project.admin_group),
                )

    data['form'] = form   
    data['project'] = project 
    return render(request, 'projects/update.html', data)
Esempio n. 4
0
def create(request):
    data = {}
    if request.method == 'POST':
        if not session_is_owner(request):
            return Http403

        form = ProjectForm(request.POST)
        if form.is_valid():
            project = form.save()

            return redirect(
                reverse('show_project', kwargs={'project': project.label}))
    else:
        form = ProjectForm(initial=dict(user=request.user))

    form.fields['admin_group'].queryset = request.user.profile\
                                                 .managed_groups.all()
    data['form'] = form
    return render(request, 'projects/create.html', data)