Пример #1
0
def clone_state(request, state_id):
    state = State.objects.get(id=state_id)
    config = Configuration.objects.get(pk=1)

    new_state = State(name=request.POST.get('state_name') or old_state.name)
    new_state.state = state.state
    new_state.save()
    return redirect(new_state.view_state_url())
Пример #2
0
def submit_turn(request, game_id):
    game = Game.objects.get(pk=game_id)

    if not game.viewable(request):
        return forbidden()
    state = game.deserialize(game.current_state())
    variables, coefficients = state['variables'], state['coefficients']

    if '' in variables.owned_items: 
        variables.owned_items.remove('')
    if '' in variables.user_messages:
        variables.user_messages.remove('')

    from engine.simple_controller import adjust_submission
    kwargs = {}
    for key in request.POST:
        kwargs[key] = request.POST.get(key)
    kwargs = adjust_submission(kwargs, variables.names)

    user_submission = game.user_input.schema().deserialize(kwargs)

    for key in user_submission:        
        variables[key] = user_submission[key]
        
    from twisterclient import TwisterClient as TC
    tc = TC(base="http://twister.ccnmtl.columbia.edu/", chain=True)
    turn = logic.Turn(variables, coefficients, tc)
    alive, variables = turn.go()

    del variables.people
    import json
    old_state = game.current_state()
    new_state = State(name=old_state.name, game=old_state.game)
    new_state.state = json.dumps(dict(
            variables=variables,
            coefficients=coefficients))
    new_state.save()

    if not alive:
        game.mark_finished()
        game.save()

    return redirect(game.show_game_url())
