Example #1
0
def view_task(request, uid, return_context=False):
    task = Task.get(uid)[0]

    # Replace newlines with <br>, etc.
    task["definition"] = clean_html(task["definition"])
    contrasts = Task.get_contrasts(task["id"])

    # Make a lookup dictionary based on concept id
    concept_lookup = dict()
    for contrast in contrasts:
        contrast_concepts = Contrast.get_concepts(contrast["contrast_id"])
        for concept in contrast_concepts:
            concept_lookup = update_lookup(concept_lookup,
                                           concept["concept_id"], contrast)

    # Retrieve conditions, make associations with contrasts
    conditions = Task.get_conditions(uid)

    context = {
        "task": task,
        "concepts": concept_lookup,
        "contrasts": contrasts,
        "conditions": conditions,
        "domain": DOMAIN
    }

    if return_context == True:
        return context
    return render(request, 'atlas/view_task.html', context)
Example #2
0
def task_gist(request, uid, query=None, return_gist=False):
    '''task_gist will return a cypher gist for a task, including nodes and relations
    :param uid: the uid for the task
    :param query: a custom query. If not defined, will show a table of concepts asserted.
    :param return_gist: if True, will return the context with all needed variables
    '''
    task_cypher, lookup = Task.cypher(uid, return_lookup=True)
    task_cypher = add_cypher_relations(task_cypher, lookup)

    task = Task.get(uid)[0]
    if query is None:
        query = "MATCH (t:task)-[r:ASSERTS]->(c:concept) RETURN t.name as task_name,c.name as concept_name;"

    # Join by newline
    task_cypher["links"] = "\n".join(task_cypher["links"])
    task_cypher["nodes"] = "\n".join(task_cypher["nodes"])

    context = {
        "relations": task_cypher["links"],
        "nodes": task_cypher["nodes"],
        "node_type": "task",
        "node_name": task["name"],
        "query": query
    }
    if return_gist is True:
        return context
    return render(request, 'graph/gist.html', context)
Example #3
0
def task_gist(request,uid,query=None,return_gist=False):
    '''task_gist will return a cypher gist for a task, including nodes and relations
    :param uid: the uid for the task
    :param query: a custom query. If not defined, will show a table of concepts asserted.
    :param return_gist: if True, will return the context with all needed variables
    '''    
    task_cypher,lookup = Task.cypher(uid,return_lookup=True)
    task_cypher = add_cypher_relations(task_cypher,lookup)

    task = Task.get(uid)[0]
    if query == None:
        query = "MATCH (t:task)-[r:ASSERTS]->(c:concept) RETURN t.name as task_name,c.name as concept_name;"

    # Join by newline
    task_cypher["links"] = "\n".join(task_cypher["links"])
    task_cypher["nodes"] = "\n".join(task_cypher["nodes"])

    context = {"relations":task_cypher["links"],
               "nodes":task_cypher["nodes"],
               "node_type":"task",
               "node_name":task["name"],
               "query":query}
    if return_gist == True:
        return context
    return render(request,'graph/gist.html',context)
Example #4
0
 def test_add_term_task(self):
     self.assertTrue(
         self.client.login(username=self.user.username,
                           password=self.password))
     task = Task()
     task_name = 'test_add_term_concept'
     definition = 'task definition'
     response = self.client.post(reverse('add_term'), {
         'term_type': 'task',
         'term_name': task_name,
         'definition_text': definition
     },
                                 follow=True)
     self.assertEqual(response.status_code, 200)
     uid = response.context['task']['id']
     tsk = task.get(uid)
     self.assertEqual(len(tsk), 1)
     tsk = task.graph.find_one('task', 'id', uid)