def topic_cloud(request):
	# Fail message if something goes "boo boo"
	fail_message = _('No topics found for subject. You will setting the guideline for this subject so take care and be responsible.')

	# Get the list of subjects or return error message
	subjects = [s.strip().lower() for s in request.GET.get('subjects','').split(',') if s.strip() != '']
	if not subjects:
		return HttpResponse(json.dumps({'success':False, 'message':fail_message}), mimetype='application/json')

	# Sizes for the cloud
	sizes = ['tiny','small','normal','large','huge']

	# Get topics for all subjects
	# First we create a set so that same topics in different subjects
	# will not affect the impact (which should be based on use by user)
	topics = [t.name for t in Topic.objects.filter(topiccombination__subject__combination__name__in=subjects).distinct()]

	# If user is authenticated add to the list all topics the user has used
	if request.user.is_authenticated():
		topics.extend([t.name for t in Topic.objects.filter(topiccombination__course__author=request.user) if t.name in topics])

	if not topics:
		return HttpResponse(json.dumps({'success':False, 'message':fail_message}), mimetype='application/json')

	cloud = cloudify(topics, sizes)
	return HttpResponse(json.dumps({'success':True, 'cloud':cloud}), mimetype='application/json')
Exemple #2
0
def search(request, tagstring=''):
    if request.method == 'GET':
        searchlist = []
        taglist = tagstring.split(' ')
        every_search = Search.objects.filter(tag__tag__in=taglist):
        for search in every_search:
            searchlist.extend([s for s in search.split(' ') if s != ''])

	return render('oer/search.html', {'tags':tagstring, searchcloud=cloudify(searchlist, ['tiny', 'small', 'normal', 'large', 'huge'])}, request)
	def render_template(self, request, form, previous_fields, step, context=None):
		if not context:
			context = {}

		ctx = context
		previous_values = []

		"""
		Determining the step status for the display of the side information.
		As the steps move up, so does the level of information
		"""
		if step == 0:
                    # Sizes for the cloud
                    sizes = ['tiny','small','normal','large','huge']

                    # Get all professions
		    profession_clouds = {}
		    for p in Profession.objects.all():
			    try:
				    profession_clouds[p.exam.title].append(p.title.lower())
			    except:
				    profession_clouds[p.exam.title] = [p.title.lower()]

		    if request.user.is_authenticated():
			    # If user is authenticated add to the list all professions within the same field as the profession she has used
			    fields = Field.objects.filter(subfield__profession__programme__author=request.user)
			    for p in Profession.objects.filter(field__field__in=fields):
				    try:
					    profession_clouds[p.exam.title].append(p.title.lower())
				    except:
					    profession_clouds[p.exam.title] = [p.title.lower()]
			    
			    # Create a profession cloud
			    ctx['exams'] = Exam.objects.all()
			    ctx['levels'] = [_('Level 1'), _('Level 2'), _('Level 3'), _('Level 4'), ]
			    ctx['fields'] = Field.objects.all()
			    ctx['profession_clouds'] = []
			    for exam in profession_clouds.keys():
				  ctx['profession_clouds'].append({'exam':exam, 'cloud':cloudify(profession_clouds[exam],sizes)})

		if step == 3:
			default_competence_values = {}
			default_competences = KeyCompetence.objects.filter(default=True)
			for competence in default_competences:
				 default_competence_values[competence.get_key_competence_display()] = competence.description
 
			ctx['key_competence_fields'] = []
			for (choice_value, choice_title) in KeyCompetence.KEY_COMPETENCE_CHOICES:
				ctx['key_competence_fields'].append({'label_tag':choice_title, 'choice':choice_value, 'name':slugicefy(choice_title), 'value':default_competence_values.get(choice_title,'')})

		if step == 5:
			# Needs a better filter when school approval is up and running
			ctx['courses'] = Course.objects.all()
			
		return super(ProgrammeWizard, self).render_template(request,form,previous_fields,step,ctx)
