Skip to content

Instantly share code, notes, and snippets.

@magopian
magopian / gist:8915831
Created February 10, 2014 13:22
update from Django 1.4 to 1.5, various notes (not complete)
Not yet! But here are some notes (taken from the release notes):
## New
* use PBKDF2 for passwords
* new URL tags : remove all ```{% load url from future %}``` (and make sure there's no old style ```{% url %}``` tags lurking around)
* **INFO**: [update_fields](https://docs.djangoproject.com/en/dev/ref/models/instances/#specifying-which-fields-to-save) added to save only needed fields on a model
* **INFO**: calls to [call_command](https://docs.djangoproject.com/en/dev/ref/django-admin/#call-command) now propagates exceptions
* **INFO**: [LOGIN_URL](https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-LOGIN_URL) and [LOGIN_REDIRECT_URL](https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-LOGIN_REDIRECT_URL) settings now also allows view function names and named url patterns
* **INFO**: when using RequestContext, there's now a [perms](https://docs.djangoproject.com/en/dev/ref/templates/api/#django-contrib-auth-context-processors-auth) in the context that allows to do ```{% if 'someapp.so
@magopian
magopian / README.rst
Last active December 30, 2015 16:29
A few notes on how to deal with a Raspberry-pi

Raspberry-Pi tips and tricks

Backup SDCard to computer

Check the output of the lsblk command to find the correct device (eg: /dev/mmcblk0):

@magopian
magopian / conftest.py
Created November 27, 2013 10:46
Little hack for pytest_django: load data in your test database before the tests are run, only if the database is being created and not reused.
import pytest
@pytest.fixture(scope='session')
def _django_db_setup(request, _django_db_setup, _django_cursor_wrapper):
"""Load any data needed for the tests after the database is created.
This "overwrites" pytest_django's own _django_db_setup.
"""
@magopian
magopian / fix_permissions.py
Created November 19, 2013 11:00
Django admin command to "fix permissions" (create them properly for proxy models). This is needed because of the following bug in Django (not fixed as of 1.6): https://code.djangoproject.com/ticket/11154
# -*- coding: utf-8 -*-
"""Add permissions for proxy model.
This is needed because of the bug https://code.djangoproject.com/ticket/11154
in Django (as of 1.6, it's not fixed).
When a permission is created for a proxy model, it actually creates if for it's
base model app_label (eg: for "article" instead of "about", for the About proxy
model).
@magopian
magopian / conftest.py
Last active November 1, 2018 17:10
Some pytest(-django) fixtures that I find useful. There's also an "app" fixture to take advantage of django-webtest when used with py.test.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, division
import pytest
from django_webtest import DjangoTestApp, WebTestMixin
class Stub(object):
"""Stub methods, keep track of calls."""
@magopian
magopian / admin_list_editable_autosubmit.js
Last active September 10, 2021 15:51
Small js script that automatically submits the changelist form on field changes. This is convenient when used with https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_editable, and avoids having to remember to submit the form when done (the form on the changelist page doesn't look like a form after all, …
/*
* Only useful in changelist pages when the ModelAdmin displayed has
* "list_editable" (https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_editable)
* configured.
*
* When one of the input/select/textarea value is changed, automatically submit
* the form using ajax.
*
* Only form fields relevant to the "list_editable" will trigger a form submit.
*
@magopian
magopian / gist:6128849
Last active August 27, 2019 04:32
Local git mirror of github used by private Jenkins
So I've installed a dead simple backup, in /home/USER/git_backup/:
git clone --mirror git@github.com:USER/PROJECT.git
update.sh (launched every 5 minutes by cron):
#/bin/sh
cd /home/USER/git_backup/PROJECT.git
LINES=`git remote update 2>&1 | wc -l`
@magopian
magopian / conftest.py
Last active December 20, 2015 03:09
fixtures for pytest, using monkeypatch, and providing stub facilities, also allowing to check the calls of the stubbed methods. For a fixture that makes use of the mock library, check pelme's https://gist.github.com/pelme/59a1dee00b5f8afc278e (example usage: https://gist.github.com/pelme/08571132a677485c7e23)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, division
import pytest
class Stub(object):
"""Stub methods, keep track of calls."""
@magopian
magopian / rfpy3.py
Last active April 26, 2018 22:20
rfpy3.py : Ready For Python3? Simple script to be executed locally (in a virtualenv?) to check which of the local packages have the Py3 trove classifier, if they don't, if the newest version on PyPI has.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Ready For Python3?
Checks the locally installed distribution for the py3 trove classifier, and if
it's not found, check on PyPI if there's a newer version of this distribution.
This was done with some help from Matrixise.
@magopian
magopian / pre-commit
Created March 8, 2013 10:11
git pre-commit hook
#!/bin/sh
#
# This pre-commit hook tests various conditions to allow the commit.
# It can be disabled by using the "-n" option with "git commit".
#
# To use it, link it to .git/hooks/pre-commit:
#
# ln -s `pwd`/pre-commit .git/hooks/
if git rev-parse --verify HEAD >/dev/null 2>&1