|
a/OSSEval/analysis/views.py |
|
b/OSSEval/analysis/views.py |
|
... |
|
... |
7 |
from django.views.generic import ListView
|
7 |
from django.views.generic import ListView
|
8 |
from xml.dom import minidom
|
8 |
from xml.dom import minidom
|
9 |
|
9 |
|
10 |
from forms import AnalysisForm, UploadFileForm, ImportChoice
|
10 |
from forms import AnalysisForm, UploadFileForm, ImportChoice
|
11 |
from analysis.models import Analysis, Configuration, Instance, UploadedFile, Answer
|
11 |
from analysis.models import Analysis, Configuration, Instance, UploadedFile, Answer
|
12 |
from methodology.models import Methodology, MethodologyVersion, Question
|
12 |
from methodology.models import Methodology, MethodologyVersion, Question, Page
|
13 |
from OSSEval.utils import xmlMinidom, TrivialJSONEncoder
|
13 |
from OSSEval.utils import xmlMinidom, TrivialJSONEncoder, SearchEngine
|
14 |
|
14 |
|
15 |
def analysis_new(request, analysis_id=0):
|
15 |
def analysis_new(request, analysis_id=0):
|
16 |
if request.method == "POST":
|
16 |
if request.method == "POST":
|
|
|
17 |
form = AnalysisForm(request.POST)
|
|
|
18 |
if form.is_valid():
|
|
|
19 |
model_instance = form.save()
|
|
|
20 |
model_instance.created = timezone.now()
|
|
|
21 |
model_instance.save()
|
|
|
22 |
return HttpResponseRedirect(reverse('analysis_list'))
|
|
|
23 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
|
|
24 |
else:
|
17 |
if analysis_id>0:
|
25 |
if analysis_id>0:
|
18 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
26 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
19 |
form = AnalysisForm(instance = analysis)
|
27 |
form = AnalysisForm(instance = analysis)
|
|
|
28 |
return render(request, 'analysis/analysis_new.html', {'form': form, 'analysis': analysis})
|
20 |
else:
|
29 |
else:
|
21 |
form = AnalysisForm(request.POST)
|
|
|
22 |
if form.is_valid():
|
|
|
23 |
cfg = Configuration.objects.get(pk=1)
|
|
|
24 |
model_instance = form.save()
|
|
|
25 |
model_instance.created = timezone.now()
|
|
|
26 |
# model_instance.methodology_version = cfg.default_methodology_version
|
|
|
27 |
# print "model_instance.methodology_version: " + str(model_instance.methodology_version.id)
|
|
|
28 |
model_instance.save()
|
|
|
29 |
return HttpResponseRedirect(reverse('analysis_list'))
|
|
|
30 |
else:
|
|
|
31 |
form = AnalysisForm()
|
30 |
form = AnalysisForm()
|
32 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
31 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
33 |
|
32 |
|
34 |
|
33 |
|
35 |
class AnalysisList(ListView):
|
34 |
class AnalysisList(ListView):
|
36 |
queryset = Analysis.objects.order_by('-created')
|
35 |
queryset = Analysis.objects.order_by('-created')
|
37 |
context_object_name = 'analises_list'
|
36 |
context_object_name = 'analises_list'
|
38 |
|
37 |
|
39 |
def detail(request, analysis_id):
|
38 |
def detail(request, analysis_id):
|
40 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
39 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
41 |
|
|
|
42 |
entity = analysis.methodology_version.methodology.entity
|
40 |
entity = analysis.methodology_version.methodology.entity
|
43 |
|
41 |
|
44 |
exec("from " + entity.actual_entity_app + ".views import search_html_form, instance_list_html")
|
42 |
exec("from " + entity.actual_entity_app + ".views import search_html_form, instance_list_html")
|
45 |
#"Content-Type: text/html; charset=utf-8" has to be removed as these methods return just a partial
|
43 |
#"Content-Type: text/html; charset=utf-8" has to be removed as these methods return just a partial
|
46 |
search_html_ui = str(search_html_form(request, analysis_id))[len("Content-Type: text/html; charset=utf-8"):]
|
44 |
search_html_ui = str(search_html_form(request, analysis_id))[len("Content-Type: text/html; charset=utf-8"):]
|
|
... |
|
... |
82 |
|
80 |
|
83 |
def get_answers(request):
|
81 |
def get_answers(request):
|
84 |
id_instance = request.GET.get("id_instance", "")
|
82 |
id_instance = request.GET.get("id_instance", "")
|
85 |
answers = Answer.objects.filter(instance_id=id_instance)
|
83 |
answers = Answer.objects.filter(instance_id=id_instance)
|
86 |
return HttpResponse(TrivialJSONEncoder().encode(list(answers)))
|
84 |
return HttpResponse(TrivialJSONEncoder().encode(list(answers)))
|
|
|
85 |
|
|
|
86 |
def get_metadata(request):
|
|
|
87 |
metadata = []
|
|
|
88 |
id_instance = request.GET.get("id_instance", "")
|
|
|
89 |
instance = Instance.objects.get(pk = id_instance)
|
|
|
90 |
entity = instance.analysis.methodology_version.methodology.entity
|
|
|
91 |
#list of questions; just a plain list, I do not care in which page they are
|
|
|
92 |
list_of_questions = []
|
|
|
93 |
pages = Page.objects.filter(methodology_version = instance.analysis.methodology_version)
|
|
|
94 |
for page in pages:
|
|
|
95 |
list_of_questions += page.questions()
|
|
|
96 |
#all metadata about this instance
|
|
|
97 |
i = instance.actual_instance.getInstanceInfo()
|
|
|
98 |
|
|
|
99 |
#eval python; python code assumes that all the information is in a structure called "i" which stands for "instance"
|
|
|
100 |
for question in list_of_questions:
|
|
|
101 |
description = ""
|
|
|
102 |
value = -1
|
|
|
103 |
exec(question.eval_description)
|
|
|
104 |
exec(question.eval_value)
|
|
|
105 |
#run queries on search engine
|
|
|
106 |
for query in question.query_set.all():
|
|
|
107 |
site = ""
|
|
|
108 |
print query.eval_text
|
|
|
109 |
exec(query.eval_text)
|
|
|
110 |
print q
|
|
|
111 |
print query.eval_site
|
|
|
112 |
exec(query.eval_site)
|
|
|
113 |
print site
|
|
|
114 |
search_count = str(SearchEngine.search_count(q, site))
|
|
|
115 |
search_url = SearchEngine.search_url(q, site)
|
|
|
116 |
print "get_metadata search_url: " + search_url
|
|
|
117 |
search_engine_name = SearchEngine.search__engine_name()
|
|
|
118 |
description += "<a target='_blank' href='" + search_url + "'>'" + SearchEngine.readable_query(q, site) + "' on " + search_engine_name + ": (" + search_count + " results)</a><br>"
|
|
|
119 |
q = {}
|
|
|
120 |
q["question_id"] = question.id
|
|
|
121 |
q["description"] = description
|
|
|
122 |
q["value"] = value
|
|
|
123 |
metadata.append(q)
|
|
|
124 |
|
|
|
125 |
#restituire la lista delle domande con le elaborazioni allegate
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
# answers = Answer.objects.filter(instance_id=id_instance)
|
|
|
129 |
return HttpResponse(TrivialJSONEncoder().encode(list(metadata)))
|
87 |
|
130 |
|
88 |
def export(request, analysis_id):
|
131 |
def export(request, analysis_id):
|
89 |
a = get_object_or_404(Analysis, pk=analysis_id)
|
132 |
a = get_object_or_404(Analysis, pk=analysis_id)
|
90 |
mv = a.methodology_version
|
133 |
mv = a.methodology_version
|
91 |
exported_xml = "<osseval>" + a.to_xml() + mv.to_xml() + "</osseval>"
|
134 |
exported_xml = "<osseval>" + a.to_xml() + mv.to_xml() + "</osseval>"
|
|
... |
|
... |
157 |
a = Analysis()
|
200 |
a = Analysis()
|
158 |
a.methodology_version = mv
|
201 |
a.methodology_version = mv
|
159 |
analysis_xml = xmldoc.getElementsByTagName('Analysis')[0]
|
202 |
analysis_xml = xmldoc.getElementsByTagName('Analysis')[0]
|
160 |
if import_analysis:
|
203 |
if import_analysis:
|
161 |
a.from_xml(analysis_xml, always_insert)
|
204 |
a.from_xml(analysis_xml, always_insert)
|
|
|
205 |
return HttpResponseRedirect(reverse('analysis_detail', args=(a.id,)))
|
162 |
else:
|
206 |
else:
|
163 |
a.id = analysis_xml.attributes["Id"].firstChild.data
|
207 |
a.id = analysis_xml.attributes["Id"].firstChild.data
|
164 |
return HttpResponseRedirect(reverse('analysis_detail', args=(a.id,)))
|
208 |
return HttpResponseRedirect(reverse('analysis_list'))
|