Пример #3
0
def import_data():
    #initial imports

    #Processing model: State

    from main.models import State

    main_state_1 = State()
    main_state_1.name = u'Alabama'
    main_state_1.abbreviation = u'AL'
    main_state_1 = importer.save_or_locate(main_state_1)

    main_state_2 = State()
    main_state_2.name = u'Alaska'
    main_state_2.abbreviation = u'AK'
    main_state_2 = importer.save_or_locate(main_state_2)

    main_state_3 = State()
    main_state_3.name = u'Arizona'
    main_state_3.abbreviation = u'AZ'
    main_state_3 = importer.save_or_locate(main_state_3)

    main_state_4 = State()
    main_state_4.name = u'Arkansas'
    main_state_4.abbreviation = u'AR'
    main_state_4 = importer.save_or_locate(main_state_4)

    main_state_5 = State()
    main_state_5.name = u'California'
    main_state_5.abbreviation = u'CA'
    main_state_5 = importer.save_or_locate(main_state_5)

    main_state_6 = State()
    main_state_6.name = u'Colorado'
    main_state_6.abbreviation = u'CO'
    main_state_6 = importer.save_or_locate(main_state_6)

    main_state_7 = State()
    main_state_7.name = u'Connecticut'
    main_state_7.abbreviation = u'CT'
    main_state_7 = importer.save_or_locate(main_state_7)

    main_state_8 = State()
    main_state_8.name = u'Delaware'
    main_state_8.abbreviation = u'DE'
    main_state_8 = importer.save_or_locate(main_state_8)

    main_state_9 = State()
    main_state_9.name = u'Florida'
    main_state_9.abbreviation = u'FL'
    main_state_9 = importer.save_or_locate(main_state_9)

    main_state_10 = State()
    main_state_10.name = u'Georgia'
    main_state_10.abbreviation = u'GA'
    main_state_10 = importer.save_or_locate(main_state_10)

    main_state_11 = State()
    main_state_11.name = u'Hawaii'
    main_state_11.abbreviation = u'HI'
    main_state_11 = importer.save_or_locate(main_state_11)

    main_state_12 = State()
    main_state_12.name = u'Idaho'
    main_state_12.abbreviation = u'ID'
    main_state_12 = importer.save_or_locate(main_state_12)

    main_state_13 = State()
    main_state_13.name = u'Illinois'
    main_state_13.abbreviation = u'IL'
    main_state_13 = importer.save_or_locate(main_state_13)

    main_state_14 = State()
    main_state_14.name = u'Indiana'
    main_state_14.abbreviation = u'IN'
    main_state_14 = importer.save_or_locate(main_state_14)

    main_state_15 = State()
    main_state_15.name = u'Iowa'
    main_state_15.abbreviation = u'IA'
    main_state_15 = importer.save_or_locate(main_state_15)

    main_state_16 = State()
    main_state_16.name = u'Kansas'
    main_state_16.abbreviation = u'KS'
    main_state_16 = importer.save_or_locate(main_state_16)

    main_state_17 = State()
    main_state_17.name = u'Kentucky'
    main_state_17.abbreviation = u'KY'
    main_state_17 = importer.save_or_locate(main_state_17)

    main_state_18 = State()
    main_state_18.name = u'Louisiana'
    main_state_18.abbreviation = u'LA'
    main_state_18 = importer.save_or_locate(main_state_18)

    main_state_19 = State()
    main_state_19.name = u'Maine'
    main_state_19.abbreviation = u'ME'
    main_state_19 = importer.save_or_locate(main_state_19)

    main_state_20 = State()
    main_state_20.name = u'Maryland'
    main_state_20.abbreviation = u'MD'
    main_state_20 = importer.save_or_locate(main_state_20)

    main_state_21 = State()
    main_state_21.name = u'Massachusetts'
    main_state_21.abbreviation = u'MA'
    main_state_21 = importer.save_or_locate(main_state_21)

    main_state_22 = State()
    main_state_22.name = u'Michigan'
    main_state_22.abbreviation = u'MI'
    main_state_22 = importer.save_or_locate(main_state_22)

    main_state_23 = State()
    main_state_23.name = u'Minnesota'
    main_state_23.abbreviation = u'MN'
    main_state_23 = importer.save_or_locate(main_state_23)

    main_state_24 = State()
    main_state_24.name = u'Mississippi'
    main_state_24.abbreviation = u'MS'
    main_state_24 = importer.save_or_locate(main_state_24)

    main_state_25 = State()
    main_state_25.name = u'Missouri'
    main_state_25.abbreviation = u'MS'
    main_state_25 = importer.save_or_locate(main_state_25)

    main_state_26 = State()
    main_state_26.name = u'Montana'
    main_state_26.abbreviation = u'MT'
    main_state_26 = importer.save_or_locate(main_state_26)

    main_state_27 = State()
    main_state_27.name = u'Nebraska'
    main_state_27.abbreviation = u'NE'
    main_state_27 = importer.save_or_locate(main_state_27)

    main_state_28 = State()
    main_state_28.name = u'Nevada'
    main_state_28.abbreviation = u'NV'
    main_state_28 = importer.save_or_locate(main_state_28)

    main_state_29 = State()
    main_state_29.name = u'New Hampshire'
    main_state_29.abbreviation = u'NH'
    main_state_29 = importer.save_or_locate(main_state_29)

    main_state_30 = State()
    main_state_30.name = u'New Jersey'
    main_state_30.abbreviation = u'NJ'
    main_state_30 = importer.save_or_locate(main_state_30)

    main_state_31 = State()
    main_state_31.name = u'New Mexico'
    main_state_31.abbreviation = u'NM'
    main_state_31 = importer.save_or_locate(main_state_31)

    main_state_32 = State()
    main_state_32.name = u'New York'
    main_state_32.abbreviation = u'NY'
    main_state_32 = importer.save_or_locate(main_state_32)

    main_state_33 = State()
    main_state_33.name = u'North Carolina'
    main_state_33.abbreviation = u'NC'
    main_state_33 = importer.save_or_locate(main_state_33)

    main_state_34 = State()
    main_state_34.name = u'North Dakota'
    main_state_34.abbreviation = u'ND'
    main_state_34 = importer.save_or_locate(main_state_34)

    main_state_35 = State()
    main_state_35.name = u'Ohio'
    main_state_35.abbreviation = u'OH'
    main_state_35 = importer.save_or_locate(main_state_35)

    main_state_36 = State()
    main_state_36.name = u'Oklahoma'
    main_state_36.abbreviation = u'OK'
    main_state_36 = importer.save_or_locate(main_state_36)

    main_state_37 = State()
    main_state_37.name = u'Oregon'
    main_state_37.abbreviation = u'OR'
    main_state_37 = importer.save_or_locate(main_state_37)

    main_state_38 = State()
    main_state_38.name = u'Pennsylvania'
    main_state_38.abbreviation = u'PA'
    main_state_38 = importer.save_or_locate(main_state_38)

    main_state_39 = State()
    main_state_39.name = u'Rhode Island'
    main_state_39.abbreviation = u'RI'
    main_state_39 = importer.save_or_locate(main_state_39)

    main_state_40 = State()
    main_state_40.name = u'South Carolina'
    main_state_40.abbreviation = u'SC'
    main_state_40 = importer.save_or_locate(main_state_40)

    main_state_41 = State()
    main_state_41.name = u'South Dakota'
    main_state_41.abbreviation = u'SD'
    main_state_41 = importer.save_or_locate(main_state_41)

    main_state_42 = State()
    main_state_42.name = u'Tennessee'
    main_state_42.abbreviation = u'TN'
    main_state_42 = importer.save_or_locate(main_state_42)

    main_state_43 = State()
    main_state_43.name = u'Texas'
    main_state_43.abbreviation = u'TX'
    main_state_43 = importer.save_or_locate(main_state_43)

    main_state_44 = State()
    main_state_44.name = u'Utah'
    main_state_44.abbreviation = u'UT'
    main_state_44 = importer.save_or_locate(main_state_44)

    main_state_45 = State()
    main_state_45.name = u'Vermont'
    main_state_45.abbreviation = u'VT'
    main_state_45 = importer.save_or_locate(main_state_45)

    main_state_46 = State()
    main_state_46.name = u'Virginia'
    main_state_46.abbreviation = u'VA'
    main_state_46 = importer.save_or_locate(main_state_46)

    main_state_47 = State()
    main_state_47.name = u'Washington'
    main_state_47.abbreviation = u'WA'
    main_state_47 = importer.save_or_locate(main_state_47)

    main_state_48 = State()
    main_state_48.name = u'West Virginia'
    main_state_48.abbreviation = u'WV'
    main_state_48 = importer.save_or_locate(main_state_48)

    main_state_49 = State()
    main_state_49.name = u'Wisconsin'
    main_state_49.abbreviation = u'WI'
    main_state_49 = importer.save_or_locate(main_state_49)

    main_state_50 = State()
    main_state_50.name = u'Wyoming'
    main_state_50.abbreviation = u'WY'
    main_state_50 = importer.save_or_locate(main_state_50)
