def delete(self): """ Sets the deleted flag to 1 and saves to DB. """ if options.readonly: return False self.deleted = 1; self.save() tags = models.TaggedFile.where('sharedfile_id = %s', self.id) for tag in tags: tag.deleted = 1 tag.save() delete_posts.delay_or_run(sharedfile_id=self.id) if self.original_id > 0: calculate_saves.delay_or_run(self.original_id) if self.parent_id > 0: calculate_saves.delay_or_run(self.original_id) #mute conversations conversations = conversation.Conversation.where('sharedfile_id = %s', self.id) [c.mute() for c in conversations] ssfs = shakesharedfile.Shakesharedfile.where('sharedfile_id = %s', self.id) [ssf.delete() for ssf in ssfs]
def save(self, *args, **kwargs): """ Sets the dates before saving. """ if options.readonly: self.add_error('_', 'Site is read-only.') return False self._set_dates() ignore_tags = False #we dont want to set tags if this is a save from a shared file if 'ignore_tags' in kwargs and kwargs['ignore_tags']: ignore_tags = True if 'ignore_tags' in kwargs: del (kwargs['ignore_tags']) super(Sharedfile, self).save(*args, **kwargs) if ignore_tags: return # clear out all tags all_tagged_files = models.TaggedFile.where('sharedfile_id = %s', self.id) for tf in all_tagged_files: tf.deleted = 1 tf.save() # extract tags tags = self.find_tags() for t in tags: tag = models.Tag.get("name = %s", t) if not tag: tag = models.Tag(name=t) tag.save() tagged_file = models.TaggedFile.get( 'sharedfile_id = %s and tag_id = %s', self.id, tag.id) if tagged_file and tagged_file.deleted: tagged_file.deleted = 0 tagged_file.save() else: tagged_file = models.TaggedFile(sharedfile_id=self.id, tag_id=tag.id, deleted=0) tagged_file.save()