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 #15 from DrClockwork/dev
Browse files Browse the repository at this point in the history
Dev to Master
  • Loading branch information
DrClockwork authored Feb 19, 2018
2 parents 1ea593e + d34f7a3 commit 28058b3
Show file tree
Hide file tree
Showing 16 changed files with 873 additions and 397 deletions.
42 changes: 13 additions & 29 deletions h5pp/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,39 @@
from h5pp.models import *

class LibrariesAdmin(admin.ModelAdmin):
list_display = ('title', 'machine_name', 'library_id')
ordering = ('title', 'machine_name')
list_display = ('title', 'library_id')
ordering = ('title', 'library_id')
readonly_fields = ('library_id', 'major_version', 'minor_version', 'patch_version')
exclude = ('restricted', 'runnable')

admin.site.register(h5p_libraries, LibrariesAdmin)

class LibrariesLanguageAdmin(admin.ModelAdmin):
list_display = ('library_id', 'language_code')
ordering = ('library_id', 'language_code')
readonly_fields = ('library_id',)

admin.site.register(h5p_libraries_languages, LibrariesLanguageAdmin)

class LibrariesLibrariesAdmin(admin.ModelAdmin):
list_display = ('library_id', 'required_library_id', 'dependency_type')
ordering = ('library_id', 'required_library_id')

admin.site.register(h5p_libraries_libraries, LibrariesLibrariesAdmin)

class ContentsAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'content_type')
ordering = ('title', 'author')
readonly_fields = ('content_id', 'main_library_id')
exclude = ('disable',)

admin.site.register(h5p_contents, ContentsAdmin)

class ContentsLibrariesAdmin(admin.ModelAdmin):
list_display = ('content_id', 'library_id', 'dependency_type')
ordering = ('content_id', 'library_id')

admin.site.register(h5p_contents_libraries, ContentsLibrariesAdmin)

class PointsAdmin(admin.ModelAdmin):
list_display = ('content_id', 'uid', 'points', 'max_points')
ordering = ('content_id', 'uid')
readonly_fields = ('content_id', 'uid')
exclude = ('started', 'finished')

admin.site.register(h5p_points, PointsAdmin)

class ContentUserAdmin(admin.ModelAdmin):
list_display = ('user_id', 'content_main_id')
ordering = ('user_id', 'content_main_id')

admin.site.register(h5p_content_user_data, ContentUserAdmin)

class EventsAdmin(admin.ModelAdmin):
list_display = ('user_id', 'type', 'sub_type', 'library_name')
ordering = ('user_id', 'type')

admin.site.register(h5p_events, EventsAdmin)

class CountersAdmin(admin.ModelAdmin):
list_display = ('type', 'library_name', 'num')
ordering = ('type', 'library_name')
list_display = ('user_id', 'type', 'sub_type')
ordering = ('type', 'sub_type')
readonly_fields = ('user_id', 'created_at', 'type', 'sub_type', 'content_id', 'content_title', 'library_name', 'library_version')

admin.site.register(h5p_counters, CountersAdmin)
admin.site.register(h5p_events, EventsAdmin)
12 changes: 8 additions & 4 deletions h5pp/h5p/h5pclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from django.conf import settings
from django.contrib import messages
from django.db import connection
from h5pp.models import h5p_libraries, h5p_libraries_libraries, h5p_libraries_languages, h5p_contents, h5p_counters, h5p_contents_libraries, h5p_content_user_data
from django.template.defaultfilters import slugify
from h5pp.models import *
from h5pp.h5p.h5pevent import H5PEvent
from h5pp.h5p.library.h5pclasses import H5PCore, H5PValidator, H5PStorage, H5PContentValidator, H5PExport
from h5pp.h5p.library.h5pclasses import *
from h5pp.h5p.editor.h5peditorclasses import H5PDjangoEditor
from h5pp.h5p.editor.library.h5peditorstorage import H5PEditorStorage
import collections
Expand Down Expand Up @@ -68,7 +69,7 @@ def getPlatformInfo(self):
return {
'name': 'django',
'version': django.get_version(),
'h5pVersion': h5pInfo
'h5pVersion': '7.x'
}
##
# Fetches a file from a remote server using HTTP GET
Expand Down Expand Up @@ -367,6 +368,7 @@ def updateContent(self, content, contentMainId=None):
update.main_library_id = content['library']['libraryId']
update.filtered = ''
update.disable = content['disable']
update.slug = slugify(content['title'])
update.save()

# Derive library data from string
Expand All @@ -391,11 +393,12 @@ def insertContent(self, content, contentMainId=None):
title=content['title'],
json_contents=content['params'],
embed_type='div',
content_type=content['library']['machineName'],
main_library_id=content['library']['libraryId'],
author=content['author'],
disable=content['disable'],
filtered='',
slug='')
slug=slugify(content['title']))

event = H5PEvent('content', 'create', result.content_id, content['title'] if 'title' in content else '', content[
'library']['machineName'], str(content['library']['majorVersion']) + '.' + str(content['library']['minorVersion']))
Expand Down Expand Up @@ -549,6 +552,7 @@ def loadContent(self, pid):
hn.title,
hn.json_contents AS params,
hn.embed_type,
hn.content_type,
hn.author,
hl.library_id,
hl.machine_name AS library_name,
Expand Down
64 changes: 45 additions & 19 deletions h5pp/h5p/h5pmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ def h5pUpdate(request):


