def topic_home(request, slug):
    current_topic = get_object_or_404(Topic, slug=slug)
    headline = """Learn """ + unicode(current_topic.name).capitalize() + """ - from the best tutorials and online courses"""
    topics = Topic.objects.filter(resource__title__isnull=False).distinct().order_by('name')

    ctx = {
        'current_topic': current_topic,
        'headline': headline,
        'topics': topics
    }

    resourcetypes = []
    res_types = ResourceType.objects.all().order_by('name')
    for res_type in res_types:
        try:
            result = FeaturedResource.objects.get(topic=current_topic, resource_type=res_type)
            resourcetypes.append((result.resource_type.slug, result.resource))
        except FeaturedResource.DoesNotExist:
            result = current_topic.resource_set.filter(resource_type=res_type).order_by('-rating_votes')
            if 0 > len(result):
                resourcetypes.append((result[0].resource_type.slug, result[0]))
    ctx['resourcetypes'] = SortedDict(resourcetypes)

    return render_to_response('resources/topic_home.html', ctx, context_instance=RequestContext(request))
dataset/ETHPy150Open codesters/codesters/resources/views.py/topic_home/swapped operands of `>`