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))
def confirm_object_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 = ObjectExplorationWrapper.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
def reject_object_implication(request): group, bridge = group_and_bridge(request) is_member = group.user_is_member(request.user) print request.POST if not is_member: return HttpResponseForbidden("You must be a project member to do this") if request.method == 'POST': try: print attribute_name = request.POST['example_name'] if len(attribute_name) == 0: raise Exception("Attribute's name can't be empty") request.POST['imp_pk'] imp_pk = int(request.POST['imp_pk']) extent = set() for key in request.POST: if key != 'example_name' and key != 'imp_pk': extent.add(int(key)) premise = ObjectExplorationWrapper.get_premise(group, int(imp_pk)) ObjectExplorationWrapper.reject_implication_with_counterexample( group, imp_pk, attribute_name, premise | extent) 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": attribute_name, }) return HttpResponse(simplejson.dumps({'status': status}, ensure_ascii=False), mimetype='application/json') else: raise Http404
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))
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))
def unconfirm_object_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 = ObjectImplication.objects.get( pk=pk).get_as_fca_implication() ObjectExplorationWrapper.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
def get_object_conclusion(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: objects_ids = ObjectExplorationWrapper.get_conclusion( group, int(imp_pk)) except: return HttpResponse("reload") return HttpResponse(simplejson.dumps(list(objects_ids), ensure_ascii=False), mimetype='application/json') else: raise Http404