Пример #1
0
def script_new(request):
    ParamFormSet = formset_factory(ParamForm, can_delete = True )
    if request.method == 'POST':
        script_form = ScriptForm( request.POST )
        param_formset = ParamFormSet( data = request.POST, prefix='param')
        
        if script_form.is_valid() and param_formset.is_valid():
            script = script_form.save()
            for parameter_data in param_formset.cleaned_data:
                if parameter_data:
                    parameter = Parameter.objects.create( **parameter_data )
                    script.parameters.add( parameter )
            script.save()
            
            info_msg(request, 'Script added successfully')
            
            if 'save_and_add' in request.POST.keys():
                return redirect('script_new')
            else:            
                return redirect('script_list')
    else:
        script_form = ScriptForm()
        param_formset = ParamFormSet( prefix='param' )
    
    return render(request, 'script_new.html', {
        'form'   : script_form,
        'formset': param_formset,
    })
Пример #2
0
def section_new(request):
    data = request.POST.copy()
    data.update({
        'name': data['label'].lower().replace(' ', '_')
    })
    form = SectionForm( data = data )
    if form.is_valid():
        info_msg(request, "Category '%s' created successfully" % data['label'])
        form.save()
    return redirect('script_list')
Пример #3
0
def script_delete(request, script_id):
    script = get_object_or_404(Script, id = script_id)
    script.delete()
    
    info_msg(request, 'Script deleted successfully.')
    return redirect('script_list')