Skip to content

Commit

Permalink
removing dajaxice requirement, 'manual' ajax requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmarcondes committed Mar 28, 2014
1 parent c33a86c commit 5920296
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 24 deletions.
2 changes: 0 additions & 2 deletions escenario/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
'dajaxice.finders.DajaxiceFinder',
)

# Make this unique, and don't share it with anybody.
Expand Down Expand Up @@ -136,7 +135,6 @@
# 'django.contrib.admindocs',
'generator',
'south',
'dajaxice',
)

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
Expand Down
3 changes: 1 addition & 2 deletions escenario/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{% load staticfiles %}
{% load dajaxice_templatetags %}
<html>
<head>
{% dajaxice_js_import %}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body background="{% static 'background.gif' %}">

Expand Down
8 changes: 6 additions & 2 deletions escenario/templates/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2>FALTA!! OE PENALTI!!</h2>
<span style="padding-right:15px;">
<a href="{{ esc.img_id }}"><img width=300 src="{{ esc.img_id }}" alt="{{ esc.esc.titulo }}" ></a>
<span style="font-size:36px;" id="span{{ esc.id }}">{{ esc.votos }}</span>
<input type="button" name="click{{ esc.id }}" onclick="Dajaxice.generator.vote_escimg(vote_callback, {'id': {{ esc.id }} })" value="+1"/>
<input type="button" name="click{{ esc.id }}" onclick="vote_callback({{ esc.id }})" value="+1"/>
</span>
{% endfor %}

Expand All @@ -40,7 +40,11 @@ <h2>FALTA!! OE PENALTI!!</h2>
{% block scripts %}
<script>
function vote_callback(data){
document.getElementById('span' + data.id).innerHTML = data.votos;
result = $.get("/api/vote/" + data,
function(result) {
document.getElementById('span' + result.id).innerHTML = result.votos;
},
"json")
}
</script>
{% endblock %}
11 changes: 0 additions & 11 deletions generator/ajax.py

This file was deleted.

6 changes: 1 addition & 5 deletions generator/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.conf.urls import patterns, include, url
from views import Home, About, List, Restricted
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from dajaxice.core import dajaxice_autodiscover, dajaxice_config

dajaxice_autodiscover()

urlpatterns = patterns('',
url(r'^$', Home.as_view()),
Expand All @@ -14,8 +11,7 @@
url(r'^restricted/$', Restricted.as_view()),
url(r'^api/list/$', 'generator.views.api_list'),
url(r'^api/create/$', 'generator.views.api_create'),

url(dajaxice_config.dajaxice_url, include('dajaxice.urls')),
url(r'^api/vote/(?P<escimg_id>\d+)$', 'generator.views.api_vote'),
)

urlpatterns += staticfiles_urlpatterns()
8 changes: 8 additions & 0 deletions generator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ class Restricted(View):
def get(self, request):
return render(request, self.template_name, {})


def api_vote(request, escimg_id):
print "called api"
escimg = EscImg.objects.get(id=int(escimg_id))
votos = escimg.gostei()
escimg.save()
result = {'id': escimg.id, 'votos': votos}
return HttpResponse(json.dumps(result), mimetype='application/json')
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ South==0.8.2
coverage==3.7
dj-database-url==0.2.2
dj-static==0.0.5
django-dajax==0.9.2
django-dajaxice==0.5.5
django-toolbelt==0.0.1
gunicorn==18.0
mock==1.0.1
Expand Down

0 comments on commit 5920296

Please sign in to comment.