Пример #1
0
def update_topic_name(request, course):
    nodeid = request.POST['nodeid']
    name = request.POST['name' + nodeid]
    topic = Topics.objects.get(pk=nodeid)
    verb = 'Topic, "' + topic.name + '" was renamed to "' + name + '"'
    topic.name = name
    topic.save()
    notify_edit_course(request.user, course, verb)
Пример #2
0
def create_topics(request, pk):
    course = Course.objects.get(pk=pk)
    name = request.POST['name']
    parentid = request.POST['parent']
    if parentid == '':
        parent = None
    else:
        parent = Topics.objects.get(pk=parentid)
    topic = Topics.objects.create(name=name, parent=parent, course=course)
    verb = 'Topic, "' + name + '" was added'
    notify_edit_course(request.user, course, verb)
    return topic
Пример #3
0
def manage_resource(request, pk):
    if request.user.is_authenticated:
        course = Course.objects.get(pk=pk)
        if course.state == States.objects.get(
                name='draft') and course.created_by != request.user:
            return redirect('home')
        if request.method == 'POST':
            topicid = request.POST['topic']
            topic = Topics.objects.get(pk=topicid)
            topic_type = request.POST['topic_type']
            if topic_type == 'Youtube' or topic_type == 'External':
                topic_link = request.POST['topic_link']
                topic_description = request.POST['topic_description']
                link = Links.objects.create(link=topic_link,
                                            desc=topic_description,
                                            topics=topic,
                                            types=topic_type)
                verb = topic_type + ' link was added to "' + topic.name + '"'
            elif topic_type == 'PublishedArticle':
                article_id = request.POST['article_id']
                article = Articles.objects.get(pk=article_id)
                topicarticle = TopicArticle.objects.create(topics=topic,
                                                           article=article)
                verb = 'Published article was added to "' + topic.name + '"'
            notify_edit_course(request.user, course, verb)
            return redirect('course_view', pk=pk)
        else:
            try:
                course = CommunityCourses.objects.get(course=pk)
                topics = Topics.objects.filter(course=pk)
                articles = Articles.objects.filter(state__name='publish')
            except CommunityCourses.DoesNotExist:
                raise Http404
            membership = CommunityMembership.objects.get(
                user=request.user.id, community=course.community)
            message = canEditCourse(course.course.state.name,
                                    membership.role.name, course.course,
                                    request)
            if message != 'True':
                return render(request, 'error.html', {
                    'message': message,
                    'url': 'course_view',
                    'argument': pk
                })
            return render(request, 'manage_resource.html', {
                'course': course,
                'topics': topics,
                'articles': articles
            })
    else:
        return redirect('course_view', pk=pk)
Пример #4
0
def move_topic(request, course):
    parent = request.POST['parent']
    if parent == '':
        parent = None
    else:
        parent = Topics.objects.get(pk=parent)
    topic = request.POST['topic']
    topic = Topics.objects.get(pk=topic)
    if canMove(parent, topic):
        topic.parent = parent
        topic.save()
        verb = 'Topic, "' + str(topic.name) + '" was moved under "' + str(
            topic.parent) + '"'
        notify_edit_course(request.user, course, verb)
        return True
    else:
        return False
Пример #5
0
def update_course_info(request, pk):
    if request.user.is_authenticated:
        course = Course.objects.get(pk=pk)
        if course.state == States.objects.get(
                name='draft') and course.created_by != request.user:
            return redirect('home')
        community = CommunityCourses.objects.get(course=pk)
        uid = request.user.id
        membership = None
        comm = Community.objects.get(pk=community.community.id)
        errormessage = ''
        try:
            membership = CommunityMembership.objects.get(user=uid,
                                                         community=comm.id)
            if membership:
                if request.method == 'POST':
                    title = request.POST['name']
                    body = request.POST['desc']
                    getstate = request.POST['change_course_state']
                    state = States.objects.get(name=getstate)
                    course.title = title
                    course.body = body
                    course.state = state
                    try:
                        image = request.FILES['course_image']
                        course.image = image
                    except:
                        errormessage = 'image not uploaded'
                    course.save()
                    notify_edit_course(request.user, course,
                                       'Course information was updated')
                    if getstate == 'visible':
                        create_resource_feed(course, 'course_edit',
                                             request.user)
                    elif getstate == 'publishable':
                        create_resource_feed(course, 'course_no_edit',
                                             request.user)
                        notify_update_course_state(request.user, course,
                                                   'publishable')
                    elif getstate == 'publish':
                        create_resource_feed(course, 'course_published',
                                             request.user)
                        notify_update_course_state(request.user, course,
                                                   'publish')
                    return redirect('course_view', pk=pk)
                else:
                    message = canEditCourse(course.state.name,
                                            membership.role.name, course,
                                            request)
                    if message != 'True':
                        return render(
                            request, 'error.html', {
                                'message': message,
                                'url': 'course_view',
                                'argument': pk
                            })
                    return render(
                        request, 'update_course_info.html', {
                            'course': course,
                            'membership': membership,
                            'community': community,
                            'comm': comm
                        })
            else:
                return redirect('course_view', pk=pk)
        except CommunityMembership.DoesNotExist:
            return redirect('login')
    else:
        return redirect('login')
Пример #6
0
def delete_topic(request, course):
    deletenodeid = request.POST['deletenodeid']
    topic = Topics.objects.get(pk=deletenodeid)
    verb = 'Topic, "' + topic.name + '" and its sub-topics if any, were deleted'
    topic.delete()
    notify_edit_course(request.user, course, verb)