def save(self, *args, **kwargs): """Save the Resource""" if not self.pk: self.slug = slugify(unicode(self.name)) while Resource.objects.filter(slug=self.slug).exists(): self.slug = u'{name_slug}-{random}'.format( name_slug=slugify(unicode(self.name)), random=generate_random_string()) return super(Resource, self).save(*args, **kwargs)
def save(self, *args, **kwargs): """Save the Resource""" if not self.pk: self.slug = slugify(unicode(self.name)) while Resource.objects.filter(slug=self.slug).exists(): self.slug = u'{name_slug}-{random}'.format( name_slug=slugify(unicode(self.name)), random=generate_random_string() ) return super(Resource, self).save(*args, **kwargs)
def get_in_memory_image_file(): """Returns a fake image file. Faster than using file system.""" image_file = StringIO() image = PILImage.new("RGBA", size=(50, 50), color=(256, 0, 0)) image.save(image_file, 'png') name = '%s.png' % generate_random_string() image_file.name = name image_file.width = 200 image_file.height = 200 image_file._committed = False image_file.save = Mock() image_file.url = '/uploads/%s' % name image_file.__unicode__ = Mock(return_value=name) image_file.seek(0) return image_file