def save(self, request, client, *args, **kwargs): company_client = super(CompanyClientForm, self).save(commit=False, *args, **kwargs) company_client.company = client.person.company if not request.POST.get( 'client_id' ): # client and person is new, lets create it before person = Person(name=request.POST.get('name')) person.save() person.organization.add(request.user.get_profile().org_active.id) client_related = Client( person=person, idRecord=request.user.get_profile().org_active.last_id_record + 1) client_related.save() company_client.active = True else: # client already exist, let's create or edit some existing relation if not request.POST.get('client_id') in [ i.client.id for i in client.person.company.companyclient_set.all() ] and not request.POST.get( 'active'): # relation already exists, let's edit it company_client.active = True client_related = Client.objects.get( pk=request.POST.get('client_id'), person__organization=request.user.get_profile().org_active) company_client.client = client_related company_client.responsible = False if not request.POST.get( 'responsible') else True company_client.save() return company_client
def save(self, request, client, *args, **kwargs): company_client = super(CompanyClientForm, self).\ save(commit=False, *args, **kwargs) company_client.company = client.person.company # client and person is new, lets create it before if not request.POST.get('client_id'): person = Person(name=request.POST.get('name')) person.save() person.organization.add(request.user.get_profile().org_active.id) client_related = Client(person=person, idRecord=request.user.get_profile(). org_active.last_id_record + 1) client_related.save() company_client.active = True # client already exist, let's create or edit some existing relation else: # relation already exists, let's edit it if not request.POST.get('client_id') in [ i.client.id for i in client.person.company. companyclient_set.all()]\ and not request.POST.get('active'): company_client.active = True client_related = Client.objects.get(pk=request.POST.get( 'client_id'), person__organization=request. user.get_profile().org_active) company_client.client = client_related company_client.responsible = False if not request.POST.get( 'responsible') else True company_client.save() return company_client
def save_mini_professional(request): object = CareProfessional() person = Person() person.name = request.POST.get('label') person.save() person.organization.add(Organization.objects.get(pk=request.POST.get('organization'))) object.person = person object.save() return HttpResponse("%s" % (object.id))
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()
def save_mini_professional(request): object = CareProfessional() person = Person() person.name = request.POST.get('label') person.save() person.organization.add( Organization.objects.get(pk=request.POST.get('organization'))) object.person = person object.save() return HttpResponse("%s" % (object.id))
def setUp(self): self.factory = RequestFactory() p = Person() User.objects.create(username="******", password="******") p.user = User.objects.get(username="******") p.save() client = Client(person=p, idRecord=1) client.save() self.person = Person.objects.get(user_id=p.user.id)
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()
def setUp(self): tobias = User() joaquim = Person() mcdonalds = Organization() self.perfil = Profile() self.perfil.user = tobias tobias.username = "******" self.perfil.pk = 99 mcdonalds.pk = 12 joaquim.pk = 44 self.perfil.org_active = mcdonalds self.perfil.person = joaquim self.perfil._set_temp("abacate")
def save(self, request, client, *args, **kwargs): family = super(FamilyForm, self).save(*args, **kwargs) family.client = client if request.POST.get('client_id'): # existing client client_related = Client.objects.filter(pk=request.POST.get('client_id'), person__organization = request.user.get_profile().org_active)[0] else: # client and person is new, lets create it before person = Person(name=request.POST.get('name')) person.save() person.organization.add(request.user.get_profile().org_active.id) client_related = Client(person=person, idRecord = request.user.get_profile().org_active.last_id_record + 1) client_related.save() family.client_related = client_related family.save() return family
def contact_professional_save(request, object_id=None): try: object = get_object_or_404(CareProfessional, pk=object_id) identification = object.professionalIdentification person = object.person except: object = CareProfessional() person = Person() if object.id and not have_careprofessional_perms_save(request, object): return render_to_response('403.html', { 'object': _("Access Denied"), }, context_instance=RequestContext(request)) if not request.POST.get('name'): return HttpResponseRedirect( ('/contact/form/professional/' if not object.id else ('/contact/form/professional/%s/') % object.id)) if not object.professionalIdentification: if request.POST.get('symbol'): identification = ProfessionalIdentification() identification.profession = Profession.objects.get( id=request.POST.get('service_profession')) identification.registerNumber = request.POST.get( 'professional_subscription') identification.save() object.professionalIdentification = identification else: object.professionalIdentification = None person.name = request.POST.get('name') person.save() person.organization.remove() person.organization.add( Organization.objects.get(pk=request.POST.get('organization'))) person = extra_data_save(request, person) object.comments = request.POST.get('comments') object.person = person object.save() messages.success(request, _('Professional contact saved successfully')) return HttpResponseRedirect('/contact/form/professional/%s/' % (object.id))
def save(request, object_id=None): """ This function view saves an employees, its address and phones. @param request: this is a request sent by the browser. @type request: an instance of the class C{HttpRequest} created by the framework Django. @param object_id: it is the I{id} of the employee that must be saved. @type object_id: an instance of the built-in type C{int}. """ if object_id: object = get_object_or_404( Employee, pk=object_id, person__organization=request.user.get_profile().org_active) person = object.person else: object = Employee() person = Person() object.person = person_save(request, person) object.job = request.POST['job'] if (request.POST['hiredate']): object.hiredate = datetime.strptime(request.POST['hiredate'], '%d/%m/%Y') object.save() messages.success(request, _('Employee saved successfully')) return HttpResponseRedirect('/employee/%s/' % object.id)
def setUp(self): self.person = Person(name="personTest") uuidField = UuidField(verbose_name="verbose_name_Test", name="nameTest") self.employee = Employee(person=self.person, hiredate="HiredateTest", job="JobTest", active=True) self.hiredate = "hiredateTest" self.job = "jobTest" self.active = False
def contact_professional_save(request, object_id=None): try: object = get_object_or_404(CareProfessional, pk=object_id) identification = object.professionalIdentification person = object.person except: object = CareProfessional() person = Person() if object.id and not have_careprofessional_perms_save(request, object): return render_to_response('403.html', {'object': _("Access Denied"), }, context_instance=RequestContext(request)) if not request.POST.get('name'): return HttpResponseRedirect(('/contact/form/professional/' if not object.id else ('/contact/form/professional/%s/') % object.id)) if not object.professionalIdentification: if request.POST.get('symbol'): identification = ProfessionalIdentification() identification.profession = Profession.objects.get( id=request.POST.get('service_profession')) identification.registerNumber = request.POST.get( 'professional_subscription') identification.save() object.professionalIdentification = identification else: object.professionalIdentification = None person.name = request.POST.get('name') person.save() person.organization.remove() person.organization.add(Organization.objects.get( pk=request.POST.get('organization'))) person = extra_data_save(request, person) object.comments = request.POST.get('comments') object.person = person object.save() messages.success(request, _('Professional contact saved successfully')) return HttpResponseRedirect('/contact/form/professional/%s/' % (object.id))
def setUp(self): person = Person() User.objects.create(username="******", password="******") person.user = User.objects.get(username="******") person.birthDate = "1990-05-14" person.birthForeignCity = "Melbourne" person.birthForeignState = "Victoria" person.birthForeignCountry = '1' person.save() contentType = ContentType() contentType.app_label = "auth" contentType.model = "any" contentType.save() emailType = EmailType() emailType.description = "Email Type" emailType.save() email = Email() email.email = "*****@*****.**" email.email_type = EmailType.objects.all()[0] email.content_object = person email.save() site = Site() site.description = "this is a website" site.site = "www.google.com.br" site.content_object = person site.save() person.save() self.p = Person.objects.get(user_id=person.user.id) def tearDown(self): for person in Person.objects.all(): person.delete() for user in User.objects.all(): user.delete()
def save(self, request, client, *args, **kwargs): family = super(FamilyForm, self).save(*args, **kwargs) family.client = client if request.POST.get('client_id'): # existing client client_related = Client.objects.filter( pk=request.POST.get('client_id'), person__organization=request.user.get_profile().org_active)[0] else: # client and person is new, lets create it before person = Person(name=request.POST.get('name')) person.save() person.organization.add(request.user.get_profile().org_active.id) client_related = Client( person=person, idRecord=request.user.get_profile().org_active.last_id_record + 1) client_related.save() family.client_related = client_related family.save() return family
def setUp(self): self.person = Person(name="tested person") self.care_professional_manager = CareProfessionalManager() self.availability = Availability self.availability.day = "1" self.availability.hour = "5" self.care_professional = CareProfessional( person=self.person, objects=self.care_professional_manager, availability=self.availability)
def setUp(self): self.person = Person(name="tested person") self.care_professional_manager = CareProfessionalManager() self.availability = Availability() self.availability.day = "1" self.availability.hour = "2010-03-27" self.care_professional = CareProfessional( objects=self.care_professional_manager, availability=self.availability) #self.care_professional.person = self.person #self.care_professional.objects = self.care_professional_manager #self.care_professional.availability = self.availability self.professional = self.care_professional self.expected_professional = "tested person"
def save_careprof(request, object_id, save_person, is_student=False): """ This view function returns the informations about CareProfessional @param request: this is a request sent by the browser. @type request: a instance of the class C{HttpRequest} created by the framework Django @param object: it is the tyoe of CareProfessional that must be filled. @type object: an instance of the built-in type C{CareProfessional}. """ if object_id: object = get_object_or_404( CareProfessional, pk=object_id, person__organization=request.user.get_profile().org_active) else: object = CareProfessional() if save_person: object.person = person_save( request, get_object_or_None(Person, pk=object.person_id) or Person()) object.save() ''' remove service before add check if service have referral before remove. cannot be removed if have referral. ''' # all service that are in list_service cannot be removed because it have referral. Create a error message for service and show to user. list_to_remove = [] # remove service, compare from form and db. for x in object.prof_services.all(): # professional if not x.id in request.POST.getlist('professional_service'): # check referral if Referral.objects.charged().filter(professional=object, service=x, status='01'): list_to_remove.append(x) # add to msg else: object.prof_services.remove(x) # remove from professional # add new service to professional for x in request.POST.getlist('professional_service'): object.prof_services.add(x) # no problem to replace profile = get_object_or_None( ProfessionalProfile, pk=object.professionalProfile_id) or ProfessionalProfile() profile.initialProfessionalActivities = request.POST.get( 'professional_initialActivitiesDate') profile.save() object.professionalProfile = profile # remove all workplace profile.workplace.clear() # update workplace for x in request.POST.getlist('professional_workplace'): profile.workplace.add( Place.objects.get( pk=x, organization=request.user.get_profile().org_active)) if not is_student: if request.POST.get('professional_registerNumber') or request.POST.get( 'professional_area'): if not object.professionalIdentification: identification = ProfessionalIdentification() else: identification = object.professionalIdentification if request.POST.get('professional_registerNumber'): identification.registerNumber = request.POST.get( 'professional_registerNumber') if request.POST.get('professional_area'): identification.profession = get_object_or_None( Profession, id=request.POST.get('professional_area')) identification.save() object.professionalIdentification = identification object.save() return object, list_to_remove
def save_careprof(request, object_id, save_person, is_student=False): """ This view function returns the informations about CareProfessional @param request: this is a request sent by the browser. @type request: a instance of the class C{HttpRequest} created by the framework Django @param object: it is the tyoe of CareProfessional that must be filled. @type object: an instance of the built-in type C{CareProfessional}. """ if object_id: object = get_object_or_404(CareProfessional, pk=object_id, person__organization=request.user.get_profile().org_active) else: object = CareProfessional() if save_person: object.person = person_save(request, get_object_or_None(Person, pk=object.person_id) or Person()) object.save() #exist_referral="False" list_from_form = request.POST.getlist('professional_service') # MAKE A LIST WHIT ID SERVICE list_db = [] for y in object.prof_services.filter(organization=request.user.get_profile().org_active): list_db.append(y.id) # IF LIST_FROM_FORM > 0 THEN ADDED SERVICE if len(list_from_form) > 0: for ps_id in list_from_form: ps = Service.objects.get(pk=ps_id) object.prof_services.add(ps) # COMPARES THE LIST_DB AND LIST_FORM, THE RESULT WILL BE SERVICES THAT WILL BE REMOVED if len(list_from_form) > 0: for x in list_from_form: try: indice = list_db.remove(x) except: pass ## REMOVE SERVICE #if len(list_db) > 0: #for o in list_db: #if Referral.objects.charged().filter(professional = object, service = o, status = '01').count() > 0: #exist_referral="True" #else: #object.prof_services.remove(o) profile = get_object_or_None(ProfessionalProfile, pk=object.professionalProfile_id) or ProfessionalProfile() profile.initialProfessionalActivities = request.POST.get('professional_initialActivitiesDate') profile.save() object.professionalProfile = profile if (len(request.POST.getlist('professional_workplace'))): for o in profile.workplace.filter(organization=request.user.get_profile().org_active): profile.workplace.remove(o) for wplace_id in request.POST.getlist('professional_workplace'): profile.workplace.add(Place.objects.get(pk=wplace_id)) if not is_student: if (len(request.POST.getlist('professional_agreement'))): profile.agreement.clear() for agreemt_id in request.POST.getlist('professional_agreement'): profile.agreement.add(Agreement.objects.get(pk=agreemt_id)) if request.POST.get('professional_registerNumber') or request.POST.get('professional_area'): if not object.professionalIdentification: identification = ProfessionalIdentification() else: identification = object.professionalIdentification if request.POST.get('professional_registerNumber'): identification.registerNumber = request.POST.get('professional_registerNumber') if request.POST.get('professional_area'): identification.profession = get_object_or_None(Profession, id=request.POST.get('professional_area')) identification.save() object.professionalIdentification = identification object.save() return object