def new_instance_submit(self, id) : """ action used by new_instance to actually create a new instance of some object """ type_uri = request.params['type_uri'] query = 'INSERT {\n' qexists = 'SELECT ?foo WHERE {\n' newuri = self.urigen() for property in schema.types_properties(type_uri, ':property_type ?type', optional = False) : #print 'property',property if property['type'] == n.bk.string : query += '<%s> <%s> "%s" . \n' % (newuri, property['prop'], request.params[str(property['prop'])]) qexists += '?foo <%s> "%s" . \n' % (property['prop'], request.params[str(property['prop'])]) elif property['prop'] == n.bk.typeof : query += '<%s> <%s> <%s> . \n' % (newuri, n.bk.typeof, type_uri) qexists += '?foo <%s> <%s> . \n' % (n.bk.typeof, type_uri) elif schema.is_type_of(property['type'], n.bk['type']) : query += '<%s> <%s> <%s> . \n' % (newuri, property['prop'], request.params[str(property['prop'])]) qexists += '?foo <%s> <%s> . \n' % (n.bk.typeof, type_uri) qexists += '} LIMIT 1' query += '}' existing_uri = g.sparql.doQueryString(qexists) print 'finished asking ...' if existing_uri : #print 'redirect_to:',str('/view/uri/' + quote(existing_uri[7:])) redirect_to(str('/view/uri/' + quote(existing_uri[7:]))) else : print 'query:',query g.sparql.doQuery(query, include_prefix = False) print 'redirect_to:',str('/view/uri/' + quote(newuri[7:])) redirect_to(str('/view/uri/' + quote(newuri[7:])))
def new_instance(self, id): """ given the name of a type, show a form to allow an instance of that type to be created """ print '------------------------' print 'begin /view/new_instance' type_name = id type_uri = schema.name_to_uri(id) c.body = '<form action="/action/new_instance_submit">' c.body += '<input type="hidden" name="type_uri" value="%s" />' % type_uri c.body += '<table>' c.body += '<tr><th>property</th><th>value</th></tr>' for property in schema.types_properties(type_uri, ":property_type ?type", optional=False): c.body += '<tr><td>' if property['type'] == n.bk.string: c.body += '%s (string)</td><td><input type="text" name="%s" />' % ( property['name'], property['prop']) elif property['type'] == n.bk.integer: # TODO: restrict this to integers c.body += '%s (integer)</td><td><input type="text" name="%s" />' % ( property['name'], property['prop']) elif property['type'] == URIRef( 'http://theburningkumquat.com/item/1239775078491'): c.body += '%s (text)</td><td><textarea name="%s"></textarea>' % ( property['name'], property['prop']) elif property['name'] == 'typeof': pass #elif property['type'] == n.bk['type'] : ## don't display this one because, it is most likely not necessary. Will ## be necessary when mulitple values can be added of the same type. This ## makes for a more complex GUI though. #pass elif schema.is_type_of(property['type'], n.bk['type']): instances = schema.instances_of(property['type'], ':name ?name') c.body += '%s</td><td><select name="%s">' % (property['name'], property['prop']) # TODO: change this to an autocomplete rather than a dropdown for instance in instances: c.body += '<option value="%s">%s' % (instance['uri'], instance['name']) c.body += '</select>' else: c.body += '%s (unkown property_type: %s)</td><td><input type="text" name="%s" />' % ( property['name'], property['type'], property['prop']) c.body += '</tr>' c.body += '</table>' c.body += '<input type="submit" /><br>' c.body += '</form>' c.title = 'Create a new <a href="/view/name/%s">%s</a>' % (type_name, type_name) return render('/index.mako')
def new_instance(self, id) : """ given the name of a type, show a form to allow an instance of that type to be created """ print '------------------------' print 'begin /view/new_instance' type_name = id type_uri = schema.name_to_uri(id) c.body = '<form action="/action/new_instance_submit">' c.body += '<input type="hidden" name="type_uri" value="%s" />' % type_uri c.body += '<table>' c.body += '<tr><th>property</th><th>value</th></tr>' for property in schema.types_properties(type_uri, ":property_type ?type", optional = False) : c.body += '<tr><td>' if property['type'] == n.bk.string : c.body += '%s (string)</td><td><input type="text" name="%s" />' % (property['name'], property['prop']) elif property['type'] == n.bk.integer : # TODO: restrict this to integers c.body += '%s (integer)</td><td><input type="text" name="%s" />' % (property['name'], property['prop']) elif property['type'] == URIRef('http://theburningkumquat.com/item/1239775078491') : c.body += '%s (text)</td><td><textarea name="%s"></textarea>' % (property['name'], property['prop']) elif property['name'] == 'typeof' : pass #elif property['type'] == n.bk['type'] : ## don't display this one because, it is most likely not necessary. Will ## be necessary when mulitple values can be added of the same type. This ## makes for a more complex GUI though. #pass elif schema.is_type_of(property['type'], n.bk['type']) : instances = schema.instances_of(property['type'], ':name ?name') c.body += '%s</td><td><select name="%s">' % (property['name'], property['prop']) # TODO: change this to an autocomplete rather than a dropdown for instance in instances : c.body += '<option value="%s">%s' % (instance['uri'], instance['name']) c.body += '</select>' else : c.body += '%s (unkown property_type: %s)</td><td><input type="text" name="%s" />' % (property['name'], property['type'], property['prop']) c.body += '</tr>' c.body += '</table>' c.body += '<input type="submit" /><br>' c.body += '</form>' c.title = 'Create a new <a href="/view/name/%s">%s</a>' % (type_name, type_name) return render('/index.mako')
def new_instance_submit(self, id): """ action used by new_instance to actually create a new instance of some object """ type_uri = request.params['type_uri'] query = 'INSERT {\n' qexists = 'SELECT ?foo WHERE {\n' newuri = self.urigen() for property in schema.types_properties(type_uri, ':property_type ?type', optional=False): #print 'property',property if property['type'] == n.bk.string: query += '<%s> <%s> "%s" . \n' % (newuri, property['prop'], request.params[str( property['prop'])]) qexists += '?foo <%s> "%s" . \n' % ( property['prop'], request.params[str(property['prop'])]) elif property['prop'] == n.bk.typeof: query += '<%s> <%s> <%s> . \n' % (newuri, n.bk.typeof, type_uri) qexists += '?foo <%s> <%s> . \n' % (n.bk.typeof, type_uri) elif schema.is_type_of(property['type'], n.bk['type']): query += '<%s> <%s> <%s> . \n' % (newuri, property['prop'], request.params[str( property['prop'])]) qexists += '?foo <%s> <%s> . \n' % (n.bk.typeof, type_uri) qexists += '} LIMIT 1' query += '}' existing_uri = g.sparql.doQueryString(qexists) print 'finished asking ...' if existing_uri: #print 'redirect_to:',str('/view/uri/' + quote(existing_uri[7:])) redirect_to(str('/view/uri/' + quote(existing_uri[7:]))) else: print 'query:', query g.sparql.doQuery(query, include_prefix=False) print 'redirect_to:', str('/view/uri/' + quote(newuri[7:])) redirect_to(str('/view/uri/' + quote(newuri[7:])))