def post(self, request): form = LoginForm() submitted_form = self.form_class(request.POST) if submitted_form.is_valid(): try: username = submitted_form.cleaned_data["username"] password = submitted_form.cleaned_data["password"] user = authenticate(username=username, password=password) if user is not None: login(request, user) """ Querying MTG DB for random 200 cards vs entire collection of 37000. Could query asynchonously to save time or save one through caching and then move to static files during production??? """ cache.set( "small_card_set", Card.where(page=1).where(pageSize=20, random=True).all(), 200) # Setting total card type in cache cache.set("card_type_total", Type.all(), 200) # Setting total card substype in cache cache.set("card_subtype_total", Subtype.all(), 200) return redirect("/home") else: messages.warning( request, 'Username or password does not match our records') return redirect("/login") except: messages.warning( request, 'Username or password does not match our records') return render(request, self.template_name, {"form": form})
def test_all_returns_types(self): with vcr.use_cassette('fixtures/types.yaml'): types = Type.all() #API returns some erroneous values, but this line is correct #Remove temporary line and uncomment this line when API is updated #self.assertEqual(["Artifact","Card","Conspiracy","Creature","Emblem","Enchantment","Host","Instant","Land","Phenomenon","Plane","Planeswalker","Scheme","Sorcery","Summon","Tribal","Vanguard","You'll"], types) self.assertEqual(["Artifact","Card","Conspiracy","Creature","Emblem","Enchantment","Hero","instant","Instant","Land","Phenomenon","Plane","Planeswalker","Scheme","Sorcery","Summon","Tribal","Vanguard","You’ll"], types)
def test_all_returns_types(self): with vcr.use_cassette('fixtures/types.yaml'): types = Type.all() self.assertEqual([ "Artifact", "Conspiracy", "Creature", "Enchantment", "Host", "Instant", "Land", "Phenomenon", "Plane", "Planeswalker", "Scheme", "Sorcery", "Tribal", "Vanguard" ], types)
def GetAllTypes(): mtgtypes = MTGType.all() types = [] for mtgtype in mtgtypes: typee = Objects.Type(0, mtgtype) types.append(typee) return types
def get(self, request): card_types = Type.all() context = { "types": card_types, "card_type_total": len(cache.get("card_type_total")), "card_subtype_total": len(cache.get("card_subtype_total")) } print("card types {}".format(card_types)) print("card types from cache {}".format(cache.get("card_type_total"))) return render(request, self.template_name, context)
def test_all_returns_types(self): with vcr.use_cassette('fixtures/types.yaml'): types = Type.all() self.assertEqual(["Artifact","Conspiracy","Creature","Enchantment","Instant","Land","Phenomenon","Plane","Planeswalker","Scheme","Sorcery","Tribal","Vanguard"], types)
def importCard(request): supertypes = Supertype.all() for supertypes in supertypes: types = SuperTypes() types.supertype = supertypes types.save() subtypes = Subtype.all() for subtype in subtypes: sub = SubTypes() sub.subtype = subtype sub.save() types = Type.all() for type in types: t = Types() t.type = type t.save() color1 = Color() color1.color = "White" color1.colorIdentity = "W" color1.save() color2 = Color() color2.color = "Red" color2.colorIdentity = "R" color2.save() color3 = Color() color3.color = "Green" color3.colorIdentity = "G" color3.save() color4 = Color() color4.color = "Black" color4.colorIdentity = "B" color4.save() color = Color() color.color = "Uncolor" color.colorIdentity = "U" color.save() color.color = "Blue" color.colorIdentity = "B" color.save() i = 0 while i <= 0: cards = Card.where(page=i).where(pageSize=1).all() if len(cards) > 0: for card in cards: c = CardU() c.cardName = card.name c.cmc = card.cmc c.type = card.type c.rarity = card.rarity c.text = card.text c.number = card.number """if hasattr(card, 'manaCost'):""" c.mana = card.manaCost if card.colors: identity = card.colors[0] colors = Color.objects.filter(color=identity).values() c.power = card.power """if hasattr(card, 'multiverseid'):""" c.multiverseid = card.multiverseid if hasattr(card, 'foreignNames'): for translate in card.foreignnames: if translate.language == "French": frenchTrad = CardTraduction() frenchTrad.imageUrl = translate.imageUrl frenchTrad.language = "French" frenchTrad.text = translate.text frenchTrad.cardId = translate.multiverseid frenchTrad.save() c.traduction = frenchTrad.id c.save() i += 1 else: i = 1 return render(request, 'app/index.html', {"len": len(cards)})