Пример #1
0
def save(request, object_id=None, save_person=True, is_student=False):

    if is_student: # verify if student can join in service
        for ps in request.POST.getlist('professional_service'):
            if not Service.objects.filter(active=True, organization=request.user.get_profile().org_active, academic_related=True, pk=ps):
                return render_to_response('403.html', {'object': _("Oops! You don't have access for this service!"), }, context_instance=RequestContext(request))

    object, list_to_remove = save_careprof(request, object_id, save_person, is_student)

    if is_student:
        student_form = StudentProfileForm(request.POST, instance=object.studentprofile) if object_id else StudentProfileForm(request.POST)
        if student_form.is_valid():
            data = student_form.save(commit=False)
            data.professional = object
            data.save()

    # one of service have referral and can't be removed from professional.
    if list_to_remove:

        # msg error
        for x in list_to_remove:
            try:
                msg += u', %s' % x.name
            except:
                msg = u'%s' % x.name

        # english error message
        #messages.error(request, _('Impossible discharged of the service. Exist referral to this professional. Service(s) <br /> %s' % msg ))
        #return HttpResponseRedirect(('/careprofessional/%s/' % object.id))

        messages.error(request, _(u'Serviço não pode ser desligado. Existe inscrição para esse profissional. Serviço<br />%s' % msg ))
        return HttpResponseRedirect(('/careprofessional/%s/' % object.id))
    else:
        messages.success(request, _('Professional saved successfully') if not is_student else _('Student saved successfully'))
        return HttpResponseRedirect(('/careprofessional/%s/' % object.id) if not is_student else ('/careprofessional/student/%s/' % object.id))
Пример #2
0
def save(request, object_id=None, save_person=True, is_student=False):

    if is_student:  # verify if student can join in service
        for ps in request.POST.getlist('professional_service'):
            if not Service.objects.filter(
                    active=True,
                    organization=request.user.get_profile().org_active,
                    academic_related=True,
                    pk=ps):
                return render_to_response(
                    '403.html', {
                        'object':
                        _("Oops! You don't have access for this service!"),
                    },
                    context_instance=RequestContext(request))

    object, list_to_remove = save_careprof(request, object_id, save_person,
                                           is_student)

    if is_student:
        student_form = StudentProfileForm(
            request.POST, instance=object.studentprofile
        ) if object_id else StudentProfileForm(request.POST)
        if student_form.is_valid():
            data = student_form.save(commit=False)
            data.professional = object
            data.save()

    # one of service have referral and can't be removed from professional.
    if list_to_remove:

        # msg error
        for x in list_to_remove:
            try:
                msg += u', %s' % x.name
            except:
                msg = u'%s' % x.name

        # english error message
        #messages.error(request, _('Impossible discharged of the service. Exist referral to this professional. Service(s) <br /> %s' % msg ))
        #return HttpResponseRedirect(('/careprofessional/%s/' % object.id))

        messages.error(
            request,
            _(u'Serviço não pode ser desligado. Existe inscrição para esse profissional. Serviço<br />%s'
              % msg))
        return HttpResponseRedirect(('/careprofessional/%s/' % object.id))
    else:
        messages.success(
            request,
            _('Professional saved successfully')
            if not is_student else _('Student saved successfully'))
        return HttpResponseRedirect(('/careprofessional/%s/' %
                                     object.id) if not is_student else (
                                         '/careprofessional/student/%s/' %
                                         object.id))
Пример #3
0
def form(request, object_id=None, template_name='careprofessional/careprofessional_form.html', is_student = False):
    if object_id:
        object = get_object_or_404(CareProfessional, pk=object_id, person__organization=request.user.get_profile().org_active)
    else:
        if not request.user.has_perm('careprofessional.careprofessional_write'):
            return render_to_response('403.html', {'object': _("Oops! You don't have access for this service!"), }, context_instance=RequestContext(request))

        object = CareProfessional()

    try:
        cities = City.objects.filter(state=request.user.get_profile().org_active.address.all()[0].city.state)
    except:
        cities = {}

    if is_student:
        student_form = StudentProfileForm(instance=object.studentprofile) if object_id else StudentProfileForm()
        ServiceTypes = Service.objects.filter( active=True, organization=request.user.get_profile().org_active, academic_related=True )
    else:
        ServiceTypes = Service.objects.filter( active=True, organization=request.user.get_profile().org_active)

    if not object.active:
        messages.success(request,  _('This professional is not enabled.'))

    return render_to_response(template_name, {
                                    'clss':request.GET.get('clss'),
                                    'object': object,
                                    'student_form': student_form if is_student else None,
                                    'phones' : None if not hasattr(object, 'person') else object.person.phones.all(),
                                    'addresses' : None if not hasattr(object, 'person') else object.person.address.all(),
                                    'documents' : None if not hasattr(object, 'person') else object.person.document.all(),
                                    'emails' : None if not hasattr(object, 'person') else object.person.emails.all(),
                                    'websites' : None if not hasattr(object, 'person') else object.person.sites.all(),
                                    'ims' : None if not hasattr(object, 'person') else object.person.instantMessengers.all(),
                                    'PROFESSIONAL_AREAS': Profession.objects.all(),
                                    'AgreementTypes': Agreement.objects.all(),
                                    'WorkPlacesTypes': Place.objects.active().filter(organization = request.user.get_profile().org_active.id),
                                    'countries': Country.objects.all(),
                                    'PhoneTypes': PhoneType.objects.all(),
                                    'AddressTypes': AddressType.objects.all(),
                                    'EmailTypes': EmailType.objects.all(),
                                    'IMNetworks': IMNetwork.objects.all() ,
                                    'TypeDocuments': TypeDocument.objects.all(),
                                    'Issuers': Issuer.objects.all(),
                                    'States': State.objects.all(),
                                    'MaritalStatusTypes': MaritalStatus.objects.all(),
                                    'PlaceTypes': PlaceType.objects.all(),
                                    'ServiceTypes': ServiceTypes,
                                    'Cities': cities,
                                    'ReferralDischargeReason': None if not object.have_referral_charged else ReferralDischargeReason.objects.all(),
                                    },
                              context_instance=RequestContext(request)
                              )
Пример #4
0
def save(request, object_id=None, save_person=True, is_student=False):
    
    if is_student: # verify if student can join in service
        for ps in request.POST.getlist('professional_service'):
            if not Service.objects.filter(active=True, organization=request.user.get_profile().org_active, academic_related=True, pk=ps):
                return render_to_response('403.html', {'object': _("Oops! You don't have access for this service!"), }, context_instance=RequestContext(request))

    object = save_careprof(request, object_id, save_person, is_student)
    clss = request.GET.get('clss')
    #exist_referral = object[1]
    #object = object[0]
    if is_student:
        student_form = StudentProfileForm(request.POST, instance=object.studentprofile) if object_id else StudentProfileForm(request.POST)
        if student_form.is_valid():
            data = student_form.save(commit=False)
            data.professional = object
            data.save()

    #if exist_referral == "False":
        #messages.success(request, _('Professional saved successfully') if not is_student else _('Student saved successfully'))
        #return HttpResponseRedirect(('/careprofessional/%s/' % object.id) if not is_student else ('/careprofessional/student/%s/' % object.id))
    messages.success(request, _('Professional saved successfully') if not is_student else _('Student saved successfully'))
    return HttpResponseRedirect(('/careprofessional/%s/' % object.id) if not is_student else ('/careprofessional/student/%s/' % object.id))