def remove_discipline(self): """ Remove the discipline triples from triple store. """ discipline = self.get_object() query = """ PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/elements/1.1/> DELETE { <%s> rdfs:subClassOf pp:Discipline ; pp:belongsTo pp:Software_Engineering ; pp:hasType pp:%s ; pp:isInTheFlowOf pp:%s ; pp:isPartOf pp:%s ; dc:title "%s" ; pp:code "%s" ; dc:description "%s" } WHERE {} """ % (discipline.uri, create_uri( discipline.classification), create_uri( discipline.semester), create_uri(discipline.core_content), discipline.title, discipline.code, discipline.description) response = Query.update(query) return response
def action(self, request, *args, **kwargs): """ Remove the triple from triple store. """ discipline = self.get_object() required = self.get_required() query = """ PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/> DELETE { <%s> pp:hasRequired <%s> . <%s> pp:isRequiredOf <%s> } WHERE {} """ % (discipline.uri, required.uri, required.uri, discipline.uri) response = Query.update(query) if response == 204: messages.success(self.request, "Required discipline removed successfully") else: messages.success(self.request, "There was a server error") return super(RemoveRequiredDisciplineView, self).action(request, *args, **kwargs)
def remove_subtopics(self): """ Remove all subtopics from discipline. """ discipline = self.get_object() subtopics = Disciplines.get_contents(discipline.uri) if subtopics: for subtopic in subtopics: query = """ PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/> DELETE {<%s> pp:hasContent <%s>} WHERE {} """ % (discipline.uri, subtopic.uri) Query.update(query)
def remove_requireds(self): """ Remove all requireds discipline from discipline. """ discipline = self.get_object() requireds = Disciplines.get_requireds(discipline.uri) if requireds: for required in requireds: query = """ PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/> DELETE { <%s> pp:hasRequired <%s> . <%s> pp:isRequiredOf <%s> } WHERE {} """ % (discipline.uri, required.uri, required.uri, discipline.uri) Query.update(query)
def form_valid(self, form): """ Receive the form already validated to create a discipline. """ title = form.cleaned_data['title'] uri = create_uri(title) code = form.cleaned_data['code'] description = form.cleaned_data['description'] classification = create_uri(form.cleaned_data['classification']) flow = create_uri(form.cleaned_data['flow']) core = create_uri(form.cleaned_data['core']) query = """ PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/elements/1.1/> INSERT { pp:%s rdfs:subClassOf pp:Discipline ; pp:belongsTo pp:Software_Engineering ; pp:hasType pp:%s ; pp:isInTheFlowOf pp:%s ; pp:isPartOf pp:%s ; dc:title "%s" ; pp:code "%s" ; dc:description "%s" } WHERE {} """ % (uri, classification, flow, core, title, code, description) if self.discipline_exists(title): messages.success(self.request, "This discipline already exists") else: response = Query.update(query) if response == 204: messages.success(self.request, "Discipline created successfully") else: messages.success(self.request, "There was a server error") return super(DisciplineCreateView, self).form_valid(form)
def action(self, request, *args, **kwargs): """ Insert content into discipline. """ discipline = self.get_object() subtopic = self.get_subtopic() query = """ PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/> INSERT {<%s> pp:hasContent <%s>} WHERE {} """ % (discipline.uri, subtopic.uri) response = Query.update(query) if response == 204: messages.success(self.request, "Subtopic inserted successfully") else: messages.success(self.request, "There was a server error") return super(InsertContentView, self).action(request, *args, **kwargs)
def action(self, request, *args, **kwargs): """ Remove the discipline triples from triple store. """ discipline = self.get_object() self.remove_subtopics() self.remove_requireds() query = """ PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/elements/1.1/> DELETE { <%s> rdfs:subClassOf pp:Discipline ; pp:belongsTo pp:Software_Engineering ; pp:hasType pp:%s ; pp:isInTheFlowOf pp:%s ; pp:isPartOf pp:%s ; dc:title "%s" ; pp:code "%s" ; dc:description "%s" } WHERE {} """ % (discipline.uri, create_uri( discipline.classification), create_uri( discipline.semester), create_uri(discipline.core_content), discipline.title, discipline.code, discipline.description) response = Query.update(query) if response == 204: messages.success(self.request, "Discipline removed successfully") else: messages.success(self.request, "There was a server error") return super(DisciplineRemoveView, self).action(request, *args, **kwargs)