Beispiel #1
0
def slideshow(request):
    """
    Continuous classification with real view of thread
    """
    categories = dict((c.pk, c) for c in Category.objects.all())
    
    cursor = request.GET.get('c') or CategoryChoice.objects.filter(user=request.user).aggregate(m=Max('thread'))['m'] or 0

    if request.POST.get('o') == 'train':
        thread = get_object_or_404(Thread, pk=request.POST.get('t'))
        cat_choices = [int(c) for c in request.POST.getlist('b') if int(c) in categories]
        if cat_choices:
            CategoryChoice.objects.filter(user=request.user).delete()
            for category in cat_choices:
                CategoryChoice.objects.create(user=request.user, category=categories[category], thread=thread)
        cursor = thread.pk
        return HttpResponseRedirect('/?c=%s' % cursor)
    
    try:
        thread = Thread.objects.filter(pk__gt=cursor).order_by('pk')[0]
    except IndexError:
        return render_to_response('trainer/out_of_threads.html', {}, request)

    cursor = thread.pk

    return render_to_response('trainer/slideshow.html', {
        'thread': thread,
        'categories_json': mark_safe(simplejson.dumps(dict((c.pk, c.name) for c in categories.itervalues()))),
        'cursor': cursor,
    }, request)
Beispiel #2
0
def login(request):
    """
    Shows a login form.
    """

    return render_to_response('auth/login.html', {
        'callback_url': request.build_absolute_uri(reverse('rpx')),
    })