示例#1
0
    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]
示例#2
0
    def save_to_shake(self, for_user, to_shake=None):
        """
        Saves this file to a user's shake, or to the to_shake
        if it is provided.
        """
        new_sharedfile = Sharedfile()
        new_sharedfile.user_id = for_user.id
        new_sharedfile.name = self.name
        new_sharedfile.title = self.title
        new_sharedfile.content_type = self.content_type
        new_sharedfile.source_url = self.source_url
        new_sharedfile.source_id = self.source_id
        new_sharedfile.parent_id = self.id
        new_sharedfile.description = self.description

        if self.original_id == 0:
            new_sharedfile.original_id = self.id
        else:
            new_sharedfile.original_id = self.original_id
        new_sharedfile.save(ignore_tags=True)
        new_sharedfile.share_key = base36encode(new_sharedfile.id)
        new_sharedfile.save(ignore_tags=True)

        if to_shake:
            shake_to_save = to_shake
        else:
            shake_to_save = for_user.shake()
        new_sharedfile.add_to_shake(shake_to_save)

        #create a notification to the sharedfile owner
        notification.Notification.new_save(for_user, self)

        calculate_saves.delay_or_run(self.id)
        return new_sharedfile