Пример #4
0
import os
import sys

sys.path.append("..")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_states.settings")

from main.models import State, City

csv_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"states.csv")

csv_file = open(csv_file_path, 'r')

reader = csv.DictReader(csv_file)

for row in reader:
	state_obj = State()
	state_obj, created = State.objects.get_or_create(name=row['state'])
	#state_obj.name = row['state']
	state_obj.abbreviation = row['abbrev']

	print state_obj.name
	print created

	
	state_obj.save()

	capital_obj, created = StateCapital.objects.get_or_create(name=row['capital'])
	capital_obj.latitude = row['latitude']
	capital_obj.longitude = row['longitude']
	capital_obj.population = row['population']
	capital_obj.state = state_obj
Пример #5
0
if "DJANGO_SETTINGS_MODULE" not in os.environ:
    # Set up django
    print("Setting up Django")
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_conf.settings")
    import django
    django.setup()

from django.db.utils import IntegrityError
from main.models import State, District, SubDistrict

fail_message = "bulk_create on {} failed. Falling back to individual saves."
pass_message = "bulk_create on {} succeeded."

if args.states is not None:
    state_dicts = get_state_dicts(args.states)
    states = [State(**d) for d in state_dicts]
    try:
        State.objects.bulk_create(states)
        print(pass_message.format('State'))
    except IntegrityError:
        print(fail_message.format('State'))
        for state in states:
            state.save()

if args.districts is not None:
    district_dicts = get_district_dicts(args.districts)
    districts = [District(**d) for d in district_dicts]
    try:
        District.objects.bulk_create(districts)
        print(pass_message.format('District'))
    except IntegrityError: