Esempio n. 1
0
    def save(self, *args, **kwargs):
        # check the args.  While the admin interface sends the user ID for the creator, the mobile app is giving us
        # the username.  So we have to detect which it is.  Note that we cannot accept NULL/no value for create_by

        # Customized the save method to update change history
        # if the private key is not null then the person exists, otherwise don't bother checking
        existing_person = bool(self.pk)
        # Put the current date/time in the updated_at field so we know when it was done
        self.updated_at = datetime.datetime.now()
        # Add site_details to person
        self.site_details = str('http://' + helpers.get_network_ip() +
                                '/persons/')
        # go ahead and save the changes
        super(Person, self).save(*args,
                                 **kwargs)  # Save the Person data to the DB
        # Finish site_details (ID was added after save)
        self.site_details += str(self.id) + '/'
        super(Person, self).save(*args,
                                 **kwargs)  # Save the Person data to the DB
        # First, check if we have a new geometry, if so then store it in location history, which we do
        # if the record is new or updated
        self.add_location_history()
        # TODO: if other fields have changed then log in the change history table
        if existing_person:
            self.add_field_history()
Esempio n. 2
0
 def save_model(self, request, obj, form, change):
     obj.uuid = str(uuid.uuid4()).decode(
         'unicode-escape'
     )  # Make new uuid for person (important for versioning)
     obj.site_details = str('http://' + helpers.get_network_ip() +
                            '/persons/')
     return super(PersonAdmin, self).save_model(request, obj, form, change)
Esempio n. 3
0
    def save(self, *args, **kwargs):
        # check the args.  While the admin interface sends the user ID for the creator, the mobile app is giving us
        # the username.  So we have to detect which it is.  Note that we cannot accept NULL/no value for create_by

        # Customized the save method to update change history
        # if the private key is not null then the person exists, otherwise don't bother checking
        existing_person = bool(self.pk)
        # Put the current date/time in the updated_at field so we know when it was done
        self.updated_at = datetime.datetime.now()
        # Add site_details to person
        self.site_details = str('http://' + helpers.get_network_ip() + '/persons/')
        # go ahead and save the changes
        super(Person, self).save(*args, **kwargs)  # Save the Person data to the DB
        # Finish site_details (ID was added after save)
        self.site_details += str(self.id) + '/'
        super(Person, self).save(*args, **kwargs)  # Save the Person data to the DB
        # First, check if we have a new geometry, if so then store it in location history, which we do
        # if the record is new or updated
        self.add_location_history()
        # TODO: if other fields have changed then log in the change history table
        if existing_person:
            self.add_field_history()
Esempio n. 4
0
 def save_model(self, request, obj, form, change):
     obj.uuid = str(uuid.uuid4()).decode(
         'unicode-escape')  # Make new uuid for shelter
     obj.site_details = str('http://' + helpers.get_network_ip() +
                            '/shelters/')
     return super(ShelterAdmin, self).save_model(request, obj, form, change)
Esempio n. 5
0
    def auto_populate(self, request, **kwargs):
        # method check to avoid bad requests
        self.method_check(request, allowed=['get'])

        files = os.listdir('/vida/samples/photos/')

        res = {'Status': 'Pictures Uploaded: '}

        # reset the OpenBR Gallery
        if os.path.isfile(get_gallery_file()):
            os.remove(get_gallery_file())

        ctr = 0
        length = files.__len__()
        with open('/vida/samples/MOCK_DATA.json') as personDB:
            _personDB = json.load(personDB)
            db_size = len(_personDB) - 1 # indexing
            person_index = 0
            for file in files:
                with open('/vida/samples/photos/' + file, 'rb') as f:
                    url = helpers.get_network_ip('eth1')
                    response = requests.post('http://' + url + '/api/v1/fileservice/', data={'index': 'false'}, files={'file': f}, auth=('admin', 'admin'))
                    if response.status_code == 201:
                        # Picture successfully uploaded
                        pictureFilename = json.loads(response._content)['name']

                        # Separate gender
                        isFemale = False
                        if 'female' in file:
                            isFemale = True
                        while True:
                            if person_index > db_size: # just in case
                                person_index = 0

                            # *Try* and match up a gender specific picture to the correct gender
                            thisGender = _personDB[person_index]['gender']
                            if isFemale:
                                if thisGender == 'Male':
                                    person_index += 1
                                elif thisGender == 'Female':
                                    break
                                else:
                                    break
                            else:
                                if thisGender == 'Female':
                                    person_index += 1
                                elif thisGender == 'Male':
                                    break
                                else:
                                    break

                        # Get person information
                        uploadJSON = '{"given_name":"' + _personDB[person_index]['given_name'] + '", "street_and_number":"' + _personDB[person_index]['street_and_number'] + '",'
                        uploadJSON += '"family_name":"' + _personDB[person_index]['family_name'] + '", "gender":"' + _personDB[person_index]['gender'] + '", '
                        if 'fathers_given_name' in _personDB[person_index]:
                            uploadJSON += '"fathers_given_name":"' + _personDB[person_index]['fathers_given_name'] + '", '
                        if 'mothers_given_name' in _personDB[person_index]:
                            uploadJSON += '"mothers_given_name":"' + _personDB[person_index]['mothers_given_name'] + '", '
                        uploadJSON += '"age":"' + str(_personDB[person_index]['age']) + '", "date_of_birth":" ' + _personDB[person_index]['date_of_birth'] + '", '
                        uploadJSON += '"city":"' + _personDB[person_index]['city'] + '", "phone_number":" ' + _personDB[person_index]['phone_number'] + '", '
                        if 'province_or_state' in _personDB[person_index]:
                            uploadJSON += '"province_or_state":"' + _personDB[person_index]['province_or_state'] + '", '
                        uploadJSON += '"pic_filename":"' + pictureFilename + '"'
                        uploadJSON += '}'
                        person_index += 1 # move forward in _nameDB
                        headers = {'Content-type':'application/json', 'Content-length':len(uploadJSON), 'Accept':'application/json'}
                        postResponse = requests.post('http://' + url + '/api/v1/person/', data=uploadJSON, headers=headers, auth=('admin', 'admin'))
                        if (postResponse.status_code != 201):
                            raise self.create_response(request, response)

                res['Status'] += file
                ctr += 1
                if (ctr != length):
                    res['Status'] += ' || '


        response = self.create_response(request, res)
        return response
