def process_userprofile(photo_basepath, model_hash, instance): """ Read the otm1 user photo off userprofile fixture, load the file, create storage-backed image and thumbnail, attach to user. the workflow for user photos is: * get photo data from otm1 as tarball that matches relative path * get userprofile fixture from otm1 as usual * dump photo data locally * modify photo_path to match local path for imports * "migrate" userprofile using this migrator with photo_path matching local. """ photo_path = model_hash['fields']['photo'] if not photo_path: return None user = User.objects.get(pk=model_hash['fields']['user']) photo_full_path = os.path.join(photo_basepath, photo_path) try: photo_data = open(photo_full_path) except IOError: print("Failed to read photo %s ... SKIPPING USER %s %s" % (photo_full_path, user.id, user.username)) return None user.photo, user.thumbnail = save_uploaded_image(photo_data, "user-%s" % user.pk, thumb_size=(85, 85)) user.save()
def process_userprofile(photo_basepath, model_hash, instance): """ Read the otm1 user photo off userprofile fixture, load the file, create storage-backed image and thumbnail, attach to user. the workflow for user photos is: * get photo data from otm1 as tarball that matches relative path * get userprofile fixture from otm1 as usual * dump photo data locally * modify photo_path to match local path for imports * "migrate" userprofile using this migrator with photo_path matching local. """ photo_path = model_hash['fields']['photo'] if not photo_path: return None user = User.objects.get(pk=model_hash['fields']['user']) photo_full_path = os.path.join(photo_basepath, photo_path) try: photo_data = open(photo_full_path) except IOError: print("Failed to read photo %s ... SKIPPING USER %s %s" % (photo_full_path, user.id, user.username)) return None user.photo, user.thumbnail = save_uploaded_image( photo_data, "user-%s" % user.pk, thumb_size=(85, 85)) user.save()
def test_rotates_image(self): sideways_file = self.load_resource('tree_sideways.jpg') img_file, __ = save_uploaded_image(sideways_file, 'test') expected_width, expected_height = Image.open(sideways_file).size actual_width, actual_height = Image.open(img_file).size self.assertEquals(expected_width, actual_height) self.assertEquals(expected_height, actual_width)
def process_userprofile(migration_rules, migration_event, photo_basepath, model_dict, up_obj, instance, **kwargs): """ Read the otm1 user photo off userprofile fixture, load the file, create storage-backed image and thumbnail, attach to user. the workflow for user photos is: * get photo data from otm1 as tarball that matches relative path * get userprofile fixture from otm1 as usual * dump photo data locally * modify photo_path to match local path for imports * "migrate" userprofile using this migrator with photo_path matching local. """ photo_path = model_dict['fields']['photo'] if not photo_path: return None user = User.objects.get(pk=model_dict['fields']['user']) photo_full_path = os.path.join(photo_basepath, photo_path) try: photo_data = open(photo_full_path) except IOError: print("Failed to read photo %s ... SKIPPING USER %s %s" % (photo_full_path, user.id, user.username)) return None user.photo, user.thumbnail = save_uploaded_image( photo_data, "user-%s" % user.pk, thumb_size=(85, 85)) user.save() OTM1ModelRelic.objects.create(instance=instance, migration_event=migration_event, otm1_model_id=model_dict['pk'], otm2_model_name='userprofile', otm2_model_id=models.UNBOUND_MODEL_ID) return None
def process_userprofile(migration_rules, migration_event, photo_basepath, model_dict, up_obj, instance, **kwargs): """ Read the otm1 user photo off userprofile fixture, load the file, create storage-backed image and thumbnail, attach to user. the workflow for user photos is: * get photo data from otm1 as tarball that matches relative path * get userprofile fixture from otm1 as usual * dump photo data locally * modify photo_path to match local path for imports * "migrate" userprofile using this migrator with photo_path matching local. """ photo_path = model_dict['fields']['photo'] if not photo_path: return None user = User.objects.get(pk=model_dict['fields']['user']) photo_full_path = os.path.join(photo_basepath, photo_path) try: photo_data = open(photo_full_path) except IOError: print("Failed to read photo %s ... SKIPPING USER %s %s" % (photo_full_path, user.id, user.username)) return None user.photo, user.thumbnail = save_uploaded_image(photo_data, "user-%s" % user.pk, thumb_size=(85, 85)) user.save() OTM1ModelRelic.objects.create(instance=instance, migration_event=migration_event, otm1_model_id=model_dict['pk'], otm2_model_name='userprofile', otm2_model_id=models.UNBOUND_MODEL_ID) return None
def set_image(self, image_data, degrees_to_rotate=None): self.image, self.thumbnail = save_uploaded_image( image_data, self.image_prefix, thumb_size=(256, 256), degrees_to_rotate=degrees_to_rotate)
def set_image(self, image_data): self.image, self.thumbnail = save_uploaded_image(image_data, self.image_prefix, thumb_size=(256, 256))
def set_image(self, image_data): name_prefix = "%s-%s" % (self.tree.plot.pk, self.tree.pk) self.image, self.thumbnail = save_uploaded_image( image_data, name_prefix, thumb_size=(256, 256))
def set_image(self, image_data): self.image, self.thumbnail = save_uploaded_image( image_data, self.image_prefix, thumb_size=(256, 256))