def _remove_photo(meeting, person): response = {} photo = person.decoded_data.get('photo') original_photo = person.decoded_data.get('original_photo') if photo: try: path(photos.path(photo)).remove() except os.error: pass if original_photo: try: path(photos.path(original_photo)).remove() except os.error: pass person.data['photo'] = None person.data.pop('original_photo', None) person.save() sugar.activity(meeting.id, "remove-participant-photo", person.name, person.id) response["status"] = "success" return flask.json.dumps(response)
def _edit_photo(meeting, person): response = {'status': 'error'} app = flask.current_app #delete current photo if exists photo = person.decoded_data.get('photo') original_photo = person.decoded_data.get('original_photo') if photo: try: path(photos.path(photo)).remove() except os.error: pass if original_photo: try: path(photos.path(original_photo)).remove() except os.error: pass photo_name = '%s.' % secure_filename(person.decoded_data['personal_last_name']) filename = photos.save(flask.request.files['photo'], name=photo_name) file_path = app.config['UPLOADED_PHOTOS_DEST'] / filename file_size = app.config['UPLOADED_PHOTO_RESOLUTION'] new_file_path = sugar.optimize_photo(file_path, file_size) person.data['photo'] = new_file_path.name person.data.pop('original_photo', None) person.save() sugar.activity(meeting.id, 'edit-participant-photo', person.name, person.id) response['status'] = 'success' response['url'] = person.image_file return flask.json.dumps(response)