def apply_cropping(self, crop): """Set self.image to the cropped self.ucropped_image.""" apply_cropping_to_image( self.uncropped_image, crop['x'], crop['y'], crop['width'], crop['height'], ) if (self.image and os.path.exists(self.image.path) and self.image.path != self.uncropped_image.path): os.unlink(self.image.path) self.image.name = self.uncropped_image.name self.save()
def update_suggestion_and_save(self, suggestion, submit): is_form_valid = self.is_valid() current_revision = suggestion.get_current_revision() if 'title' in self.cleaned_data: current_revision.title = self.cleaned_data['title'] or '' if 'description' in self.cleaned_data: current_revision.description = \ self.cleaned_data['description'] or '' current_revision.save() suggestion.type = self.cleaned_data['type'] if self.cleaned_data.get('image', None): suggestion.image = self.cleaned_data['image'] if is_form_valid and submit == 'save': sx = ( float(self.cropping['natural_width']) / float(self.cropping['display_width']) ) sy = ( float(self.cropping['natural_height']) / float(self.cropping['display_height']) ) apply_cropping_to_image( suggestion.image, self.cropping['x'] * sx, self.cropping['y'] * sy, self.cropping['w'] * sx, self.cropping['h'] * sy, ) suggestion.slug = slugify( suggestion.get_current_revision().title) suggestion.is_draft = False suggestion.save() notification = Notification.create_for_suggestion(suggestion) if notification.owner != suggestion.owner: notification.save() else: suggestion.save() return is_form_valid
def apply_cropping(self, crop): """Set self.image to the cropped self.ucropped_image.""" apply_cropping_to_image( self.uncropped_image, crop['x'], crop['y'], crop['width'], crop['height'], ) if ( self.image and os.path.exists(self.image.path) and self.image.path != self.uncropped_image.path ): os.unlink(self.image.path) self.image.name = self.uncropped_image.name self.save()