Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
def form(request):
    form = StudyForm()
    if form.is_valid():
        message = "データの検証に成功しました。"
    else:
        message = "データの検証に失敗しました。"
    context = {
        "form":form,
        'message' : message,
    }
    return render(request,"mysite/index.html",context )
Ejemplo n.º 3
0
def new_study(request):
    if request.method == 'POST':
        sform = StudyForm(request.POST, instance=Study())
        if sform.is_valid():
            sform.save()
        return HttpResponseRedirect('/viewer/study/')
    else:
        sform = StudyForm(instance=Study())
        context = {'study_form': sform}
        context.update(csrf(request))
        return render_to_response('viewer/study/new_study.html', context,
                                  context_instance=RequestContext(request))
Ejemplo n.º 4
0
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('/viewer/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))
Ejemplo n.º 5
0
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))
Ejemplo n.º 6
0
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))
Ejemplo n.º 7
0
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))
Ejemplo n.º 8
0
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))
Ejemplo n.º 9
0
def create_study(request):
    """
        create a new study for the given instution
    """

    if request.method == 'POST':
        institution_pk = request.POST['institution']
        institution = Institution.objects.get(pk=institution_pk)
        test = request.POST.getlist('managers')
        if request.user.id not in request.POST.getlist('managers'):
            request.POST.appendlist('managers', unicode(request.user.id))

        form = StudyForm(usersset=institution.user_set.all(), data=request.POST, initial={'institution': institution_pk})

        if form.is_valid():
            study = form.save(commit=False)
            study.save()
            return redirect('/groups/%s/%s/' % (request.POST['institution'], form.instance.id))
        else:
            institution = Institution.objects.get(pk=request.POST['institution'])
            return render_to_response(
                'scs_groups/createstudy.html',
                {'form': form,
                 'institution': institution},
                RequestContext(request)
            )
    else:
        institution_pk = request.GET['institution']
        institution = Institution.objects.get(pk=institution_pk)
        if not request.user in institution.managers.all():
            return redirect('/groups/%s/' % institution_pk)

        form = StudyForm(usersset=institution.user_set.all(),  initial={'institution': institution_pk})
        form.Meta.model.institution = institution

        return render_to_response(
            'scs_groups/createstudy.html',
            {'form': form,
             'institution': institution},
            RequestContext(request)
        )
Ejemplo n.º 10
0
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))