def edit_study(request, study_id): study = Study.objects.get(id=study_id) if request.method == 'GET': form = StudyForm(instance=study) return render_to_response('study.html', { 'r_id': study.requisition.id, 'id': study_id, 'form': form, 'editing': True }, context_instance=RequestContext(request)) if request.method == 'POST': form = StudyForm(request.POST, instance=study) if form.is_valid(): study = form.save() return redirect( reverse_lazy('studies:view_study', kwargs={'study_id': str(study_id)})) return render_to_response('study.html', { 'r_id': study.requisition.id, 'id': study_id, 'form': form, 'editing': True }, context_instance=RequestContext(request))
def edit_study(request, study_id): if request.method == 'POST': s = Study.objects.get(pk=study_id) updated_form = StudyForm(request.POST, instance=s) if updated_form.is_valid(): updated_form.save() return HttpResponseRedirect(reverse('manage_study')) else: study_obj = Study.objects.get(pk=study_id) sform = StudyForm(instance=study_obj) context = {'study_form': sform, 'name': study_obj.name, 'pk': study_obj.pk} context.update(csrf(request)) return render_to_response('viewer/study/edit_study.html', context, context_instance=RequestContext(request))
def new_study(request): if request.method == 'POST': sform = StudyForm(request.POST, instance=Study()) if sform.is_valid(): sform.save() return HttpResponseRedirect('/viewer/new_study/') else: sform = StudyForm(instance=Study()) context = {'study_form': sform} studies = Study.objects.all() context['studies'] = studies context.update(csrf(request)) return render_to_response('viewer/new_study.html', context, context_instance=RequestContext(request))
def new_study(request): if request.method == 'POST': sform = StudyForm(request.POST, instance=Study()) if sform.is_valid(): sform.save() return HttpResponseRedirect(reverse('manage_study')) else: project_pk = request.session.get('viewing_project', None) if project_pk is None: return HttpResponseRedirect(reverse('no_project')) sform = StudyForm(instance=Study(), initial={'project': project_pk}) context = { 'study_form': sform, 'project_name': Project.objects.get(pk=project_pk).name } context.update(csrf(request)) return render_to_response('viewer/study/new_study.html', context, context_instance=RequestContext(request))
def create_study(request, req_id=None): if request.method == 'GET': if req_id: form = StudyForm(initial={'requisition': req_id}) return render_to_response('study.html', { 'id': req_id, 'form': form }, context_instance=RequestContext(request)) else: form = StudyForm() return render_to_response('study.html', {'form': form}, context_instance=RequestContext(request)) if request.method == 'POST': form = StudyForm(request.POST, request.FILES) if form.is_valid(): study = form.save() if request.FILES: study.attachment = request.FILES.get('attachment') study.save() study.requisition.status = 'P' study.requisition.save() notificate_assignation(study.employee, study.id) return redirect(reverse_lazy('studies:home')) return render_to_response('study.html', { 'id': req_id, 'form': form }, context_instance=RequestContext(request))