From b5898d7cf105f6452520c52f0dd384ca187df872 Mon Sep 17 00:00:00 2001 From: Evin Jaff Date: Sat, 13 Jul 2024 19:05:13 -0500 Subject: [PATCH] Cross-gen in submit form works better --- ..._pokemon_pokemon_compatible_generations.py | 17 + server/pokepoll/models.py | 1 - .../static/pokepoll/autocomplete_form_ui.js | 10 +- .../pokepoll/held_items_to_id_gen_5.json | 323 ++++++++++++++++++ .../pokepoll/pokemon_ability_to_id_gen_5.json | 2 +- server/pokepoll/support/cachedconstants.py | 2 +- .../templates/pokepoll/master_submit.html | 48 ++- server/pokepoll/views.py | 35 +- 8 files changed, 411 insertions(+), 27 deletions(-) create mode 100644 server/pokepoll/migrations/0015_remove_pokemon_pokemon_compatible_generations.py create mode 100644 server/pokepoll/static/pokepoll/held_items_to_id_gen_5.json diff --git a/server/pokepoll/migrations/0015_remove_pokemon_pokemon_compatible_generations.py b/server/pokepoll/migrations/0015_remove_pokemon_pokemon_compatible_generations.py new file mode 100644 index 0000000..2cf42a9 --- /dev/null +++ b/server/pokepoll/migrations/0015_remove_pokemon_pokemon_compatible_generations.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.6 on 2024-07-13 23:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('pokepoll', '0014_alter_pokemon_pokemon_intended_generation'), + ] + + operations = [ + migrations.RemoveField( + model_name='pokemon', + name='pokemon_compatible_generations', + ), + ] diff --git a/server/pokepoll/models.py b/server/pokepoll/models.py index 6e8ef34..7283658 100644 --- a/server/pokepoll/models.py +++ b/server/pokepoll/models.py @@ -36,7 +36,6 @@ class Pokemon(models.Model): pokemon_held_item = models.IntegerField(default=0) pokemon_is_shiny = models.BooleanField(default=False) pokemon_intended_generation = models.IntegerField(default=4, choices=[(1, "Gen 1"), (2, "Gen 2"), (3, "Gen 3"), (4, "Gen 4"), (5, "Gen 5"), (6, "Gen 6"), (7, "Gen 7"), (8, "Gen 8")]) - pokemon_compatible_generations = models.JSONField(default=list([4])) pub_date = models.DateTimeField("date published") diff --git a/server/pokepoll/static/pokepoll/autocomplete_form_ui.js b/server/pokepoll/static/pokepoll/autocomplete_form_ui.js index 67e784d..ff0e296 100644 --- a/server/pokepoll/static/pokepoll/autocomplete_form_ui.js +++ b/server/pokepoll/static/pokepoll/autocomplete_form_ui.js @@ -1,5 +1,7 @@ -function autocomplete(inp, arr) { +function autocomplete(inp, arr, selectionCallback) { + // selectionCallback is a lambda that should be called when a selection is made + /*the autocomplete function takes two arguments, the text field element and an array of possible autocompleted values:*/ var currentFocus; @@ -34,6 +36,12 @@ function autocomplete(inp, arr) { /*close the list of autocompleted values, (or any other open lists of autocompleted values:*/ closeAllLists(); + if (selectionCallback){ + selectionCallback(); + } + else { + console.log("No selection callback provided"); + } }); a.appendChild(b); } diff --git a/server/pokepoll/static/pokepoll/held_items_to_id_gen_5.json b/server/pokepoll/static/pokepoll/held_items_to_id_gen_5.json new file mode 100644 index 0000000..a3a5e71 --- /dev/null +++ b/server/pokepoll/static/pokepoll/held_items_to_id_gen_5.json @@ -0,0 +1,323 @@ +{ + "None": 0, + "Master Ball": 1, + "Ultra Ball": 2, + "Great Ball": 3, + "Poké Ball": 4, + "Safari Ball": 5, + "Net Ball": 6, + "Dive Ball": 7, + "Nest Ball": 8, + "Repeat Ball": 9, + "Timer Ball": 10, + "Luxury Ball": 11, + "Premier Ball": 12, + "Dusk Ball": 13, + "Heal Ball": 14, + "Quick Ball": 15, + "Cherish Ball": 16, + "Potion": 17, + "Antidote": 18, + "Burn Heal": 19, + "Ice Heal": 20, + "Awakening": 21, + "Parlyz Heal": 22, + "Full Restore": 23, + "Max Potion": 24, + "Hyper Potion": 25, + "Super Potion": 26, + "Full Heal": 27, + "Revive": 28, + "Max Revive": 29, + "Fresh Water": 30, + "Soda Pop": 31, + "Lemonade": 32, + "Moomoo Milk": 33, + "EnergyPowder": 34, + "Energy Root": 35, + "Heal Powder": 36, + "Revival Herb": 37, + "Ether": 38, + "Max Ether": 39, + "Elixir": 40, + "Max Elixir": 41, + "Lava Cookie": 42, + "Berry Juice": 43, + "Sacred Ash": 44, + "HP Up": 45, + "Protein": 46, + "Iron": 47, + "Carbos": 48, + "Calcium": 49, + "Rare Candy": 50, + "PP Up": 51, + "Zinc": 52, + "PP Max": 53, + "Old Gateau": 54, + "Guard Spec.": 55, + "Dire Hit": 56, + "X Attack": 57, + "X Defense": 58, + "X Speed": 59, + "X Accuracy": 60, + "X Sp. Atk": 61, + "X Sp. Def": 62, + "Poké Doll": 63, + "Fluffy Tail": 64, + "Blue Flute": 65, + "Yellow Flute": 66, + "Red Flute": 67, + "Black Flute": 68, + "White Flute": 69, + "Shoal Salt": 70, + "Shoal Shell": 71, + "Red Shard": 72, + "Blue Shard": 73, + "Yellow Shard": 74, + "Green Shard": 75, + "Super Repel": 76, + "Max Repel": 77, + "Escape Rope": 78, + "Repel": 79, + "Sun Stone": 80, + "Moon Stone": 81, + "Fire Stone": 82, + "Thunder Stone": 83, + "Water Stone": 84, + "Leaf Stone": 85, + "TinyMushroom": 86, + "Big Mushroom": 87, + "Pearl": 88, + "Big Pearl": 89, + "Stardust": 90, + "Star Piece": 91, + "Nugget": 92, + "Heart Scale": 93, + "Honey": 94, + "Growth Mulch": 95, + "Damp Mulch": 96, + "Stable Mulch": 97, + "Gooey Mulch": 98, + "Root Fossil": 99, + "Claw Fossil": 100, + "Helix Fossil": 101, + "Dome Fossil": 102, + "Old Amber": 103, + "Armor Fossil": 104, + "Skull Fossil": 105, + "Rare Bone": 106, + "Shiny Stone": 107, + "Dusk Stone": 108, + "Dawn Stone": 109, + "Oval Stone": 110, + "Odd Keystone": 111, + "Griseous Orb": 112, + "Douse Drive": 116, + "Shock Drive": 117, + "Burn Drive": 118, + "Chill Drive": 119, + "Sweet Heart": 134, + "Adamant Orb": 135, + "Lustrous Orb": 136, + "Greet Mail": 137, + "Favored Mail": 138, + "RSVP Mail": 139, + "Thanks Mail": 140, + "Inquiry Mail": 141, + "Like Mail": 142, + "Reply Mail": 143, + "BridgeMail S": 144, + "BridgeMail D": 145, + "BridgeMail T": 146, + "BridgeMail V": 147, + "BridgeMail M": 148, + "Cheri Berry": 149, + "Chesto Berry": 150, + "Pecha Berry": 151, + "Rawst Berry": 152, + "Aspear Berry": 153, + "Leppa Berry": 154, + "Oran Berry": 155, + "Persim Berry": 156, + "Lum Berry": 157, + "Sitrus Berry": 158, + "Figy Berry": 159, + "Wiki Berry": 160, + "Mago Berry": 161, + "Aguav Berry": 162, + "Iapapa Berry": 163, + "Razz Berry": 164, + "Bluk Berry": 165, + "Nanab Berry": 166, + "Wepear Berry": 167, + "Pinap Berry": 168, + "Pomeg Berry": 169, + "Kelpsy Berry": 170, + "Qualot Berry": 171, + "Hondew Berry": 172, + "Grepa Berry": 173, + "Tamato Berry": 174, + "Cornn Berry": 175, + "Magost Berry": 176, + "Rabuta Berry": 177, + "Nomel Berry": 178, + "Spelon Berry": 179, + "Pamtre Berry": 180, + "Watmel Berry": 181, + "Durin Berry": 182, + "Belue Berry": 183, + "Occa Berry": 184, + "Passho Berry": 185, + "Wacan Berry": 186, + "Rindo Berry": 187, + "Yache Berry": 188, + "Chople Berry": 189, + "Kebia Berry": 190, + "Shuca Berry": 191, + "Coba Berry": 192, + "Payapa Berry": 193, + "Tanga Berry": 194, + "Charti Berry": 195, + "Kasib Berry": 196, + "Haban Berry": 197, + "Colbur Berry": 198, + "Babiri Berry": 199, + "Chilan Berry": 200, + "Liechi Berry": 201, + "Ganlon Berry": 202, + "Salac Berry": 203, + "Petaya Berry": 204, + "Apicot Berry": 205, + "Lansat Berry": 206, + "Starf Berry": 207, + "Enigma Berry": 208, + "Micle Berry": 209, + "Custap Berry": 210, + "Jaboca Berry": 211, + "Rowap Berry": 212, + "BrightPowder": 213, + "White Herb": 214, + "Macho Brace": 215, + "Exp. Share": 216, + "Quick Claw": 217, + "Soothe Bell": 218, + "Mental Herb": 219, + "Choice Band": 220, + "King's Rock": 221, + "Silver Powder": 222, + "Amulet Coin": 223, + "Cleanse Tag": 224, + "Soul Dew": 225, + "DeepSeaTooth": 226, + "DeepSeaScale": 227, + "Smoke Ball": 228, + "Everstone": 229, + "Focus Band": 230, + "Lucky Egg": 231, + "Scope Lens": 232, + "Metal Coat": 233, + "Leftovers": 234, + "Dragon Scale": 235, + "Light Ball": 236, + "Soft Sand": 237, + "Hard Stone": 238, + "Miracle Seed": 239, + "Black Glasses": 240, + "Black Belt": 241, + "Magnet": 242, + "Mystic Water": 243, + "Sharp Beak": 244, + "Poison Barb": 245, + "NeverMeltIce": 246, + "Spell Tag": 247, + "TwistedSpoon": 248, + "Charcoal": 249, + "Dragon Fang": 250, + "Silk Scarf": 251, + "Up-Grade": 252, + "Shell Bell": 253, + "Sea Incense": 254, + "Lax Incense": 255, + "Lucky Punch": 256, + "Metal Powder": 257, + "Thick Club": 258, + "Stick": 259, + "Red Scarf": 260, + "Blue Scarf": 261, + "Pink Scarf": 262, + "Green Scarf": 263, + "Yellow Scarf": 264, + "Wide Lens": 265, + "Muscle Band": 266, + "Wise Glasses": 267, + "Expert Belt": 268, + "Light Clay": 269, + "Life Orb": 270, + "Power Herb": 271, + "Toxic Orb": 272, + "Flame Orb": 273, + "Quick Powder": 274, + "Focus Sash": 275, + "Zoom Lens": 276, + "Metronome": 277, + "Iron Ball": 278, + "Lagging Tail": 279, + "Destiny Knot": 280, + "Black Sludge": 281, + "Icy Rock": 282, + "Smooth Rock": 283, + "Heat Rock": 284, + "Damp Rock": 285, + "Grip Claw": 286, + "Choice Scarf": 287, + "Sticky Barb": 288, + "Power Bracer": 289, + "Power Belt": 290, + "Power Lens": 291, + "Power Band": 292, + "Power Anklet": 293, + "Power Weight": 294, + "Shed Shell": 295, + "Big Root": 296, + "Choice Specs": 297, + "Flame Plate": 298, + "Splash Plate": 299, + "Zap Plate": 300, + "Meadow Plate": 301, + "Icicle Plate": 302, + "Fist Plate": 303, + "Toxic Plate": 304, + "Earth Plate": 305, + "Sky Plate": 306, + "Mind Plate": 307, + "Insect Plate": 308, + "Stone Plate": 309, + "Spooky Plate": 310, + "Draco Plate": 311, + "Dread Plate": 312, + "Iron Plate": 313, + "Odd Incense": 314, + "Rock Incense": 315, + "Full Incense": 316, + "Wave Incense": 317, + "Rose Incense": 318, + "Luck Incense": 319, + "Pure Incense": 320, + "Protector": 321, + "Electirizer": 322, + "Magmarizer": 323, + "Dubious Disc": 324, + "Reaper Cloth": 325, + "Razor Claw": 326, + "Razor Fang": 327, + "TM01": 328, + "TM02": 329, + "TM03": 330, + "TM04": 331, + "TM05": 332, + "TM06": 333 + + + + +} \ No newline at end of file diff --git a/server/pokepoll/static/pokepoll/pokemon_ability_to_id_gen_5.json b/server/pokepoll/static/pokepoll/pokemon_ability_to_id_gen_5.json index bc2ab68..ffae049 100644 --- a/server/pokepoll/static/pokepoll/pokemon_ability_to_id_gen_5.json +++ b/server/pokepoll/static/pokepoll/pokemon_ability_to_id_gen_5.json @@ -1 +1 @@ -{"None": 0, "Stench": 1, "Drizzle": 2, "Speed Boost": 3, "Battle Armor": 4, "Sturdy": 5, "Damp": 6, "Limber": 7, "Sand Veil": 8, "Static": 9, "Volt Absorb": 10, "Water Absorb": 11, "Oblivious": 12, "Cloud Nine": 13, "Compound Eyes": 14, "Insomnia": 15, "Color Change": 16, "Immunity": 17, "Flash Fire": 18, "Shield Dust": 19, "Own Tempo": 20, "Suction Cups": 21, "Intimidate": 22, "Shadow Tag": 23, "Rough Skin": 24, "Wonder Guard": 25, "Levitate": 26, "Effect Spore": 27, "Synchronize": 28, "Clear Body": 29, "Natural Cure": 30, "Lightning Rod": 31, "Serene Grace": 32, "Swift Swim": 33, "Chlorophyll": 34, "Illuminate": 35, "Trace": 36, "Huge Power": 37, "Poison Point": 38, "Inner Focus": 39, "Magma Armor": 40, "Water Veil": 41, "Magnet Pull": 42, "Soundproof": 43, "Rain Dish": 44, "Sand Stream": 45, "Pressure": 46, "Thick Fat": 47, "Early Bird": 48, "Flame Body": 49, "Run Away": 50, "Keen Eye": 51, "Hyper Cutter": 52, "Pickup": 53, "Truant": 54, "Hustle": 55, "Cute Charm": 56, "Plus": 57, "Minus": 58, "Forecast": 59, "Sticky Hold": 60, "Shed Skin": 61, "Guts": 62, "Marvel Scale": 63, "Liquid Ooze": 64, "Overgrow": 65, "Blaze": 66, "Torrent": 67, "Swarm": 68, "Rock Head": 69, "Drought": 70, "Arena Trap": 71, "Vital Spirit": 72, "White Smoke": 73, "Pure Power": 74, "Shell Armor": 75, "Air Lock": 76, "Tangled Feet": 77, "Motor Drive": 78, "Rivalry": 79, "Steadfast": 80, "Snow Cloak": 81, "Gluttony": 82, "Anger Point": 83, "Unburden": 84, "Heatproof": 85, "Simple": 86, "Dry Skin": 87, "Download": 88, "Iron Fist": 89, "Poison Heal": 90, "Adaptability": 91, "Skill Link": 92, "Hydration": 93, "Solar Power": 94, "Quick Feet": 95, "Normalize": 96, "Sniper": 97, "Magic Guard": 98, "No Guard": 99, "Stall": 100, "Technician": 101, "Leaf Guard": 102, "Klutz": 103, "Mold Breaker": 104, "Super Luck": 105, "Aftermath": 106, "Anticipation": 107, "Forewarn": 108, "Unaware": 109, "Tinted Lens": 110, "Filter": 111, "Slow Start": 112, "Scrappy": 113, "Storm Drain": 114, "Ice Body": 115, "Solid Rock": 116, "Snow Warning": 117, "Honey Gather": 118, "Frisk": 119, "Reckless": 120, "Multitype": 121, "Flower Gift": 122, "Bad Dreams": 123, "Pickpocket": 124, "Sheer Force": 125, "Contrary": 126, "Unnerve": 127, "Defiant": 128, "Defeatist": 129, "Cursed Body": 130, "Healer": 131, "Friend Guard": 132, "Weak Armor": 133, "Heavy Metal": 134, "Light Metal": 135, "Multiscale": 136, "Toxic Boost": 137, "Flare Boost": 138, "Harvest": 139, "Telepathy": 140, "Moody": 141, "Overcoat": 142, "Poison Touch": 143, "Regenerator": 144, "Big Pecks": 145, "Sand Rush": 146, "Wonder Skin": 147, "Analytic": 148, "Illusion": 149, "Imposter": 150, "Infiltrator": 151, "Mummy": 152, "Moxie": 153, "Justified": 154, "Rattled": 155, "Magic Bounce": 156, "Sap Sipper": 157, "Prankster": 158, "Sand Force": 159, "Iron Barbs": 160, "Zen Mode": 161, "Victory Star": 162, "Turboblaze": 163} \ No newline at end of file +{"None": 0, "Stench": 1, "Drizzle": 2, "Speed Boost": 3, "Battle Armor": 4, "Sturdy": 5, "Damp": 6, "Limber": 7, "Sand Veil": 8, "Static": 9, "Volt Absorb": 10, "Water Absorb": 11, "Oblivious": 12, "Cloud Nine": 13, "Compound Eyes": 14, "Insomnia": 15, "Color Change": 16, "Immunity": 17, "Flash Fire": 18, "Shield Dust": 19, "Own Tempo": 20, "Suction Cups": 21, "Intimidate": 22, "Shadow Tag": 23, "Rough Skin": 24, "Wonder Guard": 25, "Levitate": 26, "Effect Spore": 27, "Synchronize": 28, "Clear Body": 29, "Natural Cure": 30, "Lightning Rod": 31, "Serene Grace": 32, "Swift Swim": 33, "Chlorophyll": 34, "Illuminate": 35, "Trace": 36, "Huge Power": 37, "Poison Point": 38, "Inner Focus": 39, "Magma Armor": 40, "Water Veil": 41, "Magnet Pull": 42, "Soundproof": 43, "Rain Dish": 44, "Sand Stream": 45, "Pressure": 46, "Thick Fat": 47, "Early Bird": 48, "Flame Body": 49, "Run Away": 50, "Keen Eye": 51, "Hyper Cutter": 52, "Pickup": 53, "Truant": 54, "Hustle": 55, "Cute Charm": 56, "Plus": 57, "Minus": 58, "Forecast": 59, "Sticky Hold": 60, "Shed Skin": 61, "Guts": 62, "Marvel Scale": 63, "Liquid Ooze": 64, "Overgrow": 65, "Blaze": 66, "Torrent": 67, "Swarm": 68, "Rock Head": 69, "Drought": 70, "Arena Trap": 71, "Vital Spirit": 72, "White Smoke": 73, "Pure Power": 74, "Shell Armor": 75, "Air Lock": 76, "Tangled Feet": 77, "Motor Drive": 78, "Rivalry": 79, "Steadfast": 80, "Snow Cloak": 81, "Gluttony": 82, "Anger Point": 83, "Unburden": 84, "Heatproof": 85, "Simple": 86, "Dry Skin": 87, "Download": 88, "Iron Fist": 89, "Poison Heal": 90, "Adaptability": 91, "Skill Link": 92, "Hydration": 93, "Solar Power": 94, "Quick Feet": 95, "Normalize": 96, "Sniper": 97, "Magic Guard": 98, "No Guard": 99, "Stall": 100, "Technician": 101, "Leaf Guard": 102, "Klutz": 103, "Mold Breaker": 104, "Super Luck": 105, "Aftermath": 106, "Anticipation": 107, "Forewarn": 108, "Unaware": 109, "Tinted Lens": 110, "Filter": 111, "Slow Start": 112, "Scrappy": 113, "Storm Drain": 114, "Ice Body": 115, "Solid Rock": 116, "Snow Warning": 117, "Honey Gather": 118, "Frisk": 119, "Reckless": 120, "Multitype": 121, "Flower Gift": 122, "Bad Dreams": 123, "Pickpocket": 124, "Sheer Force": 125, "Contrary": 126, "Unnerve": 127, "Defiant": 128, "Defeatist": 129, "Cursed Body": 130, "Healer": 131, "Friend Guard": 132, "Weak Armor": 133, "Heavy Metal": 134, "Light Metal": 135, "Multiscale": 136, "Toxic Boost": 137, "Flare Boost": 138, "Harvest": 139, "Telepathy": 140, "Moody": 141, "Overcoat": 142, "Poison Touch": 143, "Regenerator": 144, "Big Pecks": 145, "Sand Rush": 146, "Wonder Skin": 147, "Analytic": 148, "Illusion": 149, "Imposter": 150, "Infiltrator": 151, "Mummy": 152, "Moxie": 153, "Justified": 154, "Rattled": 155, "Magic Bounce": 156, "Sap Sipper": 157, "Prankster": 158, "Sand Force": 159, "Iron Barbs": 160, "Zen Mode": 161, "Victory Star": 162, "Turboblaze": 163, "Teravolt": 164} \ No newline at end of file diff --git a/server/pokepoll/support/cachedconstants.py b/server/pokepoll/support/cachedconstants.py index 40489bd..a54ca2f 100644 --- a/server/pokepoll/support/cachedconstants.py +++ b/server/pokepoll/support/cachedconstants.py @@ -38,7 +38,7 @@ MAX_ABILITY_DICT = { 3: 75, 4: 124, - 5: 164, + 5: 165, 6: 191, 7: 233, 8: 267, diff --git a/server/pokepoll/templates/pokepoll/master_submit.html b/server/pokepoll/templates/pokepoll/master_submit.html index 01e7214..f518654 100644 --- a/server/pokepoll/templates/pokepoll/master_submit.html +++ b/server/pokepoll/templates/pokepoll/master_submit.html @@ -538,10 +538,16 @@
Existing user not found, enter your name below and we will create a record a // Parse the JSON data const pokemonNames = await response.json(); // Now you can use the `pokemonNames` variable which contains the parsed JSON data + + pokemonNamesArray = []; + // iterate through json by key + for (let key in pokemonNames) { + pokemonNamesArray[pokemonNames[key]-1] = key; + } - console.log(pokemonNames); + console.log(pokemonNamesArray); - return pokemonNames + return pokemonNamesArray } catch (error) { console.error('There was a problem with the fetch operation:', error); @@ -608,10 +614,10 @@
Existing user not found, enter your name below and we will create a record a } -async function fetchPokemonMoves(pokemon_generation){ +async function fetchPokemonMoves(generation){ try { // Fetch the JSON data - const response = await fetch(STATIC_MOVES_JSON_PATHS[pokemon_generation - 1]); + const response = await fetch(STATIC_MOVES_JSON_PATHS[generation - 1]); @@ -631,14 +637,10 @@
Existing user not found, enter your name below and we will create a record a } -async function fetchPokemonAbilities(max_index){ +async function fetchPokemonAbilities(generation){ try { // Fetch the JSON data - {% with "pokepoll/pokemon_ability_to_id_gen_"|add:pokemon_generation|stringformat:"s"|add:".json" as filename %} - const response = await fetch("{% static filename %}"); - {% endwith %} - - + const response = await fetch(STATIC_ABILITY_JSON_PATHS[generation - 1]); // Check if the fetch was successful if (!response.ok) { @@ -659,7 +661,8 @@
Existing user not found, enter your name below and we will create a record a // Register autocomplete listeners onto elements fetchPokemonNames(current_generation).then(all_pokemon => { - autocomplete(document.getElementById("myInput"), all_pokemon); + console.log(all_pokemon); + autocomplete(document.getElementById("myInput"), all_pokemon, refreshPokemonPreview); COMPLETE_POKEDEX = all_pokemon; }) @@ -794,7 +797,7 @@
Existing user not found, enter your name below and we will create a record a let selected = document.getElementById("{{ pokemon_form.pokemon_intended_generation.id_for_label }}").value; console.log(selected); current_generation = selected; - refreshUI(); + refreshUI(generation_changed=true); refreshPokemonPreview(); }); @@ -809,20 +812,35 @@
Existing user not found, enter your name below and we will create a record a async function refreshUI(generation_changed=false) { console.log("Calling UI Refresh") - console.log(`Status of Global Variables: \n NATURES: ${NATURES} \n NATURES_GEN_3: ${NATURES_GEN_3} \n Current Generation: ${current_generation} \n POKEMON_GENERATION: ${POKEMON_GENERATION} \n max_pokedex_entry: ${max_pokedex_entry}`) + console.log(`Status of Global Variables: \n NATURES: ${NATURES} \n NATURES_GEN_3: ${NATURES_GEN_3} \n Current Generation: ${current_generation} \n POKEMON_GENERATION: ${POKEMON_GENERATION} \n`) //fill_in_generations("{{ pokemon_form.pokemon_compatible_generations.id_for_label }}", current_generation); fill_in_natures("{{ pokemon_form.pokemon_nature.id_for_label }}", current_generation); // update ability and held item autocomplete if the generation changed if (generation_changed) { - fetchPokemonAbilities(max_pokedex_entry).then(all_abilities => { + console.log("Generation Changed to " + current_generation); + + fetchPokemonNames(current_generation).then(all_pokemon => { + autocomplete(document.getElementById("myInput"), all_pokemon, refreshPokemonPreview); + COMPLETE_POKEDEX = all_pokemon; + }) + + fetchPokemonAbilities(current_generation).then(all_abilities => { autocomplete(document.getElementById("ability"), all_abilities); }) - fetchHeldItems(max_pokedex_entry).then(all_items => { + fetchHeldItems(current_generation).then(all_items => { autocomplete(document.getElementById("held_item"), all_items); }) + + // Register autocomplete onto all 4 moves + fetchPokemonMoves(current_generation).then(all_moves => { + for (let i = 1; i <= 4; i++) { + autocomplete(document.getElementById("pokemon_move" + i), all_moves); + } + }) + } } diff --git a/server/pokepoll/views.py b/server/pokepoll/views.py index 87562b9..b216da6 100644 --- a/server/pokepoll/views.py +++ b/server/pokepoll/views.py @@ -86,7 +86,7 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["moves_pretty"] = [] - with open(os.path.join(settings.BASE_DIR, 'pokepoll/static/pokepoll/pokemon_move_to_id_gen_{}.json'.format(settings.POKEMON_GENERATION))) as f: + with open(os.path.join(settings.BASE_DIR, 'pokepoll/static/pokepoll/pokemon_move_to_id_gen_{}.json'.format(context['pokemon'].pokemon_intended_generation))) as f: move_dex = json.load(f) # find the keys that match the values in the pokemon_moves list for move in context['pokemon'].pokemon_moves: @@ -120,8 +120,7 @@ class Meta: 'pokemon_moves', 'pokemon_movespp', 'pokemon_is_shiny', - 'pokemon_intended_generation', - 'pokemon_compatible_generations'] + 'pokemon_intended_generation'] class SubmitterForm(forms.ModelForm): class Meta: @@ -148,9 +147,15 @@ class CaptchaTestForm(forms.Form): for game in PKHEX_GAMECODES: pokemon_choices += ((PKHEX_GAMECODES[game], game),) + generation_choices = () + + for generation in range(1, 10): + generation_choices += ((generation, "Generation {}".format(generation)),) + pokemon_game = forms.ChoiceField(choices=pokemon_choices, required=True, label="Game") - - num_eggs = forms.IntegerField(min_value=1, max_value=50) + egg_or_level1 = forms.ChoiceField(choices=[(1, "Egg"), (0, "Level 1")], required=True, label="Egg or Level 1") + allowed_generations = forms.MultipleChoiceField(choices=generation_choices, required=True, label="Allowed Generations") + num_eggs = forms.IntegerField(min_value=1, max_value=50, required=True, label="Number of Eggs") import random from django.db.models import Max, Min @@ -158,10 +163,14 @@ class CaptchaTestForm(forms.Form): def get_random_objects(model, count): max_id = model.objects.aggregate(max_id=Max("id"))['max_id'] min_id = model.objects.aggregate(min_id=Min("id"))['min_id'] - + if max_id is None or min_id is None: return model.objects.none() # No objects in the model + # check quantity of objects in the model + if count < model.objects.count(): + raise ValueError("Count must be greater than the number of objects in the model") + random_ids = set() while len(random_ids) < count: random_id = random.randint(min_id, max_id) @@ -259,6 +268,14 @@ def post(self, request, *args, **kwargs): # add validation here + # get the intended generation of the pokemon + # if the generation is not in the range of 1-8, return an error + pokemon_generation = int(request.POST.get('pokemon_intended_generation')) + if pokemon_generation not in range(1, 9): + return Http404("Invalid Generation") + + + # if email is in database foreign_key = None pokemon_species = None @@ -314,7 +331,7 @@ def post(self, request, *args, **kwargs): pokemon_held_item = request.POST.get('pokemon_held_item') # Translate strings to ints - with open(os.path.join(settings.BASE_DIR, 'pokepoll/static/pokepoll/held_items_to_id_gen_{}.json'.format(settings.POKEMON_GENERATION))) as f: + with open(os.path.join(settings.BASE_DIR, 'pokepoll/static/pokepoll/held_items_to_id_gen_{}.json'.format(pokemon_generation))) as f: item_dex = json.load(f) if pokemon_held_item in item_dex: pokemon_held_item = item_dex[request.POST.get('pokemon_held_item')] @@ -323,7 +340,7 @@ def post(self, request, *args, **kwargs): pokemon_moves = [] # populate moves with the values from the form - with open(os.path.join(settings.BASE_DIR, 'pokepoll/static/pokepoll/pokemon_move_to_id_gen_{}.json'.format(settings.POKEMON_GENERATION))) as f: + with open(os.path.join(settings.BASE_DIR, 'pokepoll/static/pokepoll/pokemon_move_to_id_gen_{}.json'.format(pokemon_generation))) as f: move_dex = json.load(f) for i in range(4): move = request.POST.get('pokemon_move' + str(i + 1)) @@ -361,6 +378,8 @@ def post(self, request, *args, **kwargs): 'pokemon_held_item': pokemon_held_item, 'pokemon_moves': pokemon_moves, 'pokemon_nature': pokemon_nature, + 'pokemon_intended_generation': pokemon_generation, + }