Skip to content

Instantly share code, notes, and snippets.

@kevin-brown
kevin-brown / developing.md
Created September 6, 2014 21:07
Installing MouseTrap on Windows

Assuming bare, untouched Windows 7 Ultimate x64

Install git

http://git-scm.com/downloads

Clone repository

git clone https://github.com/GNOME-MouseTrap/mousetrap.git
@kevin-brown
kevin-brown / workflow.md
Last active August 29, 2015 14:06
MouseTrap development workflow

Development workflow

Over the summer we switched our workflow to include GitHub in order to help up facilitate the rewrite of MouseTrap. Now that the summer is over, we are left wondering how we should handle contributions to the project.

MouseTrap workflows

MouseTrap has had two main workflows during the time that I have been on the project.

@kevin-brown
kevin-brown / convert.py
Last active December 7, 2017 01:50
MySQL to SQLite database dump converter
import fileinput
import re
import sys
file_name = sys.argv[1]
new_file = sys.argv[2]
rh = open(file_name, "r")
lines = rh.readlines()
rh.close()
# Do not include the browsable api renderer in the initial list of classes
if not DEBUG:
REST_FRAMEWORK["DEFAULT_RENDERER_CLASSES"] += [
"rest_framework.renderers.BrowsableAPIRenderer",
]
@kevin-brown
kevin-brown / mixins.py
Last active November 28, 2019 09:27
DRF and Django compatible initialization mixin
class CompatibleDispatchInitialization(object):
"""
Allow data to be initialized before a view is fully dispatched in a way
that is consistent across both standard Django views and Django REST
Framework views.
While initializing data would typically be done within `dispatch`, the
request is not fully initialized at that point during DRF views which
causes issues with authentication. For this reason, it is recommended to
do data initialization within the `initial` method for DRF views. The
@kevin-brown
kevin-brown / views.py
Created May 24, 2014 14:33
Fixed DisablePaginationMixin. This needs to be added to your views.
class DisablePaginationMixin(object):
def get_paginate_by(self, queryset=None):
if self.paginate_by_param in self.request.QUERY_PARAMS and \
self.request.QUERY_PARAMS[self.paginate_by_param] == '0':
return None
return super(DisablePaginationMixin, self).get_paginate_by(queryset)
@kevin-brown
kevin-brown / select2.md
Last active June 26, 2016 16:49
Websites and applications which use Select2. This is not official or anything.

Nested ViewSets for DRF

DRF doesn't allow nested ViewSets natively, so I figured out the least amount of tweaks required to get it working.

The fields that are provided allow you to override the reverse() call with a specific mapping. These cannot be used across urls yet, as it pulls straight from the kwargs.

In your field, you must define map, which is a dictionary of destinaton => previous kwargs keys. These keys are relative to the current URL.