"""
prereqs:
1) add autoreload.py to django/utils folder
2) create scripts folder (sibling to 'apps' and 'settings')
3) store this file in <yourproject>/scripts/
4) from console, run: python server.py
"""

# Warning:
# This works for me, but might not for you. (Windows XP, Python 2.4.1)

# TODO: needs to be refactored to play nicer with the DJANGO_SETTINGS_MODULE and PORT command line arguments of django-admin

# important configuration settings:
#factor this into a meta config file?
DJANGO_SETTINGS_MODULE = '<change_me_to_the_name_of_your_app>.settings.admin'
PORT = '<change_me_to_the_port_you_want_to_run_django_on>'  #must be a string


def start():
    import sys
    
    #import the root of your application
    #to get these relative paths correct, this script expects to be run from <yourproject>.scripts
    sys.path.append('../../')

    #The following is ugly... only because a hypenn makes "from django.bin.django-admin import runserver" invalid syntax.
    import django
    django_admin = __import__('django.bin.django-admin')
    runserver = django.bin.__dict__['django-admin'].runserver


    import os
    os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE
    
    #actually start things up...
    runserver(PORT)


if __name__ == "__main__":
    from django.utils import autoreload
    autoreload.main(start)