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 _parse_prim(self, prim): if prim[0] == 's': # need the [1:] at the end to get rid of the leading u added by repr return repr(unicode(prim[1:]))[1:] elif prim[0] == 'n': return str(float(prim[1:])) elif prim[0] == 'i': return str(int(prim[1:])) elif prim[0] == 'u': return '<%s>' % re_uri.sub('', prim[1:]) elif prim[0] == 'a': name = schema.name_to_uri(prim[1:]) if name: return '<%s>' % name else: return None else: return None
def _parse_prim(self, prim) : if prim[0] == 's' : # need the [1:] at the end to get rid of the leading u added by repr return repr(unicode(prim[1:]))[1:] elif prim[0] == 'n' : return str(float(prim[1:])) elif prim[0] == 'i' : return str(int(prim[1:])) elif prim[0] == 'u' : return '<%s>' % re_uri.sub('', prim[1:]) elif prim[0] == 'a' : name = schema.name_to_uri(prim[1:]) if name : return '<%s>' % name else : return None else : return None