Exemplo n.º 1
0
def add_from_frame(request, lang, frame, activity=None):
    '''Add a new assertion from a given frame.'''
    frame = get_object_or_404(Frame, id=frame)
    if request.method == 'POST':
        # User gave data. Add it.
        language = get_language(lang)
        lang = language.id
        assert frame.language == language
        text1 = request.POST['field_1']
        text2 = request.POST['field_2']
        rating = request.POST.get('rating', 1)

        if activity is None:
            activity = Activity.objects.get(id=MANUAL_ENTRY_ACTIVITY_ID)

        assertion = add_assertion(request, request.user, frame, text1, text2,
        activity, rating)

        # Clear recently learned.
        from django.core.cache import cache
        cache.delete('recently_learned_'+lang)
        cache.delete('recently_learned_'+lang+'_full')

        return HttpResponseRedirect(reverse('assertion',kwargs=dict(id=assertion.id,
                                                                   lang=lang)))
    else:
        return respond_with('commons/add_assertion.html', request, {'frame': frame})
Exemplo n.º 2
0
def add_from_frame(request):
    frame = Frame.objects.get(id=get_parameter(request.POST, 'frame_id', int))
    text1 = get_parameter(request.POST, 'text1')
    text2 = get_parameter(request.POST, 'text2')
    rating = rating_values[get_parameter(request.POST, 'rating')]

    if len(text1) == 0 or len(text2) == 0:
        raise InputError(_('One of the slots was not filled in.'))
    activity_name = get_parameter(request.POST, 'activity')

    user = request.user
    activity, created = Activity.objects.get_or_create(name=activity_name)
    assertion = add_assertion(request, request.user, frame, text1, text2,
    activity, rating)

    return {'text': _('Knowledge accepted.'), 'id': assertion.id}