This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import passwords from Dashlane's CSV-export into pass | |
# Note: you might need to manually clean up the typically malformatted Dashlane CSV export | |
import sys | |
import csv | |
import argparse | |
import subprocess | |
def main(argv=None): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InlineButtonsAdminMixin(object): | |
""" | |
Mixin which dynamically adds links to inline admins on the top right of | |
the admin form. | |
""" | |
class Media: | |
js = ('js/inlinebuttons.js',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.urlresolvers import reverse | |
from sorl.thumbnail import get_thumbnail | |
from django.conf.urls.defaults import patterns, url | |
# This nice little snippet makes the life of someone extending the admin | |
# functionality a lot easier. | |
# Find the original at: http://djangosnippets.org/snippets/1804/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Listener(object): | |
""" | |
Class-based listeners, based on Django's class-based generic views. Yay! | |
Usage:: | |
class MySillyListener(Listener): | |
def dispatch(self, sender, **kwargs): | |
# DO SOMETHING | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging, re | |
logger = logging.getLogger(__name__) | |
from django.utils.translation import get_language | |
LANGUAGE_CODE_RE = re.compile(r'_(?P<code>[a-z_]{2,5})$') | |
class TranslatableMixin(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderableFormMixin(object): | |
""" | |
Form mixin class which allows for reordering and hiding fields for normal | |
forms, similar to the way this is possible with ModelForms:: | |
class MyFunkyForm(OrderableFormMixin, Form): | |
class Meta: | |
fields = ('my_field1', 'my_field2') | |
This snippet is based on: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sanitize_log_data(secret, data=None, leave_characters=4): | |
""" | |
Clean private/secret data from log statements and other data. | |
Assumes data and secret are strings. Replaces all but the first | |
`leave_characters` of `secret`, as found in `data`, with '*'. | |
If no data is given, all but the first `leave_characters` of secret | |
are simply replaced and returned. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oldfile = open('freeze_old.txt') | |
newfile = open('freeze_new.txt') | |
packages = {} | |
def splitpackage(line): | |
result = line.split('==') | |
if not len(result) == 2: | |
result = line.split('@') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.exceptions import ValidationError | |
... | |
def default_validator(value): | |
""" Make sure only one instance of MyModel has default=True """ | |
if value and MyModel.objects.filter(default=True).exists(): | |
raise ValidationError('A default has already been defined.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
# Import the PROJECT_MODEL string from the current app's settings | |
from .settings import PROJECT_MODEL | |
class Task(models.Model): | |
""" | |
Instead of explicitly giving the model for the FK as a Python object or | |
explicitly stating a string in the form '<app>.<modelname>', we'll use |
OlderNewer