This file contains hidden or 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 sys, unicodedata, re | |
# Get all unicode characters | |
all_chars = (unichr(i) for i in xrange(sys.maxunicode)) | |
# Get all non printable characters | |
control_chars = ''.join(c for c in all_chars if unicodedata.category(c) == 'Cc') | |
# Create regex of above characters | |
control_char_re = re.compile('[%s]' % re.escape(control_chars)) | |
# Substitute these characters by empty string in the original string. | |
def remove_control_chars(s): | |
return control_char_re.sub('', s) |
This file contains hidden or 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.contrib.gis.geos import Polygon | |
polygon = Polygon([ [ -0.300718341203409, 51.499348080169298 ], [ -0.305825965105626, 51.498332099170185 ], [ -0.307022220327252, 51.502946258541684 ], [ -0.307484352569642, 51.502956525191117 ], [ -0.307389790901562, 51.50270877049892 ], [ -0.308467442785522, 51.502477927448041 ], [ -0.308630258983584, 51.502711378579441 ], [ -0.315328507266898, 51.501115424124485 ], [ -0.315307276005044, 51.500597160763 ], [ -0.31700604605745, 51.499968706315791 ], [ -0.316747263949783, 51.499679935641787 ], [ -0.317115403364906, 51.499542240450104 ], [ -0.322434764868367, 51.505306090523163 ], [ -0.326171329324033, 51.503962067782354 ], [ -0.32920456109009, 51.50959043971325 ], [ -0.326859549034093, 51.509719773727142 ], [ -0.319498302693188, 51.51090313757738 ], [ -0.319724317133101, 51.513533929252844 ], [ -0.320820301819518, 51.514534281758522 ], [ -0.32142240605236, 51.516032924757987 ], [ -0.322601530580793, 51.517087503992336 ], [ -0.323069801167743, 51.52081970904073 ], [ |
This file contains hidden or 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
# models.py | |
from mptt.models import MPTTModel, TreeForeignKey | |
from parler.models import TranslatableModel, TranslatedFields | |
from .managers import CategoryManager | |
class Category(MPTTModel, TranslatableModel): | |
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True) |
This file contains hidden or 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 printTable(table, first_row_is_header=True, spacing=4): | |
# caluclate the number of columns | |
cols = len(table[0]) | |
# calculate the max width for each column | |
max_list = [None]*cols | |
for i in xrange(cols): | |
max_list[i] = max([len(str(x[i])) if i<len(x) else 0 for x in table]) | |
# calc row length for lines |