Beispiel #1
0
	def types_properties_autocomplete(self) :
		"""
		given a list of types and a optionally substr to search for in properties,
		return possible type names each on their own line.
		TODO: don't show properties which are unique and already have a value.
		"""
		types_str = request.params['types']
		if 'q' in request.params :
			property_substr = request.params['q']
		else :
			property_substr = ''
		
		types = types_str.split(', ')
		
		properties = schema.types_properties(types, ':input_type ?input_type')
		
		def prop_str(prop) :
			if prop['input_type'] == n.bk.suggest :
				input_type = 'suggest'
			elif prop['input_type'] == n.bk.plain :
				input_type = 'plain'
			elif prop['input_type'] == URIRef('http://theburningkumquat.com/item/1240190068661') :
				input_type = 'textarea'
			elif prop['input_type'] == URIRef('http://theburningkumquat.com/item/1240715819851') :
				input_type = 'integer'
			return '%s|%s' % (prop['name'], input_type)
		
		return '\n'.join(set([prop_str(prop) for prop in properties if property_substr in prop['name']]))
Beispiel #2
0
	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:])))
Beispiel #3
0
    def types_properties_autocomplete(self):
        """
		given a list of types and a optionally substr to search for in properties,
		return possible type names each on their own line.
		TODO: don't show properties which are unique and already have a value.
		"""
        types_str = request.params['types']
        if 'q' in request.params:
            property_substr = request.params['q']
        else:
            property_substr = ''

        types = types_str.split(', ')

        properties = schema.types_properties(types, ':input_type ?input_type')

        def prop_str(prop):
            if prop['input_type'] == n.bk.suggest:
                input_type = 'suggest'
            elif prop['input_type'] == n.bk.plain:
                input_type = 'plain'
            elif prop['input_type'] == URIRef(
                    'http://theburningkumquat.com/item/1240190068661'):
                input_type = 'textarea'
            elif prop['input_type'] == URIRef(
                    'http://theburningkumquat.com/item/1240715819851'):
                input_type = 'integer'
            return '%s|%s' % (prop['name'], input_type)

        return '\n'.join(
            set([
                prop_str(prop) for prop in properties
                if property_substr in prop['name']
            ]))
Beispiel #4
0
    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')
Beispiel #5
0
	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')
Beispiel #6
0
    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:])))
