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 #3 from DrClockwork/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DrClockwork authored Apr 19, 2017
2 parents 9eacbc3 + 5f568d4 commit 584b121
Show file tree
Hide file tree
Showing 21 changed files with 811 additions and 433 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
H5PP is a port of H5P by Joubel to the Python language and the web framework Django. H5P makes it easy to create, share and reuse HTML5 content and applications. Authors may create and edit interactive video, presentations, games, advertisements and more. Content may be imported and exported. All that is needed to view or edit H5P content is a web browser.

## Quick start
1. Add 'h5pp' to your INSTALLED_APPS settings like this :
1. Install H5PP packages with pip :
<pre><code>
pip install H5PP-0.1.tar.gz
</code></pre>

2. Add 'h5pp' to your INSTALLED_APPS settings like this :
<pre><code>
INSTALLED_APPS = [
...
'h5pp',
]
</code></pre>

2. Include the h5pp Urlconf in your project urls.py like this :
3. Include the h5pp Urlconf in your project urls.py like this :
<pre><code>
url(r'^h5p/', include('h5pp.urls'))
</code></pre>

3. Include these variables into the settings.py file of your Django project :
4. Include these variables into the settings.py file of your Django project :
<pre><code>
H5P_VERSION = '7.x'
H5P_DEV_MODE = 0
Expand All @@ -25,16 +30,17 @@ H5P_URL = '/h5p/'
H5P_SAVE = 30
H5P_EXPORT = '/exports/'
H5P_LANGUAGE = 'en'
BASE_URL = 'http://localhost:8000' # Hostname of your server
</code></pre>
Beta version use the inner system of login of Django. So don't forget to set your `LOGIN_URL` and `LOGIN_REDIRECT_URL` variables in your settings.

4. If not already done. Make a 'media' directory at the root of your Django project.
5. If not already done. Make a 'media' directory at the root of your Django project.

5. Run `python manage.py migrate` to create the h5pp models.
6. Run `python manage.py migrate` to create the h5pp models.

6. Start the development server and visit http://127.0.0.1:8000/h5p/home/ to access to the main menu of h5pp. Go to libraries to install the officiel H5P Release from h5p.org.
7. Start the development server and visit http://127.0.0.1:8000/h5p/home/ to access to the main menu of h5pp. Go to libraries to install the officiel H5P Release from h5p.org.

7. Visit http://127.0.0.1:8000/h5p/create/ to create or upload new H5P contents.
8. Visit http://127.0.0.1:8000/h5p/create/ to create or upload new H5P contents.

## Beta version
This version of H5P is a beta. Many things have to be corrected, code need to be optimized and currently the project is being tested. So we can not ensure the stability of the project until the end of the beta phase.
Expand Down
Binary file modified dist/H5PP-0.1.tar.gz
Binary file not shown.
55 changes: 54 additions & 1 deletion h5pp/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
from django.contrib import admin
from h5pp.models import *

# Register your models here.
class LibrariesAdmin(admin.ModelAdmin):
list_display = ('title', 'machine_name', 'library_id')
ordering = ('title', 'machine_name')

admin.site.register(h5p_libraries, LibrariesAdmin)

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

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')

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')

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')

admin.site.register(h5p_counters, CountersAdmin)
10 changes: 6 additions & 4 deletions h5pp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@


def handleUploadedFile(files, filename):
if not os.path.exists(settings.MEDIA_ROOT + '/tmp'):
os.mkdir(settings.MEDIA_ROOT + '/tmp')
if not os.path.exists(settings.MEDIA_ROOT + '/h5pp/tmp'):
os.makedirs(settings.MEDIA_ROOT + '/h5pp/tmp')

with open(settings.MEDIA_ROOT + '/tmp/' + filename, 'wb+') as destination:
with open(settings.MEDIA_ROOT + '/h5pp/tmp/' + filename, 'wb+') as destination:
for chunk in files.chunks():
destination.write(chunk)

return {'folderPath': settings.MEDIA_ROOT + '/tmp', 'path': settings.MEDIA_ROOT + '/tmp/' + filename}
return {'folderPath': settings.MEDIA_ROOT + '/h5pp/tmp', 'path': settings.MEDIA_ROOT + '/h5pp/tmp/' + filename}

##
# Form for upload/update h5p libraries
Expand Down Expand Up @@ -144,6 +144,8 @@ def clean(self):
raise forms.ValidationError(
'Impossible to create the content')

return content['id']

return self.cleaned_data