def h5pDelete(request):
res = h5p_contents.objects.filter(content_id=request.GET['contentId']).extra(
select={'id': 'content_id'}).values('id', 'slug')
for content in res:
h5pDeleteH5PContent(request, content)
content = h5p_contents.objects.get(content_id=request.GET['contentId'])
h5pDeleteH5PContent(request, content)

if 'main_library' in request.POST:
# Log content delete
Expand All @@ -132,11 +130,11 @@ def h5pDeleteH5PContent(request, content):
storage.deletePackage(content)

# Remove content points
h5p_points.objects.filter(content_id=content['id']).delete()
h5p_points.objects.filter(content_id=content.content_id).delete()

# Remove content user data
h5p_content_user_data.objects.filter(
content_main_id=content['id']).delete()
content_main_id=content.content_id).delete()


def h5pLoad(request):
Expand Down Expand Up @@ -504,9 +502,7 @@ def h5pAddIframeAssets(request, integration, contentId, files):
integration['core']['scripts'] = assets['js']
integration['core']['styles'] = assets['css']

writable = os.path.exists(settings.H5P_PATH)
# Temp
writable = False
writable = False # Temporary, future feature
if writable:
if not os.path.exists(os.path.join(settings.H5P_PATH, 'files')):
os.mkdir(os.path.join(settings.H5P_PATH, 'files'))
Expand Down Expand Up @@ -587,21 +583,51 @@ def h5pEmbed(request):

def getUserScore(contentId, user=None, ajax=False):
if user != None:
score = h5p_points.objects.filter(
scores = h5p_points.objects.filter(
content_id=contentId, uid=user.id).values('points', 'max_points')
else:
score = h5p_points.objects.filter(content_id=contentId).extra(
select={'user': 'uid'}).values('user', 'points', 'max_points')
for user in score:
user['user'] = User.objects.get(id=user['user']).username

if len(score) > 0:
scores = h5p_points.objects.filter(content_id=contentId)
for score in scores:
score.uid = User.objects.get(id=score.uid).username
score.has_finished = score.finished >= score.started
score.points = '..' if score.points == None else score.points
score.max_points = '..' if score.max_points == None else score.max_points

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

return None

def exportScore(contentId=None):
response = ''
if contentId:
scores = h5p_points.objects.filter(content_id=contentId)
content = h5p_contents.objects.get(content_id=contentId)
response = response + '[Content] : %s - [Users] : %s\n' % (content.title, len(scores))
for score in scores:
score.uid = User.objects.get(id=score.uid).username
score.has_finished = 'Completed' if score.finished >= score.started else 'Not completed'
score.points = '..' if score.points == None else score.points
score.max_points = '..' if score.max_points == None else score.max_points
response = response + '[Username] : %s | [Current] : %s | [Max] : %s | [Progression] : %s\n' % (score.uid, score.points, score.max_points, score.has_finished)
return response

scores = h5p_points.objects.all()
response = response + '[Users] : %s\n' % len(scores)
currentContent = ''
for score in scores:
content = h5p_contents.objects.get(content_id=score.content_id)
if content.content_id != currentContent:
response = response + '--------------------\n[Content] : %s\n--------------------\n' % content.title
score.uid = User.objects.get(id=score.uid).username
score.has_finished = 'Completed' if score.finished >= score.started else 'Not completed'
score.points = '..' if score.points == None else score.points
score.max_points = '..' if score.max_points == None else score.max_points
response = response + '[Username] : %s | [Current] : %s | [Max] : %s | [Progression] : %s\n' % (score.uid, score.points, score.max_points, score.has_finished)
currentContent = content.content_id
return response
##
# Uninstall H5P
##
Expand Down Expand Up @@ -667,4 +693,4 @@ def dictfetchall(self, cursor):
return [
dict(zip([col[0] for col in desc], row))
for row in cursor.fetchall()
]
]
Loading

3 comments on commit 28058b3

@Tasm-Devil
Copy link

@Tasm-Devil Tasm-Devil commented on 28058b3 Feb 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!
I got two problems after installing the package via pip in my virtualenv and editing settings.py and urls.py as described here.

from django.conf.urls import url, include

urlpatterns = [
    ...
    url(r'^h5p/', include('h5pp.urls')),
]

This doesn't work on django>=10. I get an Error:

TypeError: view must be a callable or a list/tuple in the case of include().

I switched to django<10 and I got no Error. But then I run makemigrations, migrate and runserver and opened http://localhost:8000/h5p/home

ImportError at /h5p/home

I'm new to django and i have no clue how to fix this. Here is the traceback

EDIT:
I found a solution. I had to install these two packages:

pip install requests
pip install image

@Tasm-Devil
Copy link

@Tasm-Devil Tasm-Devil commented on 28058b3 Feb 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it to the point where i have to upload the h5p-file. After choosing the file, the label says:
Selected file: C:\fakepath\official-h5p-release-20170301.h5p
but there is no way to proceed ??? Where do I have to click. I feel so dump, the there is no message, no button, no error message.

EDIT:
<div class="configuration" align="center"> was set to display:none. I removed this property in my DOM-Inspector and suddenly I saw the button to install. Wow, that was a journey. I hope this comment will help you to fix this problem. I would add a pull request if I were able to.

@DrClockwork
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi !
Yes it's a mistake with my indentation. The input 'proceed' must be outside the div 'configuration'.
I'll fix that next week after my holidays. In addition, the compatibility with django 1.11 will arrive in June (and thus the porting of the code in python 3).

Next time you can use the 'issue' section if you spot other bugs. This allows me to have a better tracking of identified bugs.

Thank you for your help !

Please sign in to comment.