Beispiel #7
0
	def _renderItem(self, subquery, object) :
		"""
		render a single item, called by both name and id, depending how the item
		is looked up
		"""
		
		if 'name' in object :
			title = object['name']
			name = object['name']
		else :
			title = object.values()[0]
			name = None
		
		# pull all triples with this item as the subject
		query = """
		PREFIX : <http://theburningkumquat.com/schema/>
		SELECT ?sub ?pred ?val WHERE {
		%s .
		?sub ?pred ?val .
		}""" % subquery
		rows = g.sparql.doQueryRows(query)
		
		if len(rows) == 0 :
			c.body = "Can't find " + title
			c.title = "Error:"
			return render('/index.mako')

		# extract a list of the predicated, types and valid properties
		preds = [str(row['pred']) for row in rows]
		types = [str(row['val']) for row in rows if row['pred'] == n.bk['typeof']]
		properties = schema.types_properties(types)
		
		body = ""
		post_body = ""
		if name :
			body += '<a href="/action/delete/%s">delete</a> ' % name
		
		# special case for items which are types
		if str(n.bk['type']) in types :
			if name :
				body += '<a href="/action/new_instance/%s">create new %s</a> ' % (name, name)
				body += '<a href="/view/instances/%s">show all instances</a> ' % name
				post_body = '<div class="module-title">instances of %s:</a></div>' % name
				post_body += render('/instances.mako', type_name = name)
		
		#body += triples
		body += '<div id="subject_name">%s</div>' % title
		body += """<a href="javascript:toggle_uri()">uri</a> """
		body += '<div id="uri">'
		body += rows[0]['sub']
		body += '</div>'
		body += '<br><br>'
		
		for row in rows :
			# if predicate is a description
			if row['pred'] == URIRef('http://theburningkumquat.com/item/1239866285061') :
				md = markdown.Markdown()
				body += '<div id="description">%s</div><a id="description-edit">edit</a><br><br>' % md.convert(row['val'])
				body += '<div id="description_raw" value="%s" />' % row['val']
				row['hidden'] = True
			elif row['pred'] == URIRef('http://theburningkumquat.com/item/1244598466111') :
				# TODO: make this really work.  since different div names from description its not the same
				md = markdown.Markdown()
				body += '<div id="note">%s</div><a id="note-edit">edit</a><br><br>' % md.convert(row['val'])
				body += '<div id="note_raw" value="%s" />' % row['val']
				row['hidden'] = True
			elif row['pred'] == n.bk.name :
				row['hidden'] = True
		
		if name and str(n.bk['property']) in types :
			query = """
				PREFIX : <http://theburningkumquat.com/schema/>
				SELECT ?name WHERE {
					?x ?prop ?y ;
					   :name ?name .
					?prop :name "%s"
				} LIMIT 10""" % name
			instances = g.sparql.doQueryList(query)
			body += '<br><br><div>some objects with this property:<ul>'
			for instance in instances :
				body += '<li>%s' % rh.viewnamelink(instance)
			body += '</ul></div>'
		
		# used to determine which properties are valid
		body += '<div id="types" value="%s" />' % ', '.join(types)
		
		body += """
		<script>
		$(document).ready(function () {
			$('#row_count').hide();
			$('#description').editable(function (value, settings) {
					$.post('/action/update_unique_value', {
						sub : 'u%s',
						pred : 'uhttp://theburningkumquat.com/item/1239866285061',
						obj : 's' + value,
					});
					return value;
				}, { 
					event      : 'edit',
					onblur     : 'ignore',
					type       : 'textarea',
					rows       : 50,
					cols       : 60,
					cancel     : 'Cancel',
					submit     : 'OK',
					indicator  : '<img src="/img/indicator.gif">',
					data       : function (value) { return $('#description_raw').attr('value'); },
			});
			$('#description-edit').bind('click', function() {
				$('#description').trigger('edit');
			});
			
			$('#title').editable(function (value, settings) {
					$.post('/action/update_unique_value', {
						sub : 'u%s',
						pred : 'uhttp://theburningkumquat.com/schema/name',
						obj : 's' + value,
					});
					return value;
				}, {
					event : 'edit',
					onblur : 'submit',
					indicator  : '<img src="/img/indicator.gif">',
			});
			$('#title-edit').bind('click', function() {
				$('#title').trigger('edit');
			});
		});
		</script>
		""" % (rows[0]['sub'], rows[0]['sub'])
		
		# setup the template info
		c.rows = rows
		c.body = body
		c.post_body = post_body
		c.title = title
		c.title_edit = '<a id="title-edit">edit</a>'
		c.jsincludes = ['dbops.js', 'jquery-autocomplete.js', 'jquery.jeditable.mini.js', 'page-view.js', 'sorttable.js']
		c.cssincludes = ['autocomplete.css']
		
		return render('/index.mako')
