diff --git a/h5pp/h5p/h5pmodule.py b/h5pp/h5p/h5pmodule.py index 8e4cfa9..32f66e8 100644 --- a/h5pp/h5p/h5pmodule.py +++ b/h5pp/h5p/h5pmodule.py @@ -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') @@ -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 @@ -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() + ] \ No newline at end of file diff --git a/h5pp/views.py b/h5pp/views.py index 579dd16..f4062dd 100644 --- a/h5pp/views.py +++ b/h5pp/views.py @@ -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')