Skip to content

Instantly share code, notes, and snippets.

View philipn's full-sized avatar

Philip Neustrom philipn

View GitHub Profile
class SlugifyMixin(object):
def obj_get(self, request=None, **kwargs):
slug = getattr(self._meta, 'slug_lookup_field', 'slug')
kwargs[slug] = slugify(kwargs[slug])
return super(SlugifyMixin, self).obj_get(request=request, **kwargs)
def override_urls(self):
slug = getattr(self._meta, 'slug_lookup_field', 'slug')
return [
url(r"^(?P<resource_name>%s)/(?P<%s>.+?)/*$" %
{% load static from staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
@philipn
philipn / gist:2907544
Created June 10, 2012 22:29
Cache cloudmade titles in localwiki
You'll want to replace 'localwiki.org' with your hostname here.
----------------------
Add to localsettings.py:
OLWIDGET_CUSTOM_LAYER_TYPES = {
'cachedcloudmade': """OpenLayers.Layer.CachedCloudMade('CachedCloudMade',
['//map-a.localwiki.org/tile/ca694687020d468283a545db191bcb81/35165/256/',
'//map-b.localwiki.org/tile/ca694687020d468283a545db191bcb81/35165/256/',
'//map-c.localwiki.org/tile/ca694687020d468283a545db191bcb81/35165/256/'])""",
}
def filter_value_to_python(self, value, field_name, filters=None,
filter_expr=None, filter_type=None):
"""
Turn the string ``value`` into a python object.
"""
# Simple values
if value in ['true', 'True', True]:
return True
elif value in ['false', 'False', False]:
@philipn
philipn / gist:3260364
Created August 4, 2012 22:31
tastypie gis queryset methods
the distance method takes a geom argument:
Map.objects.distance(geom).order_by('distance') -->
/api/map/?objects.distance=<geom>&order_by=distance
the area method takes no arguments:
Map.objects.area().order_by('area') -->
# This is an example .wsgi file for serving up localwiki inside of a
# custom virtualenv.
#
#############################################################
# CHANGE THIS LINE to the absolute path of the virtualenv:
#############################################################
VIRTUAL_ENV_PATH = '/home/philip/projects/py_envs/localwiki'
import os
import sys
@philipn
philipn / gist:5241282
Last active December 15, 2015 09:49
Custom CSS upgrade for LocalWiki platform v0.5

If you've customized your CSS or otherwise altered your site/base.html template you'll want to do the following:

Back up your old base.html template:

sudo cp /usr/share/localwiki/templates/site/base.html ~/base.html.bak

Now just remove the base.html template:

sudo rm /usr/share/localwiki/templates/site/base.html

Keybase proof

I hereby claim:

  • I am philipn on github.
  • I am philipn (https://keybase.io/philipn) on keybase.
  • I have a public key whose fingerprint is 996B 2D31 DBDC 8734 9019 3199 1319 9280 9EB7 3975

To claim this, I am signing this object:

@philipn
philipn / gist:8659192
Created January 27, 2014 23:07
Mixin to allow limiting of fields, per-request, in django-rest-framework
class AllowFieldLimitingMixin(object):
"""
A mixin for a generic APIView that will allow the serialized fields to be
limited to a set of comma-separated values, specified via the `fields`
query parameter. This will only apply to GET requests.
"""
_serializer_class_for_fields = {}
def get_serializer_class_for_fields(self, serializer_class, fields):
fields = fields.strip().split(',')
@philipn
philipn / gist:1138957
Created August 11, 2011 05:25
GeoTIFF metadata / ftp download
"""
This likely isn't useful to anybody else. But it's an example of how to
adapt python's ftplib to grab just the first few kb of a given file.
In this case, all we need is the first few kb to get the metadata from a
GeoTIFF file.
"""
import ftplib