Ejemplo n.º 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))
Ejemplo n.º 2
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))
Ejemplo n.º 3
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))
Ejemplo n.º 4
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))
Ejemplo n.º 5
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))