Exemplo n.º 1
0
def import_project(project, hashtag):
    course = {}
    course['title'] = project.name
    course['hashtag'] = hashtag
    course['description'] = project.short_description
    course['language'] = project.language
    user_uri = "/uri/user/{0}".format(
        project.participations.filter(
            organizing=True).order_by('joined_on')[0].user.username)
    course['organizer_uri'] = user_uri

    course = course_model.create_course(**course)

    # update about page
    about = {
        "uri": course['about_uri'],
        "title": "About",
        "content": project.long_description,
        "author_uri": user_uri,
    }
    content_model.update_content(**about)

    # add other pages to course
    for page in project.pages.filter(deleted=False,
                                     listed=True).order_by('index'):
        content = {
            "title": page.title,
            "content": content_utils.clean_user_content(page.content),
            "author_uri": "/uri/user/{0}".format(page.author.username),
        }
        content = content_model.create_content(**content)
        course_model.add_course_content(course['uri'], content['uri'])

    return course
Exemplo n.º 2
0
def create_content( request, course_id ):
    course_uri = course_model.course_id2uri(course_id)
    course = _get_course_or_404(course_uri)
    if request.method == "POST":
        form = ContentForm(request.POST)
        if form.is_valid():
            user = request.user.get_profile()
            user_uri = u"/uri/user/{0}".format(user.username)
            content_data = {
                'title': form.cleaned_data.get('title'),
                'content': form.cleaned_data.get('content'),
                'author_uri': user_uri,
            }
            content = content_model.create_content(**content_data)
            course_model.add_course_content(course['uri'], content['uri'])

            redirect_url = request.POST.get('next_url', None)
            if not redirect_url:
                redirect_url = reverse('courses_show',
                    kwargs={'course_id': course['id'], 'slug': course['slug']}
                )
            return http.HttpResponseRedirect(redirect_url)
    else:
        form = ContentForm()

    context = { 'form': form }
    context = _populate_course_context(request, course_id, context)
    if request.GET.get('next_url', None):
        context['next_url'] = request.GET.get('next_url', None)

    return render_to_response('courses/create_content.html', 
        context, context_instance=RequestContext(request)
    )
Exemplo n.º 3
0
def create_course(title,
                  hashtag,
                  description,
                  language,
                  organizer_uri,
                  based_on_uri=None):
    course_db = db.Course(title=title,
                          short_title=hashtag,
                          description=description,
                          language=language,
                          creator_uri=organizer_uri)

    if based_on_uri:
        based_on = _get_course_db(based_on_uri)
        course_db.based_on = based_on

    course_db.save()

    about = content_model.create_content(**{
        "title": _("About"),
        "content": "",
        "author_uri": organizer_uri
    })
    add_course_content("/uri/course/{0}".format(course_db.id), about['uri'])
    create_course_cohort("/uri/course/{0}".format(course_db.id), organizer_uri)
    course = get_course("/uri/course/{0}".format(course_db.id))

    learn_api_data = get_course_learn_api_data(course['uri'])
    learn_model.add_course_listing(**learn_api_data)
    learn_model.add_course_to_list(learn_api_data['course_url'], "drafts")

    # TODO notify admins
    return course
Exemplo n.º 4
0
def create_content( request, course_id ):
    course_uri = course_model.course_id2uri(course_id)
    course = _get_course_or_404(course_uri)
    if request.method == "POST":
        form = ContentForm(request.POST)
        if form.is_valid():
            user = request.user.get_profile()
            user_uri = u"/uri/user/{0}".format(user.username)
            content_data = {
                'title': form.cleaned_data.get('title'),
                'content': form.cleaned_data.get('content'),
                'author_uri': user_uri,
            }
            content = content_model.create_content(**content_data)
            course_model.add_course_content(course['uri'], content['uri'])

            redirect_url = request.POST.get('next_url', None)
            if not redirect_url:
                redirect_url = reverse('courses_show',
                    kwargs={'course_id': course['id'], 'slug': course['slug']}
                )
            return http.HttpResponseRedirect(redirect_url)
    else:
        form = ContentForm()

    context = { 'form': form }
    context = _populate_course_context(request, course_id, context)
    if request.GET.get('next_url', None):
        context['next_url'] = request.GET.get('next_url', None)

    return render_to_response('courses/create_content.html', 
        context, context_instance=RequestContext(request)
    )
