Created
February 15, 2012 19:46
-
-
Save markng/1838431 to your computer and use it in GitHub Desktop.
Create TM Projects automatically
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 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