Beispiel #1
0
def reload_configs(request):
    flush_all_tables()
    response = {}
    json_data = open(CONFIG_FILE_PATH, "r")
    try:
        configjson = simplejson.load(json_data)
    except ValueError:
        response['status_code'] = 400
        response["response"] = "Error parsing json file"
        return HttpResponse(simplejson.dumps(response), mimetype="application/json")
    json_data.close()
    champions = configjson["champions"]
    for champion in champions:
        championobject = None
        try:
            championobject = Champion.objects.get(name=champion["name"])
        except ObjectDoesNotExist:
            positions = champion["positions"]
            championobject = Champion(name=champion["name"], top=positions["top"], jungle=positions["jungle"], mid=positions["mid"], adc=positions["adc"], support=positions["support"])
            championobject.save()
            counterlist = CounterList(champion=championobject)
            counterlist.save()
        else:
            update_positions(championobject, champion["positions"])
        update_counters(championobject, champion["counters"])
        update_champion_compositions(championobject, champion["compositions"])
    response['status_code'] = 200
    response["response"] = "Reload successful"
    return HttpResponse(simplejson.dumps(response), mimetype="application/json")
Beispiel #2
0
def update_counters(champion, counters):
    for counter in counters:
        championcounter = None
        try:
            championcounter = Champion.objects.get(name=counter["name"])
        except ObjectDoesNotExist:
            championcounter = Champion(name=counter["name"], top=0, jungle=0, mid=0, adc=0, support=0)
            championcounter.save()
            counterlist = CounterList(champion=championcounter)
            counterlist.save()
        counterlist = champion.counterlist
        c = Counter(champion=championcounter, strength=counter["strength"], championlist=counterlist)
        c.save()