Ejemplo n.º 1
0
def setup_required_service():
    service_type = ServiceType()
    service_type.name = "Tipo de Servico"
    service_type.save()

    area1 = Area()
    area1.area_name = "area 1"
    area1.save()

    organization1 = Organization.objects.get(name=user_stub()["organization"])

    service1 = Service()
    service1.area = area1
    service1.name = "Servico 1"
    service1.organization = organization1
    service1.service_type = service_type
    service1.save()

    a = AdmissionChoice()
    a.weight = 1
    a.save()

    u = User()
    u.username = "******"
    u.password = "******"
    u.is_superuser = True
    u.save()

    person = Person()
    person.name = "nome12"
    person.user = u
    person.nickname = "apelido12"
    person.save()
    person.organization.add(organization1)
    person.save()
Ejemplo n.º 2
0
def setup_required_service():
    service_type = ServiceType()
    service_type.name="Tipo de Servico"
    service_type.save()

    area1 = Area()
    area1.area_name = "area 1"
    area1.save()

    organization1 = Organization.objects.get(name=user_stub()["organization"])

    service1 = Service()
    service1.area = area1;
    service1.name = "Servico 1"
    service1.organization = organization1
    service1.service_type = service_type
    service1.save()

    a = AdmissionChoice()
    a.weight = 1
    a.save()

    u = User()
    u.username = "******"
    u.password = "******"
    u.is_superuser = True
    u.save()

    person = Person()
    person.name = "nome12"
    person.user = u
    person.nickname = "apelido12"
    person.save()
    person.organization.add(organization1)
    person.save()