Beispiel #8
0
    def _renderItem(self, subquery, object):
        """
		render a single item, called by both name and id, depending how the item
		is looked up
		"""

        if 'name' in object:
            title = object['name']
            name = object['name']
        else:
            title = object.values()[0]
            name = None

        # pull all triples with this item as the subject
        query = """
		PREFIX : <http://theburningkumquat.com/schema/>
		SELECT ?sub ?pred ?val WHERE {
		%s .
		?sub ?pred ?val .
		}""" % subquery
        rows = g.sparql.doQueryRows(query)

        if len(rows) == 0:
            c.body = "Can't find " + title
            c.title = "Error:"
            return render('/index.mako')

        # extract a list of the predicated, types and valid properties
        preds = [str(row['pred']) for row in rows]
        types = [
            str(row['val']) for row in rows if row['pred'] == n.bk['typeof']
        ]
        properties = schema.types_properties(types)

        body = ""
        post_body = ""
        if name:
            body += '<a href="/action/delete/%s">delete</a> ' % name

        # special case for items which are types
        if str(n.bk['type']) in types:
            if name:
                body += '<a href="/action/new_instance/%s">create new %s</a> ' % (
                    name, name)
                body += '<a href="/view/instances/%s">show all instances</a> ' % name
                post_body = '<div class="module-title">instances of %s:</a></div>' % name
                post_body += render('/instances.mako', type_name=name)

        #body += triples
        body += '<div id="subject_name">%s</div>' % title
        body += """<a href="javascript:toggle_uri()">uri</a> """
        body += '<div id="uri">'
        body += rows[0]['sub']
        body += '</div>'
        body += '<br><br>'

        for row in rows:
            # if predicate is a description
            if row['pred'] == URIRef(
                    'http://theburningkumquat.com/item/1239866285061'):
                md = markdown.Markdown()
                body += '<div id="description">%s</div><a id="description-edit">edit</a><br><br>' % md.convert(
                    row['val'])
                body += '<div id="description_raw" value="%s" />' % row['val']
                row['hidden'] = True
            elif row['pred'] == URIRef(
                    'http://theburningkumquat.com/item/1244598466111'):
                # TODO: make this really work.  since different div names from description its not the same
                md = markdown.Markdown()
                body += '<div id="note">%s</div><a id="note-edit">edit</a><br><br>' % md.convert(
                    row['val'])
                body += '<div id="note_raw" value="%s" />' % row['val']
                row['hidden'] = True
            elif row['pred'] == n.bk.name:
                row['hidden'] = True

        if name and str(n.bk['property']) in types:
            query = """
				PREFIX : <http://theburningkumquat.com/schema/>
				SELECT ?name WHERE {
					?x ?prop ?y ;
					   :name ?name .
					?prop :name "%s"
				} LIMIT 10""" % name
            instances = g.sparql.doQueryList(query)
            body += '<br><br><div>some objects with this property:<ul>'
            for instance in instances:
                body += '<li>%s' % rh.viewnamelink(instance)
            body += '</ul></div>'

        # used to determine which properties are valid
        body += '<div id="types" value="%s" />' % ', '.join(types)

        body += """
		<script>
		$(document).ready(function () {
			$('#row_count').hide();
			$('#description').editable(function (value, settings) {
					$.post('/action/update_unique_value', {
						sub : 'u%s',
						pred : 'uhttp://theburningkumquat.com/item/1239866285061',
						obj : 's' + value,
					});
					return value;
				}, { 
					event      : 'edit',
					onblur     : 'ignore',
					type       : 'textarea',
					rows       : 50,
					cols       : 60,
					cancel     : 'Cancel',
					submit     : 'OK',
					indicator  : '<img src="/img/indicator.gif">',
					data       : function (value) { return $('#description_raw').attr('value'); },
			});
			$('#description-edit').bind('click', function() {
				$('#description').trigger('edit');
			});
			
			$('#title').editable(function (value, settings) {
					$.post('/action/update_unique_value', {
						sub : 'u%s',
						pred : 'uhttp://theburningkumquat.com/schema/name',
						obj : 's' + value,
					});
					return value;
				}, {
					event : 'edit',
					onblur : 'submit',
					indicator  : '<img src="/img/indicator.gif">',
			});
			$('#title-edit').bind('click', function() {
				$('#title').trigger('edit');
			});
		});
		</script>
		""" % (rows[0]['sub'], rows[0]['sub'])

        # setup the template info
        c.rows = rows
        c.body = body
        c.post_body = post_body
        c.title = title
        c.title_edit = '<a id="title-edit">edit</a>'
        c.jsincludes = [
            'dbops.js', 'jquery-autocomplete.js', 'jquery.jeditable.mini.js',
            'page-view.js', 'sorttable.js'
        ]
        c.cssincludes = ['autocomplete.css']

        return render('/index.mako')