Exemplo n.º 5
0
def create_course(title, hashtag, description, language, organizer_uri, based_on_uri=None):
    course_db = db.Course(
        title=title,
        short_title=hashtag,
        description=description,
        language=language,
        creator_uri=organizer_uri
    )

    if based_on_uri:
        based_on = _get_course_db(based_on_uri)
        course_db.based_on = based_on

    course_db.save()

    about = content_model.create_content(
       **{"title": _("About"), "content": "", "author_uri": organizer_uri}
    )
    add_course_content("/uri/course/{0}".format(course_db.id), about['uri'])
    create_course_cohort("/uri/course/{0}".format(course_db.id), organizer_uri)
    course = get_course("/uri/course/{0}".format(course_db.id))

    learn_api_data = get_course_learn_api_data(course['uri'])
    learn_model.add_course_listing(**learn_api_data)
    learn_model.add_course_to_list(learn_api_data['course_url'], "drafts")

    # TODO notify admins
    return course
Exemplo n.º 6
0
def import_project(project, hashtag):
    course = {}
    course['title'] = project.name
    course['hashtag'] = hashtag
    course['description'] = project.short_description
    course['language'] = project.language
    user_uri = "/uri/user/{0}".format(project.participations.filter(organizing=True).order_by('joined_on')[0].user.username)
    course['organizer_uri'] = user_uri

    course = course_model.create_course(**course)

    # update about page
    about = {
        "uri": course['about_uri'],
        "title": "About",
        "content": project.long_description,
        "author_uri": user_uri,
    }
    content_model.update_content(**about)

    # add other pages to course
    for page in project.pages.filter(deleted=False, listed=True).order_by('index'):
        content = {
            "title": page.title,
            "content": content_utils.clean_user_content(page.content),
            "author_uri": "/uri/user/{0}".format(page.author.username),
        }
        content = content_model.create_content(**content)
        course_model.add_course_content(course['uri'], content['uri'])

    return course
Exemplo n.º 7
0
def add_content_from_response(course_uri, url, user_uri):
    content = None
    response = request_oembedded_content(url)
    if response.status_code == 200:
        content = response.json
        content_data = {
            'title': content['title'],
            'content': content['html'],
            'author_uri': user_uri,
        }
        content = content_model.create_content(**content_data)
        course_model.add_course_content(course_uri, content['uri'])
    else:
        raise BadgeNotFoundException
    return content
Exemplo n.º 8
0
 def test_clone_content(self):
     content = content_model.create_content('title', 'content', '/uri/users/bob')
     clone = content_model.clone_content(content['uri'])
     for key in ['title', 'content']:
         self.assertTrue(content[key], clone[key])
Exemplo n.º 9
0
 def test_content_history(self):
     content = content_model.create_content('title', 'content', '/uri/users/bob')
     content_model.update_content(
         content['uri'], 'New title', 'New content', '/uri/users/testuser'
     )
Exemplo n.º 10
0
 def test_content_creation(self):
     content = content_model.create_content('title', 'content', '/uri/users/bob')
     content2 = content_model.get_content(content['uri'])
     self.assertEquals(content, content2)
Exemplo n.º 11
0
 def test_clone_content(self):
     content = content_model.create_content('title', 'content',
                                            '/uri/users/bob')
     clone = content_model.clone_content(content['uri'])
     for key in ['title', 'content']:
         self.assertTrue(content[key], clone[key])
Exemplo n.º 12
0
 def test_content_history(self):
     content = content_model.create_content('title', 'content',
                                            '/uri/users/bob')
     content_model.update_content(content['uri'], 'New title',
                                  'New content', '/uri/users/testuser')
Exemplo n.º 13
0
 def test_content_creation(self):
     content = content_model.create_content('title', 'content',
                                            '/uri/users/bob')
     content2 = content_model.get_content(content['uri'])
     self.assertEquals(content, content2)