Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #10 from DrClockwork/dev
Browse files Browse the repository at this point in the history
hotfix_add ajax for score
  • Loading branch information
DrClockwork committed Jun 26, 2017
2 parents de2686a + afc1a5e commit 4e8c280
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion h5pp/h5p/h5pmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def h5pAddIframeAssets(request, integration, contentId, files):
'cid-' + contentId]['scripts'] = core.getAssetsUrls(files['scripts'])


def getUserScore(contentId, user=None):
def getUserScore(contentId, user=None, ajax=False):
if user != None:
score = h5p_points.objects.filter(
content_id=contentId, uid=user.id).values('points', 'max_points')
Expand All @@ -565,6 +565,8 @@ def getUserScore(contentId, user=None):
user['user'] = User.objects.get(id=user['user']).username

if len(score) > 0:
if ajax:
return json.dumps(list(score))
return score

return None
Expand Down Expand Up @@ -625,3 +627,13 @@ def h5pIsExternalAsset(path):

def libraryToString(library, folderName=False):
return str(library["machineName"] if 'machineName' in library else library['name'] + ("-" if folderName else " ") + str(library["majorVersion"]) + "." + str(library["minorVersion"]))

##
# Returns all rows from a cursor as a dict
##
def dictfetchall(self, cursor):
desc = cursor.description
return [
dict(zip([col[0] for col in desc], row))
for row in cursor.fetchall()
]
7 changes: 7 additions & 0 deletions h5pp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,11 @@ def ajax(request):
data,
content_type='application/json'
)

elif 'user-scores' in request.GET:
score = getUserScore(request.GET['user-scores'], None, True)
return HttpResponse(
score,
content_type='application/json'
)
return HttpResponseRedirect('/h5p/create')

0 comments on commit 4e8c280

Please sign in to comment.