srmd/lsmhq — pull request #1 by isbadawi (2014-06-26 03:54:43+00:00)
Title: Use POST when deleting players.

n.b. The event handler is a little tricky -- in JavaScript you can define extra function parameters and they'll be ignored (value `undefined`) if they're not passed in. So on click, jQuery doesn't pass in any value for `confirmed` so it's `undefined` (which is like `false` in if statements) -- we prevent the form submission then call `bootbox.confirm`, and if it's confirmed we manually click the button again but with `confirmed == true`. Then we enter the if statement and just return, letting the form submit.

We need to do this because `bootbox.confirm` is asynchronous, so we can't just say `e.preventDefault()` inside the callback because the event handler will have already finished executing. So we always prevent the form submission, and then trigger another one if the confirmation succeeds.

(You could also use a `DeleteView` instead of the `deletePlayer` view -- it would look like this:

```python
class PlayerDelete(generic.edit.DeleteView):
success_url = reverse_lazy('core:players')

def get_object(self):
player_id = self.request.POST['player_id']
return get_object_or_404(Player, pk=player_id)
```

You can see [here](https://github.com/django/django/blob/7e2c804c9417617934cd731a4537719a1bd8d985/django/views/generic/edit.py#L245-L253) the `DeleteView` does exactly the same thing as `deletePlayer` so it's up to you).