Skip to content

Instantly share code, notes, and snippets.

View thibaut-pro's full-sized avatar
✌️

Thibaut LaBarre thibaut-pro

✌️
View GitHub Profile
@thibaut-pro
thibaut-pro / README.md
Last active June 5, 2020 23:29 — forked from rafen/README.md
Django ExtendedActionsMixin allows ModelAdmin classes to execute actions with empty queryset and filtered queryset

ExtendedActionsMixin

This is a Django mixin that allows ModelAdmin classes to execute actions without selecting any objects on the change list of the Django Admin.

To implement it you need to include the Mixin as usual (see https://docs.djangoproject.com/en/1.10/topics/class-based-views/mixins/) and define a class attribute called extended_actions containing a list of string with the name of the actions that you want to be exectued with empty queryset.

If in the action you want to use the same queryset that the user is seeing, you can use the get_filtered_queryset method also provided by the mixin

@thibaut-pro
thibaut-pro / clean_branches.sh
Created May 1, 2020 20:56
Clean up old branches
git remote prune origin ─╯
git branch -vv | grep "origin/.*: gone]" | awk '{print $1}' | xargs git branch -D
@thibaut-pro
thibaut-pro / pre-hook.sh
Created February 21, 2020 16:55
Git prehook to protect staging and master branches
#!/bin/sh
# To bypass this hook and force the push, use 'git push --no-verify'
protected_branches=('staging' 'master')
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
for branch in "${protected_branches[@]}"
do
if [ $branch = $current_branch ]; then
echo "You're about to push $branch and you don't want that"