def new_dynamic(request): """ Step 1 Set basic configurations. """ if request.method == 'POST': dynamic_form = DynamicForm(request.POST) if dynamic_form.is_valid(): new_dynamic = dynamic_form.save(commit=False) new_dynamic.user = request.user new_dynamic.save() request.session['dynamic_id'] = new_dynamic.id return HttpResponseRedirect('/dynamics/attach-molecules') else: context = { 'dynamic_form': dynamic_form, } return render(request, 'dynamics/new_dynamic.html', context) # if dynamic_id is None: context = { 'dynamic_form': DynamicForm(), } # else: # dynamic = Dynamic.objects.get(pk=dynamic_id) # dynamic_form = DynamicForm(instance=dynamic) # dynamic_form.fields['box_size'].disabled = True # dynamic_form.fields['number_of_molecules'].label = 'Number of molecules to be added' # dynamic_form.fields['number_of_atoms_for_alignment'].disabled = True # context = { # 'dynamic_form': dynamic_form, # } return render(request, 'dynamics/new_dynamic.html', context)
def test_invalid_form(self): ''' Form must be invalid ''' data = {} form = DynamicForm(data) self.assertFalse(form.is_valid())
def test_valid_form(self): ''' Form must be valid ''' data = { 'email': '*****@*****.**', 'box_size': 10, } form = DynamicForm(data) self.assertTrue(form.is_valid())
def new_dynamic(request): """ Step 1 Set basic configurations. """ if request.method == 'POST': dynamic_form = DynamicForm(request.POST) if dynamic_form.is_valid(): new_dynamic = dynamic_form.save() request.session['dynamic_id'] = new_dynamic.id return HttpResponseRedirect('/dynamics/attach-molecules') else: context = { 'dynamic_form': dynamic_form, } return render(request, 'dynamics/new_dynamic.html', context) context = { 'dynamic_form': DynamicForm(), } return render(request, 'dynamics/new_dynamic.html', context)