Esempio n. 1
0
 def obj_create(self, bundle, **kwargs):
     try:
         data = bundle.data
         user = bundle.request.user
         if user.is_anonymous():
             user = None
         if len(contact_is_valid(bundle)) > 0:
             raise BadRequest(contact_is_valid(bundle))
         print "user2 %s" % user
         data['dob'] = data['dob'] or None if 'dob' in data.keys(
         ) else None  # Empty string no good
         agencyId = data['agencyId']
         del data['agencyId']
         emails = [
             EmailAddress.get_or_create(email)[0]
             for email in data['emails'] if email
         ]
         map(lambda x: x.save(), emails)
         notes = [Note(content=data['notes'], user=user)]
         del data['notes']
         map(lambda x: x.save(), notes)
         titles = [
             Title(content=title) for title in data['titles'] if title
         ]
         del data['titles']
         map(lambda x: x.save(), titles)
         del data['emails']
         phone_numbers = [
             Phone(content=phone) for phone in data['phone_numbers']
             if phone
         ]
         del data['phone_numbers']
         map(lambda x: x.save(), phone_numbers)
         addresses = [
             Address(content=address) for address in data['addresses']
             if address
         ]
         map(lambda x: x.save(), addresses)
         del data['addresses']
         agency = Agency.objects.get(id=agencyId)
         thecontact = Contact(**data)
         thecontact.save()
         thecontact.titles = titles
         thecontact.emails = emails
         thecontact.phone_numbers = phone_numbers
         thecontact.addresses = addresses
         thecontact.notes = notes
         thecontact.agency_related_contacts = [agency]
         thecontact.creator = user
         thecontact.save()
         agency.save()
         bundle.obj = thecontact
         return bundle
     except Exception as e:
         logger.exception(e)
         raise BadRequest(str(e))
Esempio n. 2
0
 def obj_create(self, bundle, **kwargs):
     try:
         data = bundle.data
         user = bundle.request.user
         if user.is_anonymous():
             user = None
         if len(contact_is_valid(bundle)) > 0:
             raise BadRequest(contact_is_valid(bundle))
         print "user2 %s" % user
         data['dob'] = data['dob'] or None if 'dob' in data.keys() else None # Empty string no good
         agencyId = data['agencyId']
         del data['agencyId']
         emails = [EmailAddress.get_or_create(email)[0] for email in data['emails'] if email]
         map(lambda x: x.save(), emails)
         notes = [Note(content = data['notes'], user = user)]
         del data['notes']
         map(lambda x: x.save(), notes)
         titles = [Title(content = title) for title in data['titles'] if title]
         del data['titles']
         map(lambda x: x.save(), titles)
         del data['emails']
         phone_numbers = [Phone(content = phone) for phone in data['phone_numbers'] if phone]
         del data['phone_numbers']
         map(lambda x: x.save(), phone_numbers)
         addresses = [Address(content = address) for address in data['addresses'] if address]
         map(lambda x: x.save(), addresses)
         del data['addresses']
         agency = Agency.objects.get(id=agencyId)
         thecontact = Contact(**data)
         thecontact.save()
         thecontact.titles = titles
         thecontact.emails = emails
         thecontact.phone_numbers = phone_numbers
         thecontact.addresses = addresses
         thecontact.notes = notes
         thecontact.agency_related_contacts = [agency]
         thecontact.creator = user
         thecontact.save()
         agency.save()
         bundle.obj = thecontact
         return bundle
     except Exception as e:
         logger.exception(e)
         raise BadRequest (str(e))