def getJsonContent(self):
Expand Down
10 changes: 5 additions & 5 deletions h5pp/h5p/editor/h5peditorclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def getLibraryData(self, machineName, majorVersion, minorVersion, langageCode, p
self.h5p.aggregateAssets = aggregateAssets

# Create base URL
url = settings.BASE_URL + '/media' + prefix
url = settings.BASE_URL + '/media/h5pp' + prefix

# JavaScripts
if 'scripts' in files:
Expand Down Expand Up @@ -242,7 +242,9 @@ def processField(self, field, params, files):
elif field['type'] == 'group':
if params:
if len(field['fields']) == 1:
params = field['fields'][0]['name']['params']
params = {
field['fields'][0]['name']: params
}
self.processSemantics(files, field['fields'], params)
return
elif field['type'] == 'list':
Expand All @@ -267,9 +269,7 @@ def processFile(self, params, files):
else:
oldPath = self.basePath + editorPath + params['path']
newPath = self.basePath + self.contentDirectory + params['path']
if os.path.exists(newPath):
self.storage.keepFile(newPath, newPath)
elif os.path.exists(oldPath):
if not os.path.exists(newPath) and os.path.exists(oldPath):
shutil.copy(oldPath, newPath)

files.append(params['path'])
Expand Down
10 changes: 5 additions & 5 deletions h5pp/h5p/editor/h5peditormodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# Django module h5p editor
##
from django.conf import settings
from h5pp.models import h5p_content_user_data, h5p_libraries
from h5pp.models import h5p_content_user_data, h5p_libraries, h5p_points
from h5pp.h5p.h5pmodule import h5pAddCoreAssets, h5pAddFilesAndSettings
from h5pp.h5p.h5pclasses import H5PDjango
import shutil
import time
import json
import os
Expand Down Expand Up @@ -70,7 +71,7 @@ def h5peditorContent(request):

contentValidator = framework.h5pGetInstance('contentvalidator')
editor['editor'] = {
'filesPath': settings.MEDIA_URL + 'editor',
'filesPath': settings.MEDIA_URL + 'h5pp/editor',
'fileIcon': {
'path': settings.BASE_URL + settings.STATIC_URL + 'h5p/h5peditor/images/binary-file.png',
'width': 50,
Expand All @@ -80,7 +81,7 @@ def h5peditorContent(request):
'libraryPath': settings.BASE_URL + settings.STATIC_URL + 'h5p/h5peditor/',
'copyrightSemantics': contentValidator.getCopyrightSemantics(),
'assets': assets,
'contentRelUrl': '../media/content/'
'contentRelUrl': '../media/h5pp/content/'
}

return {'editor': json.dumps(editor), 'coreAssets': coreAssets, 'assets': assets, 'add': add}
Expand Down Expand Up @@ -198,7 +199,7 @@ def createContent(request, content, params):
return False

editor.processParameters(contentId, content['library'], params)
core = framework.h5pGetInstance('core')

return True


Expand All @@ -221,7 +222,6 @@ def getLibraryProperty(library, prop='all'):
else:
return False


def ajaxSuccess(data=None):
response = {
'success': True
Expand Down
10 changes: 7 additions & 3 deletions h5pp/h5p/editor/library/h5peditorfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.conf import settings
import Image
import json
import uuid
import os
Expand All @@ -22,6 +24,7 @@ def __init__(self, request, files, framework):
self.result = dict()
self.field = json.loads(field)
self.files = files['file']
self.path = settings.MEDIA_ROOT + '/h5pp/tmp/' + self.files.name

# Check if uploaded base64 encoded file
if 'dataURI' in request.POST and request.POST['dataURI'] != '':
Expand Down Expand Up @@ -99,15 +102,16 @@ def validate(self):
if 'data' in locals() or 'data' in globals():
image = Image.open(self.data)
else:
with open(self.path, 'w+') as f:
f.write(self.files.read())
# Image size from tmp file
image = Image.open(files.name)
image = Image.open(self.path)

if not image:
print('File is not an image')
return False

self.result['width'] = image[0]
self.result['height'] = image[1]
self.result['width'], self.result['height'] = image.size
self.result['mime'] = self.typ

elif self.field['type'] == 'audio':
Expand Down
2 changes: 1 addition & 1 deletion h5pp/h5p/editor/library/h5peditorstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def getLanguage(self, machineName, majorVersion, minorVersion, language):
""" % ("'" + machineName + "'", majorVersion, minorVersion, "'" + language + "'"))

result = self.dictfetchall(cursor)
return result if len(result) > 0 else False
return result[0]['language_json'] if len(result) > 0 else False

##
# Returns all rows from a cursor as a dict
Expand Down
10 changes: 8 additions & 2 deletions h5pp/h5p/h5pclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def h5pGetInstance(self, typ, h5pdir=None, h5p=None):
self.interface.getUploadedH5pPath(h5p)

if not hasattr(self, 'core'):
self.core = H5PCore(self.interface, settings.MEDIA_ROOT, settings.BASE_DIR,
self.core = H5PCore(self.interface, settings.MEDIA_ROOT + '/h5pp', settings.BASE_DIR,
'en', True if getattr(settings, 'H5P_EXPORT') else False, False)

if typ == 'validator':
Expand All @@ -57,7 +57,7 @@ def h5pGetInstance(self, typ, h5pdir=None, h5p=None):
return self.core
elif typ == 'editor':
storage = H5PEditorStorage()
return H5PDjangoEditor(self.core, storage, settings.BASE_DIR, settings.MEDIA_URL)
return H5PDjangoEditor(self.core, storage, settings.BASE_DIR, settings.MEDIA_URL + 'h5pp/')

##
# Returns info for the current platform
Expand Down Expand Up @@ -651,6 +651,12 @@ def updateContentFields(self, pid, fields):
}
h5p_contents.objects.filter(content_id=pid).update(**query)

##
# Not implemented yet
##
def afterExportCreated(self):
return 0

##
# Will clear filtered params for all the content that uses the specified
# library. This means that the content dependencies will have to be rebuilt,
Expand Down
Loading

0 comments on commit 584b121

Please sign in to comment.