예제 #1
0
def import_context_view(request, template_name="exploration/import.html"):
    """docstring for import_context"""
    group, bridge = group_and_bridge(request)
    ctx = group_context(group, bridge)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            if request.user.is_authenticated():
                import_context(group, request.FILES['import_context'])
                transaction.commit()
                ExplorationWrapper.touch(group)
            else:
                # TODO: Show message
                pass
            return HttpResponseRedirect(
                bridge.reverse('knowledge_base_index', group))
    else:
        form = UploadFileForm()
    return render_to_response(template_name, {"form": form},
                              context_instance=RequestContext(request, ctx))
예제 #2
0
def submit_intent(request):
    """AJAX"""
    group, bridge = group_and_bridge(request)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    if request.method == 'POST':
        object_pk = int(request.POST['pk'])
        intent = [int(id_) for id_ in request.POST.getlist(u'intent[]')]
        try:
            ExplorationWrapper.edit_object(group, object_pk, set(intent))
            status = 'ok'
        except Exception as details:
            status = str(details)
        else:
            if notification:
                notification.send(
                    group.member_users.all(), "intent_changed", {
                        "user": request.user,
                        "object": FObject.objects.get(pk=object_pk),
                        "project": group,
                    })
        return HttpResponse(simplejson.dumps({'status': status},
                                             ensure_ascii=False),
                            mimetype='application/json')
    else:
        raise Http404
예제 #3
0
def attribute_new(request, template_name="exploration/attributes/new.html"):
    group, bridge = group_and_bridge(request)
    ctx = group_context(group, bridge)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    if request.method == 'POST':
        form = AttributeForm(request.POST)
        if form.is_valid():
            attribute = form.save(commit=False)
            if group:
                group.associate(attribute, commit=False)
            attribute.save()
            ExplorationWrapper.touch(group)
            ObjectExplorationWrapper.touch(group)
            if notification:
                notification.send(
                    group.member_users.all(), "context_new_attribute", {
                        "user": request.user,
                        "new_attribute": attribute,
                        "project": group,
                    })
        return HttpResponseRedirect(
            bridge.reverse('knowledge_base_index', group))
    else:
        form = AttributeForm()

    data_dictionary = {"project": group, "form": form}

    return render_to_response(template_name,
                              data_dictionary,
                              context_instance=RequestContext(request, ctx))
예제 #4
0
def confirm_implication(request):
    """AJAX"""
    group, bridge = group_and_bridge(request)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    if request.method == 'POST':
        pk = request.POST['pk']
        try:
            implication = ExplorationWrapper.confirm_implication(
                group, int(pk))
        except KeyError:
            # TODO: Relative basis was changed. Show message.
            pass
        else:
            if notification:
                notification.send(
                    group.member_users.all(), "attr_imp_conf", {
                        "user": request.user,
                        "implication": implication,
                        "project": group,
                    })
        return HttpResponseRedirect(bridge.reverse('implications', group))
    else:
        raise Http404
예제 #5
0
def attribute_edit(request,
                   id,
                   template_name="exploration/attributes/edit.html"):
    group, bridge = group_and_bridge(request)
    ctx = group_context(group, bridge)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    attr = get_object_or_404(FAttribute, pk=id)
    if request.method == 'POST':
        if 'delete' in request.POST:
            attr_name = attr.name
            # ExplorationWrapper.delete_attribute(attr.pk)
            attr.delete()
            ExplorationWrapper.touch(group)
            if notification:
                notification.send(
                    group.member_users.all(), "context_remove_attribute", {
                        "user": request.user,
                        "attribute_name": attr_name,
                        "project": group,
                    })
            return HttpResponseRedirect(
                bridge.reverse('edit_attributes', group))
        else:
            form = AttributeForm(request.POST, instance=attr)
            if form.is_valid():
                form.save()
                ExplorationWrapper.touch(group)
            return HttpResponseRedirect(
                bridge.reverse(
                    'edit_attributes',
                    group,
                ))
    else:
        form = AttributeForm(instance=attr)

    data_dictionary = {"attribute": attr, "project": group, "form": form}
    return render_to_response(template_name,
                              data_dictionary,
                              context_instance=RequestContext(request, ctx))
예제 #6
0
def object_new(request, template_name="exploration/objects/new.html"):
    group, bridge = group_and_bridge(request)
    ctx = group_context(group, bridge)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    if request.method == 'POST':
        form = ObjectForm(request.POST)
        if form.is_valid():
            object_ = form.save(commit=False)
            if group:
                group.associate(object_, commit=False)
            object_.save()
            ExplorationWrapper.touch(group)
            ObjectExplorationWrapper.touch(group)
            if notification:
                notification.send(
                    group.member_users.all(), "context_new_object", {
                        "user": request.user,
                        "new_object": object_,
                        "project": group,
                    })
            return HttpResponseRedirect(
                bridge.reverse('object_details', group, {"id": object_.id}))
        else:
            # TODO: Possibly validation error handling
            return HttpResponseRedirect(
                bridge.reverse('knowledge_base_index', group))
    else:
        form = ObjectForm()

    data_dictionary = {"project": group, "form": form}

    return render_to_response(template_name,
                              data_dictionary,
                              context_instance=RequestContext(request, ctx))
