def delete(self, request, *args, **kwargs):
        try:
            node = self.get_object()
            flag = None
            osf_flag = None
            message = None
            if node.is_deleted:
                node.is_deleted = False
                node.deleted_date = None
                flag = NODE_RESTORED
                message = 'Node {} restored.'.format(node.pk)
                osf_flag = NodeLog.NODE_CREATED
            elif not node.is_registration:
                node.is_deleted = True
                node.deleted_date = datetime.utcnow()
                flag = NODE_REMOVED
                message = 'Node {} removed.'.format(node.pk)
                osf_flag = NodeLog.NODE_REMOVED
            node.save()
            if flag is not None:
                update_admin_log(
                    user_id=self.request.user.id,
                    object_id=node.pk,
                    object_repr='Node',
                    message=message,
                    action_flag=flag
                )
            if osf_flag is not None:
                # Log invisibly on the OSF.
                osf_log = NodeLog(
                    action=osf_flag,
                    user=None,
                    params={
                        'project': node.parent_id,
                    },
                    date=datetime.utcnow(),
                    should_hide=True,
                )
                osf_log.save()
        except __HOLE__:
            return page_not_found(
                request,
                AttributeError(
                    '{} with id "{}" not found.'.format(
                        self.context_object_name.title(),
                        kwargs.get('guid')
                    )
                )
            )
        return redirect(reverse_node(self.kwargs.get('guid')))
dataset/ETHPy150Open CenterForOpenScience/osf.io/admin/nodes/views.py/NodeDeleteView.delete