Ejemplo n.º 1
0
def transform_string_into_card(str):

	info_list = str.split("###")
	
	nome = info_list[0]
	
	cor = ""
	custo = ""
	tipo = ""
	poder_resistencia = ""
	texto = ""
	
	raridade = info_list[1]
	edicao = info_list[2]
	
	card = cartas_mtg(nome = nome,
					cor = cor,
					custo = custo,
					tipo = tipo,
					poder_resistencia = poder_resistencia,
					texto = texto,
					raridade = raridade,
					edicao = edicao)
	
	return card
Ejemplo n.º 2
0
def add_card_to_db(request):

    name = ""
    colour = ""
    cost = ""
    type = ""
    power_resistance = ""
    text = ""
    rarity = ""
    edition = ""
    quantidade = None
    importancia = None

    try:
        name = request.POST["name"]
        colour = request.POST["colour"]
        cost = request.POST["cost"]
        type = request.POST["type"]
        power_resistance = request.POST["power_resistance"]
        text = request.POST["text"]
        rarity = request.POST["rarity"]
        edition = request.POST["edition"]
        quantidade = int(request.POST["stock"])
        importancia = int(request.POST["importance"])

    except:
        return HttpResponse("Erro nos dados da carta " + name)

    if len(text) > 500:
        logging.info(name)
        text = text[:500]

        # cleans % from text
    text = text.replace("%", "")

    if rarity == "R" or rarity == "R // R":
        rarity = "Rare"

    if rarity == "M" or rarity == "M // M":
        rarity = "Mytic"

    if rarity == "U" or rarity == "U // U":
        rarity = "Uncommon"

    if rarity == "C" or rarity == "C // C":
        rarity = "Common"

    carta_comparacao = cartas_mtg.all().filter("nome =", name).filter("edicao =", edition).get()

    if carta_comparacao != None:
        return HttpResponse("Carta jah existe " + name)

    card = cartas_mtg(
        nome=name,
        cor=colour,
        custo=cost,
        tipo=type,
        poder_resistencia=power_resistance,
        texto=text,
        raridade=rarity,
        random_number=random_utils.get_random_number(),
        stock=int(quantidade),
        importance=int(importancia),
        edicao=edition,
    )

    card.put_DB()

    return HttpResponse("Success")