예제 #7
0
def implications(request, template_name="exploration/implications.html"):
    group, bridge = group_and_bridge(request)
    ctx = group_context(group, bridge)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    open_implications = list(ExplorationWrapper.get_open_implications(group))
    # open_implications = [open_implications_generator.next() for _ in xrange(10)]
    confirmed_implications = list(
        ExplorationWrapper.get_background_knowledge(group))
    attributes = group.content_objects(FAttribute)
    objects = group.content_objects(FObject)
    print open_implications

    open_object_implications = list(
        ObjectExplorationWrapper.get_open_implications(group))
    # open_implications = [open_implications_generator.next() for _ in xrange(10)]
    confirmed_object_implications = list(
        ObjectExplorationWrapper.get_background_knowledge(group))
    print open_object_implications
    #print confirmed_object_implications

    data_dictionary = {
        "project": group,
        "open_implications": open_implications,
        "confirmed_implications": confirmed_implications,
        'open_object_implications': open_object_implications,
        'confirmed_object_implications': confirmed_object_implications,
        "attributes": attributes,
        'objects': objects
    }

    return render_to_response(template_name,
                              data_dictionary,
                              context_instance=RequestContext(request, ctx))
예제 #8
0
def object_edit(request, id, template_name="exploration/objects/edit.html"):
    group, bridge = group_and_bridge(request)
    ctx = group_context(group, bridge)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    object_ = get_object_or_404(FObject, pk=id)
    if request.method == 'POST':
        if 'delete' in request.POST:
            object_name = object_.name
            #ExplorationWrapper.delete_object(group, object_.pk)
            object_.delete()
            ExplorationWrapper.touch(group)
            if notification:
                notification.send(
                    group.member_users.all(), "context_remove_object", {
                        "user": request.user,
                        "object_name": object_name,
                        "project": group,
                    })
            return HttpResponseRedirect(bridge.reverse('edit_kb', group))
        else:
            form = ObjectForm(request.POST, instance=object_)
            if form.is_valid():
                form.save()
                ExplorationWrapper.touch(group)
            return HttpResponseRedirect(
                bridge.reverse('object_details', group, {"id": object_.id}))
    else:
        form = ObjectForm(instance=object_)

    data_dictionary = {"object": object_, "project": group, "form": form}
    return render_to_response(template_name,
                              data_dictionary,
                              context_instance=RequestContext(request, ctx))
예제 #9
0
def unconfirm_implication(request):
    group, bridge = group_and_bridge(request)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    if request.method == 'POST':
        pk = request.POST['pk']
        implication = AttributeImplication.objects.get(
            pk=pk).get_as_fca_implication()
        ExplorationWrapper.unconfirm_implication(group, pk)
        if notification:
            notification.send(
                group.member_users.all(), "attr_imp_unconf", {
                    "user": request.user,
                    "implication": implication,
                    "project": group,
                })
        return HttpResponseRedirect(bridge.reverse('implications', group))
    else:
        raise Http404
예제 #10
0
def reject_implication(request):
    group, bridge = group_and_bridge(request)
    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    if request.method == 'POST':
        try:
            object_name = request.POST['example_name']
            if len(object_name) == 0:
                raise Exception("Object's name can't be empty")
            imp_pk = int(request.POST['imp_pk'])
            intent = set()
            for key in request.POST:
                if key != 'example_name' and key != 'imp_pk':
                    intent.add(int(key))
            premise = ExplorationWrapper.get_premise(group, int(imp_pk))
            ExplorationWrapper.reject_implication_with_counterexample(
                group, imp_pk, object_name, premise | intent)
            status = 'ok'
        except Exception as details:
            status = str(details)
        else:
            if notification:
                notification.send(
                    group.member_users.all(), "attr_imp_reject", {
                        "user": request.user,
                        "project": group,
                        "counterexample_name": object_name,
                    })
        return HttpResponse(simplejson.dumps({'status': status},
                                             ensure_ascii=False),
                            mimetype='application/json')
    else:
        raise Http404
예제 #11
0
def get_premise(request):
    """AJAX"""
    group, bridge = group_and_bridge(request)

    is_member = group.user_is_member(request.user)

    if not is_member:
        return HttpResponseForbidden("You must be a project member to do this")

    if request.method == 'POST':
        imp_pk = request.POST['imp_pk']
        try:
            attributes_ids = ExplorationWrapper.get_premise(group, int(imp_pk))
        except:
            return HttpResponse("reload")

        return HttpResponse(simplejson.dumps(list(attributes_ids),
                                             ensure_ascii=False),
                            mimetype='application/json')
    else:
        raise Http404
예제 #12
0
파일: misc.py 프로젝트: abramovd/sail
def clear_db(group):
    group.content_objects(FObject).delete()
    group.content_objects(FAttribute).delete()
    group.content_objects(AttributeImplication).delete()
    ExplorationWrapper.clear()
예제 #13
0
파일: misc.py 프로젝트: abramovd/explr-2
def clear_db(group):
    group.content_objects(FObject).delete()
    group.content_objects(FAttribute).delete()
    group.content_objects(AttributeImplication).delete()
    ExplorationWrapper.clear()