Esempio n. 6
0
 def save_model(self, request, obj, form, change):
     obj.uuid = str(uuid.uuid4()).decode('unicode-escape') # Make new uuid for shelter
     obj.site_details = str('http://' + helpers.get_network_ip() + '/shelters/')
     return super(ShelterAdmin, self).save_model(request, obj, form, change)
Esempio n. 7
0
 def save_model(self, request, obj, form, change):
     obj.uuid = str(uuid.uuid4()).decode('unicode-escape') # Make new uuid for person (important for versioning)
     obj.site_details = str('http://' + helpers.get_network_ip() + '/persons/')
     return super(PersonAdmin, self).save_model(request, obj, form, change)
Esempio n. 8
0
    def auto_populate(self, request, **kwargs):
        # method check to avoid bad requests
        self.method_check(request, allowed=['get'])

        files = os.listdir('/vida/samples/photos/')

        res = {'Status': 'Pictures Uploaded: '}

        ctr = 0
        length = files.__len__()
        with open('/vida/samples/MOCK_DATA.json') as personDB:
            _personDB = json.load(personDB)
            db_size = len(_personDB) - 1 # indexing
            person_index = 0
            for file in files:
                with open('/vida/samples/photos/' + file, 'rb') as f:
                    url = helpers.get_network_ip()
                    response = requests.post('http://' + url + '/api/v1/fileservice/', files={'file': f}, auth=('admin', 'admin'))
                    if (response.status_code == 201):
                        # Picture successfully uploaded
                        pictureFilename = json.loads(response._content)['name']
                        # Separate gender
                        isFemale = False
                        if 'female' in file:
                            isFemale = True
                        while True:
                            if person_index > db_size: # just in case
                                person_index = 0

                            # *Try* and match up a gender specific picture to the correct gender
                            thisGender = _personDB[person_index]['gender']
                            if isFemale:
                                if thisGender == 'Male':
                                    person_index += 1
                                elif thisGender == 'Female':
                                    break
                                else:
                                    break
                            else:
                                if thisGender == 'Female':
                                    person_index += 1
                                elif thisGender == 'Male':
                                    break
                                else:
                                    break

                        # Get person information
                        print "Setting up person info"
                        uploadJSON = '{"given_name":"' + _personDB[person_index]['given_name'] + '", "street_and_number":"' + _personDB[person_index]['street_and_number'] + '",'
                        uploadJSON += '"family_name":"' + _personDB[person_index]['family_name'] + '", "gender":"' + _personDB[person_index]['gender'] + '", '
                        if 'fathers_given_name' in _personDB[person_index]:
                            uploadJSON += '"fathers_given_name":"' + _personDB[person_index]['fathers_given_name'] + '", '
                        if 'mothers_given_name' in _personDB[person_index]:
                            uploadJSON += '"mothers_given_name":"' + _personDB[person_index]['mothers_given_name'] + '", '
                        uploadJSON += '"age":"' + str(_personDB[person_index]['age']) + '", "date_of_birth":" ' + _personDB[person_index]['date_of_birth'] + '", '
                        uploadJSON += '"city":"' + _personDB[person_index]['city'] + '", "phone_number":" ' + _personDB[person_index]['phone_number'] + '", '
                        if 'province_or_state' in _personDB[person_index]:
                            uploadJSON += '"province_or_state":"' + _personDB[person_index]['province_or_state'] + '", '
                        uploadJSON += '"pic_filename":"' + pictureFilename + '", "uuid":"' + str(uuid.uuid4()).decode('unicode-escape') + '"'
                        uploadJSON += '}'
                        person_index += 1 # move forward in _nameDB
                        headers = {'Content-type':'application/json', 'Content-length':len(uploadJSON), 'Accept':'application/json'}
                        postResponse = requests.post('http://' + url + '/api/v1/person/', data=uploadJSON, headers=headers, auth=('admin', 'admin'))
                        if (postResponse.status_code != 201):
                            raise self.create_response(request, response)

                res['Status'] += file
                ctr += 1
                if (ctr != length):
                    res['Status'] += ' || '

        response = self.create_response(request, res)
        return response