Exemple #1
0
def update(request, system):
    data = {}
    system = get_object_or_404(db.System, label=system)
    if request.method == 'POST':
        if request.user == system.user:
            form = SystemForm(request.POST, instance=system)
        else:
            form = SystemSecondaryForm(request.POST, instance=system)

        if form.is_valid():
            system = form.save()
            return redirect(
                reverse('show_system', kwargs=dict(system=system.label)))
    else:
        if request.user == system.user:
            form = SystemForm(instance=system)
            form.fields['admin_group'].queryset = request.user.profile\
                                                         .managed_groups.all()
        else:
            form = SystemSecondaryForm(
                instance=system,
                initial=dict(admin_group=system.admin_group),
            )

    data['form'] = form
    data['system'] = system
    return render(request, 'systems/update.html', data)
Exemple #2
0
def create(request):
    data = {}
    if request.method == 'POST':
        form = SystemForm(request.POST)
        if form.is_valid():
            system = form.save()
            
            return redirect(reverse('show_system', 
                            kwargs=dict(system=system.label)))
    else:
        form = SystemForm(initial=dict(user=request.user))
        
    form.fields['admin_group'].queryset = request.user.profile\
                                                 .managed_groups.all()    
    data['form'] = form    
    return render(request, 'systems/create.html', data)
Exemple #3
0
def update(request, system):
    data = {}
    system = get_object_or_404(db.System, label=system)
    if request.method == 'POST':
        if request.user == system.user:
            form = SystemForm(request.POST, instance=system)
        else:
            form = SystemSecondaryForm(request.POST, instance=system)
            
        if form.is_valid():
            system = form.save()
            return redirect(reverse('show_system', 
                            kwargs=dict(system=system.label)))
    else:
        if request.user == system.user:
            form = SystemForm(instance=system)
            form.fields['admin_group'].queryset = request.user.profile\
                                                         .managed_groups.all()    
        else:
            form = SystemSecondaryForm(
                instance=system,            
                initial=dict(admin_group=system.admin_group),
                )
        
    data['form'] = form   
    data['system'] = system 
    return render(request, 'systems/update.html', data)
Exemple #4
0
def create(request):
    data = {}
    if request.method == 'POST':
        form = SystemForm(request.POST)
        if form.is_valid():
            system = form.save()

            return redirect(
                reverse('show_system', kwargs=dict(system=system.label)))
    else:
        form = SystemForm(initial=dict(user=request.user))

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