Only set state to pending when last is deleted

If a user deletes a submission that's not the last one, the prior one gets a
`pending` state. This caused two submissions for the same exercise to appear
on the current_exercises list. This commit fixes this by making sure that the
submission getting deleted is the last one and then setting the state of the
prior one to `pending`.

Possible fix for #1792