Ejemplo n.º 3
0
def select_area(request, object_id=''):
    object = get_object_or_404(Service,
                               pk=object_id,
                               organization=request.user.get_profile().
                               org_active) if object_id else Service()
    return render_to_response('service/select_area.html', {
        'areas': Area.objects.all(),
        'object': object,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 4
0
def save(request, object_id=''):

    object = get_object_or_404(Service,
                               pk=object_id,
                               organization=request.user.get_profile().
                               org_active) if object_id else Service()
    object.organization = request.user.get_profile().org_active
    object.name = request.POST.get('service_name')
    object.description = request.POST.get('service_description')
    object.keywords = request.POST.get('service_keywords')
    object.comments = request.POST.get('comments')
    object.academic_related = request.POST.get('academic_related') or False
    object.is_group = request.POST.get('is_group') or False
    object.is_online = request.POST.get('is_online') or False
    object.service_type = ServiceType.objects.get(
        pk=request.POST.get('service_type'))

    if not object_id:
        object.research_project = request.POST.get('research_project') or False
        object.research_project_name = request.POST.get(
            'research_project_name')
        object.area = Area.objects.get(pk=request.POST.get('service_area'))
    else:
        object.css_color_class = request.POST.get('service_css_color_class')

    object.color = request.POST.get('service_color')
    object.save()  # save object
    """ Responsibles list """
    object.responsibles.clear()
    for p in request.POST.getlist('service_responsibles'):
        object.responsibles.add(CareProfessional.objects.get(pk=p))
    """ Professions """
    object.professions.clear()
    for p in request.POST.getlist('service_profession'):
        object.professions.add(Profession.objects.get(pk=p))
    """ Modalities """
    object.modalities.clear()
    for m in request.POST.getlist('modalities'):
        object.modalities.add(Modality.objects.get(pk=m))
    """ Age Group """
    object.age_group.clear()
    for age in request.POST.getlist('age_group'):
        object.age_group.add(AgeGroup.objects.get(pk=age))
    """ Education Level """
    object.education_level.clear()
    for edu in request.POST.getlist('education_level'):
        object.education_level.add(EducationLevel.objects.get(pk=edu))
    """ Hierachical Level """
    object.hierarchical_level.clear()
    for hierarc in request.POST.getlist('hierarchical_level'):
        object.hierarchical_level.add(
            HierarchicalLevel.objects.get(pk=hierarc))
    """ Professionals list """
    object.professionals.clear()
    for p in request.POST.getlist('service_professionals'):
        object.professionals.add(CareProfessional.objects.get(pk=p))

    object.save()
    messages.success(request, _('Service saved successfully'))

    return HttpResponseRedirect('/service/form/%s/' % object.id)
Ejemplo n.º 5
0
def form(request, object_id=None):
    object = get_object_or_404(Service,
                               pk=object_id,
                               organization=request.user.get_profile().
                               org_active) if object_id else Service()
    selected_area = get_object_or_None(
        Area, area_code=request.POST.get('area')) or object.area

    if selected_area.area_code in GENERIC_AREA:
        form_area = GenericAreaForm(instance=object)
        form_area.fields['age_group'].queryset = selected_area.age_group.all()

    if selected_area.area_code in ('school', 'psychoedu'):
        form_area = SchoolAreaForm(instance=object)
        form_area.fields[
            'education_level'].queryset = selected_area.education_level.all()

    if selected_area.area_code == 'organizational':
        form_area = OrganizationalAreaForm(instance=object)
        form_area.fields[
            'hierarchical_level'].queryset = selected_area.hierarchical_level.all(
            )

    form_area.fields['service_type'].queryset = selected_area.service_type.all(
    )
    form_area.fields['modalities'].queryset = selected_area.modalities.all()

    # select a next color when new register
    if not object.pk:
        object.color = color_rand()
        #if not request.user.get_profile().org_active.service_set.all():
        #object.css_color_class = 1
        #else:
        #if not object.css_color_class:
        #object.css_color_class = (int(Service.objects.filter(organization=request.user.get_profile().org_active).latest('date').css_color_class) + 1) \
        #if int(Service.objects.filter(organization=request.user.get_profile().org_active).latest('date').css_color_class) <=24 \
        #else 1

    return render_to_response('service/service_form.html', {
        'object':
        object,
        'CareProfessionals':
        CareProfessional.objects.active(request.user.get_profile().org_active),
        'Students':
        CareProfessional.objects.students_active(
            request.user.get_profile().org_active),
        'AgeGroups':
        AgeGroup.objects.all(),
        'Areas':
        Area.objects.all(),
        'ServiceTypes':
        ServiceType.objects.all(),
        'Modalitys':
        Modality.objects.all(),
        'Professions':
        Profession.objects.all(),
        'area':
        selected_area,
        'form_area':
        form_area,
        'clss':
        request.GET.get('clss'),
        'client_list':
        _service_clients(request, object),
        'queue_list':
        _queue_list(request, object),
        'can_list_groups':
        False if not len(_group_list(request, object)) else True,
        'can_write_group':
        False if not _can_write_group(request, object) else True,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 6
0
def save(request, object_id=''):

    object = get_object_or_404(Service,
                               pk=object_id,
                               organization=request.user.get_profile().
                               org_active) if object_id else Service()
    object.organization = request.user.get_profile().org_active
    object.name = request.POST.get('service_name')
    object.description = request.POST.get('service_description')
    object.keywords = request.POST.get('service_keywords')
    object.comments = request.POST.get('comments')
    object.academic_related = request.POST.get('academic_related') or False
    object.is_group = request.POST.get('is_group') or False
    object.is_online = request.POST.get('is_online') or False
    object.service_type = ServiceType.objects.get(
        pk=request.POST.get('service_type'))

    if not object_id:
        object.research_project = request.POST.get('research_project') or False
        object.research_project_name = request.POST.get(
            'research_project_name')
        object.area = Area.objects.get(pk=request.POST.get('service_area'))
    else:
        object.css_color_class = request.POST.get('service_css_color_class')

    object.color = request.POST.get('service_color')
    object.save()  # save object
    """ Responsibles list """
    object.responsibles.clear()
    for p in request.POST.getlist('service_responsibles'):
        object.responsibles.add(CareProfessional.objects.get(pk=p))
    """ Professions """
    object.professions.clear()
    for p in request.POST.getlist('service_profession'):
        object.professions.add(Profession.objects.get(pk=p))
    """ Modalities """
    object.modalities.clear()
    for m in request.POST.getlist('modalities'):
        object.modalities.add(Modality.objects.get(pk=m))
    """ Age Group """
    object.age_group.clear()
    for age in request.POST.getlist('age_group'):
        object.age_group.add(AgeGroup.objects.get(pk=age))
    """ Education Level """
    object.education_level.clear()
    for edu in request.POST.getlist('education_level'):
        object.education_level.add(EducationLevel.objects.get(pk=edu))
    """ Hierachical Level """
    object.hierarchical_level.clear()
    for hierarc in request.POST.getlist('hierarchical_level'):
        object.hierarchical_level.add(
            HierarchicalLevel.objects.get(pk=hierarc))
    """ Professionals list """
    # remove professional before add professional
    # check referral before remove
    for x in object.professionals.all():  # from db
        if not x.id in request.POST.getlist('service_professionals'):
            # check if professional have referral in this service
            if Referral.objects.charged().filter(professional=x,
                                                 service=object,
                                                 status='01'):
                # to create msg erro
                try:
                    msg += u", %s" % x.person.name
                except:
                    msg = u"%s" % x.person.name
            # no referral, remove from list.
            else:
                object.professionals.remove(x)

    # erro msg
    try:
        messages.error(
            request,
            _(u'Profissional não pode ser desligado desse serviço. Existe inscrição para esse profissional. Profissional:<br /> %s'
              % msg))
    except:
        pass

    # add professional
    for p in request.POST.getlist('service_professionals'):
        object.professionals.add(CareProfessional.objects.get(pk=p))
    """ Covenant list """
    object.covenant.clear()
    for p in request.POST.getlist('service_covenant'):
        object.covenant.add(Covenant.objects.get(pk=p))

    object.save()
    messages.success(request, _('Service saved successfully'))

    return HttpResponseRedirect('/service/form/%s/' % object.id)