def search(request, tags=""):
    if request.method == "POST":
        searchstring = request.POST.get("search", "")
        searchqueries = [Q(title__icontains=s) for s in searchstring.split(" ")]
        q_query = searchqueries.pop()
        for searchquery in searchqueries:
            q_query |= searchquery

        taglist = [t.strip() for t in request.POST.get("tags", "").split(",")]
        results = ActivityConstruct.objects.filter(q_query & Q(tag_set__tag__in=taglist))
        return render("oer/search_results.html", {"search": searchstring, "tags": tags, "results": results}, request)

    else:
        searchlist = []
        taglist = [t.strip() for t in tags.split(",")]
        every_search = Search.objects.filter(tag__tag__in=taglist)

        # Create a search cloud
        for search in every_search:
            searchlist.extend([s for s in search.split(" ") if s != ""])

        sizes = ["tiny", "small", "normal", "large", "huge"]
        searchcloud = cloudify(searchlist, sizes)

        # Bottom feeders
        if request.user.is_authenticated():
            my_search = every_search.filter(searcher=request.user)[:5]
        else:
            my_search = []
        popular_search = every_search[:5]
        newest_content = ActivityEntry.objects.filter(activityobject__tag_set__tag__in=taglist).order_by("-time")[:5]
        print newest_content

        return render(
            "oer/search.html",
            {
                "tags": tags,
                "searchcloud": searchcloud,
                "personal": my_search,
                "popular": popular_search,
                "activity_entries": newest_content,
            },
            request,
        )
	def render_template(self, request, form, previous_fields, step, context=None):
		if not context:
			context = {}

		ctx = context
                    
		previous_values = []

		"""
		Variables for storing strings while the user hasn't entered any data.
		"""
		name_subjects = '----'
		name_level = '-'
		name_topics = '--'
		name_credits = '--'

		"""
		Determining the step status for the display of the side information.
		As the steps move up, so does the level of information
		"""
		if step == 0:
                    # Sizes for the clodue
                    sizes = ['tiny','small','normal','large','huge']
                    # Get all subjects
                    subjects = [s.name for s in Subject.objects.all()]
                    if request.user.is_authenticated():
                        # If user is authenticated add to the list all subjects she has used
			subjects.extend([s.name for s in Subject.objects.filter(subjectcombination__course__author=request.user)])
                    
                    # Create a subject cloud
                    ctx['subject_cloud'] = cloudify(subjects,sizes)

		if step > 0:
			subjects = SubjectCombination.objects.get(pk=int(request.POST['0-subjects']))
			previous_values.append({'label':u'Námsgreinar','value':markdown(subjects.subjects())})
			name_subjects = subjects.abbreviation

			topics = TopicCombination.objects.get(pk=int(request.POST['0-topics']))
			previous_values.append({'label':u'Viðfangsefni','value':markdown(topics.topics())})
			name_topics = topics.abbreviation

		if step > 1:
			descriptive_name = request.POST['1-descriptive_name']
			previous_values.insert(0, {'label':u'Lýsandi nafn', 'value':markdown(descriptive_name)})

			level = request.POST['1-level']
			previous_values.append({'label':u'Þrep','value':u'<p>%s. þrep</p>' % level})
			name_level = level

			prerequisites = request.POST['1-prerequisites']
			previous_values.append({'label':u'Forkröfur','value':markdown(prerequisites)})

			description = request.POST['1-description']
			previous_values.append({'label':u'Lýsing','value':markdown(description)})

		if step == 3:
			credits = request.POST['2-credits']
			previous_values.insert(4, {'label':u'Framhaldsskólaeiningar', 'value':markdown(u'%s framhaldsskólaeiningar' % credits)})
			name_credits = '%02d' % int(credits)

			knowledge_goals = [Goal.objects.get(pk=int(g.strip())) for g in request.POST.getlist('2-knowledge_goals')]
			previous_values.append({'label':u'Þekkingarviðmið', 'value':u'<ul>%s</ul>' % ' '.join(['<li>%s</li>' % x.goal for x in knowledge_goals])})
			skills_goals = [Goal.objects.get(pk=int(g.strip())) for g in request.POST.getlist('2-skills_goals')]
			previous_values.append({'label':u'Leikniviðmið', 'value':u'<ul>%s</ul>' % ' '.join(['<li>%s</li>' % x.goal for x in skills_goals])})
			competence_goals = [Goal.objects.get(pk=int(g.strip())) for g in request.POST.getlist('2-competence_goals')]
			previous_values.append({'label':u'Hæfniviðmið', 'value':u'<ul>%s</ul>' % ' '.join([u'<li>%s<ul><li><div><em>Námsmat</em></div>%s</li></ul></li>' % (x.goal, ' '.join([u'%s<br/>' % e.evaluation for e in x.evaluation_set.all()])) for x in competence_goals])})
                        ctx['author'] = request.user.get_profile()

		ctx['abbreviation'] = u'%s%s%s%s' % (name_subjects, name_level, name_topics, name_credits)
		ctx['previous_values'] = previous_values

		return super(CourseWizard, self).render_template(request,form,previous_fields,step,ctx)