Esempio n. 1
0
def createView(request, contentId=None):
    if request.user.is_authenticated:
        editor = h5peditorContent(request, contentId)
        if request.method == 'POST':
            if contentId != None:
                request.POST['contentId'] = contentId
            form = CreateForm(request, request.POST, request.FILES)
            if form.is_valid():
                if contentId != None:
                    return HttpResponseRedirect('/h5p/content/?contentId=' + contentId)
                else:
                    newId = h5p_contents.objects.all(
                    ).order_by('-content_id')[0]
                    return HttpResponseRedirect('/h5p/content/?contentId=' + str(newId.content_id))
            return render(request, 'h5p/create.html', {'form': form, 'data': editor})

        elif contentId != None:
            framework = H5PDjango(request.user)
            edit = framework.loadContent(contentId)
            request.GET = request.GET.copy()
            request.GET['contentId'] = contentId
            request.GET['json_content'] = edit['params']
            request.GET['h5p_library'] = edit['library_name'] + ' ' + \
                str(edit['library_major_version']) + '.' + \
                str(edit['library_minor_version'])

        form = CreateForm(request)

        return render(request, 'h5p/create.html', {'form': form, 'data': editor})

    return HttpResponseRedirect('/h5p/login/?next=/h5p/create/')
Esempio n. 2
0
    def get_context_data(self, **kwargs):
        """
        Get the editor for the template

        """
        ctx = super(CreateContentView, self).get_context_data(**kwargs)
        ctx["data"] = h5peditorContent(self.request)

        return ctx
Esempio n. 3
0
def createView(request, contentId=None):
    if request.user.is_authenticated():
        editor = h5peditorContent(request, contentId)
        if request.method == 'POST':
            if contentId != None:
                request.POST['contentId'] = contentId
                from django.db import connection
                cursor = connection.cursor()
                cursor.execute(
                    "select community_id from h5p_contents where content_id = %s",
                    [contentId])
                cid = cursor.fetchone()[0]
                cursor.execute(
                    "select group_id from h5p_contents where content_id = %s",
                    [contentId])
                gid = cursor.fetchone()[0]
                request.POST['community_id'] = cid
                request.POST['group_id'] = gid
            else:
                request.POST['community_id'] = request.session['cid']
                cid = request.POST['community_id']
                request.POST['group_id'] = request.session['gid']
                gid = request.session['gid']
                del request.session['cid']
                del request.session['gid']
            form = CreateForm(request, request.POST, request.FILES)
            if form.is_valid():
                if contentId != None:
                    if cid != 0:
                        return HttpResponseRedirect(settings.COLLAB_ROOT +
                                                    '/community_content/' +
                                                    str(cid))
                    else:
                        return HttpResponseRedirect(settings.COLLAB_ROOT +
                                                    '/group_content/' +
                                                    str(gid))
                else:
                    newId = h5p_contents.objects.all().order_by(
                        '-content_id')[0]
                    if cid != 0:
                        return HttpResponseRedirect(settings.COLLAB_ROOT +
                                                    '/community_content/' +
                                                    str(cid))
                    else:
                        return HttpResponseRedirect(settings.COLLAB_ROOT +
                                                    '/group_content/' +
                                                    str(gid))
            return render(request, 'h5p/create.html', {
                'form': form,
                'data': editor
            })

        elif contentId != None:
            framework = H5PDjango(request.user)
            edit = framework.loadContent(contentId)
            request.GET = request.GET.copy()
            request.GET['contentId'] = contentId
            request.GET['json_content'] = edit['params']
            request.GET['content_type'] = edit['content_type']
            request.GET['h5p_library'] = edit['library_name'] + ' ' + \
                str(edit['library_major_version']) + '.' + \
                str(edit['library_minor_version'])
            print('Thefnwfkwfnlknfwknlnkllnk')

        form = CreateForm(request)

        return render(request, 'h5p/create.html', {
            'form': form,
            'data': editor
        })

    return HttpResponseRedirect('/h5p/login/?next=/h5p/create/')