Skip to content

Instantly share code, notes, and snippets.

@markng
Created February 15, 2012 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markng/1838431 to your computer and use it in GitHub Desktop.
Save markng/1838431 to your computer and use it in GitHub Desktop.
Create TM Projects automatically
import os
from django.conf import settings
from django.core.management.base import NoArgsCommand
from django.template.loader import render_to_string
from prey.models import State
class Command(NoArgsCommand):
"""command for creating templated tilemill projects"""
def handle_noargs(self, *args, **kwargs):
states = State.objects.all()
for state in states:
# only do this if the state has units
if state.unit_set.count() >= 1:
statedir = os.path.join(settings.PROJECT_PATH, 'tilemill', state.usps)
try:
os.makedirs(statedir)
except Exception, e:
# FAIL SILENTLY FOR THE WIN!
pass
# create mml
mml = render_to_string('tilemill/state.mml', {'state' : state})
mmlname = os.path.join(statedir, '%s.mml' % (state.usps))
open(mmlname, 'w').write(mml)
mss = render_to_string('tilemill/hdb.mss', {'state' : state})
mssname = os.path.join(statedir, 'hdb.mss')
open(mssname, 'w').write(mss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment