|
a/OSSEval/analysis/views.py |
|
b/OSSEval/analysis/views.py |
|
... |
|
... |
5 |
from django.template import RequestContext
|
5 |
from django.template import RequestContext
|
6 |
from django.utils import simplejson, timezone
|
6 |
from django.utils import simplejson, timezone
|
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, MyModelForm
|
11 |
from analysis.models import Analysis, Configuration, Instance, UploadedFile, Answer, Methodology, MethodologyVersion, Question, Page
|
11 |
from analysis.models import Analysis, Configuration, Instance, UploadedFile, Answer, Methodology, MethodologyVersion, Question, Page
|
12 |
#from methodology.models import Methodology, MethodologyVersion, Question, Page
|
12 |
#from methodology.models import Methodology, MethodologyVersion, Question, Page
|
13 |
from OSSEval.utils import xmlMinidom, TrivialJSONEncoder, SearchEngine
|
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)
|
17 |
form = AnalysisForm(request.POST)
|
18 |
if form.is_valid():
|
18 |
if form.is_valid():
|
19 |
model_instance = form.save()
|
19 |
model_instance = form.save()
|
|
|
20 |
model_instance.visible = True
|
|
|
21 |
weight_scenarios = model_instance.methodology_version.weight_scenario_set.filter(active=True)
|
|
|
22 |
if len(weight_scenarios) == 1:
|
|
|
23 |
model_instance.weight_scenario = weight_scenarios[0]
|
|
|
24 |
else:
|
|
|
25 |
raise Exception("There should be exactly one active WeightScenario for MethodologyVersion " + str(model_instance.methodology_version.id))
|
|
|
26 |
model_instance.protected = False
|
20 |
model_instance.created = timezone.now()
|
27 |
model_instance.created = timezone.now()
|
21 |
model_instance.save()
|
28 |
model_instance.save()
|
22 |
return HttpResponseRedirect(reverse('analysis_list'))
|
29 |
return HttpResponseRedirect(reverse('analysis_list'))
|
23 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
30 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
24 |
else:
|
31 |
else:
|
25 |
if analysis_id>0:
|
32 |
if analysis_id>0:
|
26 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
33 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
27 |
form = AnalysisForm(instance = analysis)
|
34 |
form = AnalysisForm(request.POST or None, instance = analysis)
|
28 |
return render(request, 'analysis/analysis_new.html', {'form': form, 'analysis': analysis})
|
35 |
return render(request, 'analysis/analysis_new.html', {'form': form, 'analysis': analysis})
|
29 |
else:
|
36 |
else:
|
30 |
form = AnalysisForm()
|
37 |
form = AnalysisForm()
|
31 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
38 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
32 |
|
39 |
|
|
... |
|
... |
36 |
context_object_name = 'analises_list'
|
43 |
context_object_name = 'analises_list'
|
37 |
|
44 |
|
38 |
def detail(request, analysis_id):
|
45 |
def detail(request, analysis_id):
|
39 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
46 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
40 |
entity = analysis.methodology_version.methodology.entity
|
47 |
entity = analysis.methodology_version.methodology.entity
|
41 |
|
48 |
weight_scenarios = analysis.methodology_version.weightscenario_set.all()
|
42 |
exec("from " + entity.actual_entity_app + ".views import search_html_form, instance_list_html")
|
49 |
exec("from " + entity.actual_entity_app + ".views import search_html_form, instance_list_html")
|
43 |
#"Content-Type: text/html; charset=utf-8" has to be removed as these methods return just a partial
|
50 |
#"Content-Type: text/html; charset=utf-8" has to be removed as these methods return just a partial
|
44 |
search_html_ui = str(search_html_form(request, analysis_id))[len("Content-Type: text/html; charset=utf-8"):]
|
51 |
search_html_ui = str(search_html_form(request, analysis_id))[len("Content-Type: text/html; charset=utf-8"):]
|
45 |
analysis_detail = str(instance_list_html(request, analysis_id))[len("Content-Type: text/html; charset=utf-8"):]
|
52 |
analysis_detail = str(instance_list_html(request, analysis_id))[len("Content-Type: text/html; charset=utf-8"):]
|
46 |
|
53 |
|
47 |
return render(request, 'analysis/analysis_detail.html', {'analysis': analysis, 'analysis_detail': analysis_detail, 'search_html_ui': search_html_ui})
|
54 |
return render(request, 'analysis/analysis_detail.html', {'analysis': analysis, 'analysis_detail': analysis_detail, 'search_html_ui': search_html_ui, 'weight_scenarios': weight_scenarios})
|
48 |
|
55 |
|
49 |
def analysis_questions(request, analysis_id):
|
56 |
def analysis_questions(request, analysis_id):
|
50 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
57 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
51 |
|
58 |
|
52 |
entity = analysis.methodology_version.methodology.entity
|
59 |
entity = analysis.methodology_version.methodology.entity
|
|
... |
|
... |
55 |
#"Content-Type: text/html; charset=utf-8" has to be removed as these methods return just a partial
|
62 |
#"Content-Type: text/html; charset=utf-8" has to be removed as these methods return just a partial
|
56 |
analysis_detail = str(instance_list_html(request, analysis_id))[len("Content-Type: text/html; charset=utf-8"):]
|
63 |
analysis_detail = str(instance_list_html(request, analysis_id))[len("Content-Type: text/html; charset=utf-8"):]
|
57 |
|
64 |
|
58 |
return render(request, 'analysis/analysis_questions.html', {'analysis': analysis, 'analysis_detail': analysis_detail, 'methodology_version': analysis.methodology_version})
|
65 |
return render(request, 'analysis/analysis_questions.html', {'analysis': analysis, 'analysis_detail': analysis_detail, 'methodology_version': analysis.methodology_version})
|
59 |
|
66 |
|
60 |
def analysis_report(request, analysis_id):
|
67 |
def analysis_report(request, analysis_id, weight_scenario_id = 0):
|
61 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
68 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
62 |
analysis.calculate_scores()
|
69 |
weight_scenario = analysis.calculate_scores(weight_scenario_id)
|
63 |
# print "I am in view 'analysis_report'; page: " + analysis.methodology_version.page_set.all()[0].name
|
|
|
64 |
# print "has radar_chart: " + analysis.methodology_version.page_set.all()[0].radar_chart[:100]
|
|
|
65 |
# print "has pippo: " + analysis.methodology_version.page_set.all()[0].pippo
|
|
|
66 |
td_width = 100 / (1 + len(analysis.instance_set.all()))
|
70 |
td_width = 100 / (1 + len(analysis.instance_set.all()))
|
|
|
71 |
trend_script = "<script type=\"text/javascript\" src=\"//www.google.com/trends/embed.js?hl=it&q="
|
|
|
72 |
comma = ""
|
|
|
73 |
for instance in analysis.instance_set.all():
|
|
|
74 |
trend_script += comma + instance.name
|
|
|
75 |
comma = ","
|
|
|
76 |
# trend_script += "eucalyptus,+OpenNebula,+OpenStack,+Mozilla+Firefox"
|
|
|
77 |
trend_script += "&cmpt=q&content=1&cid=TIMESERIES_GRAPH_0&export=5&w=500&h=330\"></script>"
|
67 |
return render(request, 'analysis/analysis_report.html', {'analysis': analysis, 'td_width': td_width})
|
78 |
return render(request, 'analysis/analysis_report.html', {'analysis': analysis, 'td_width': td_width, 'trend_script': trend_script, 'weight_scenario': weight_scenario})
|
68 |
|
79 |
|
69 |
def save_answer(request):
|
80 |
def save_answer(request):
|
70 |
try:
|
81 |
try:
|
71 |
question_id = request.POST.get("question_id", "")
|
82 |
question_id = request.POST.get("question_id", "")
|
72 |
id_selected_instance = request.POST.get("id_selected_instance", "")
|
83 |
id_selected_instance = request.POST.get("id_selected_instance", "")
|
|
... |
|
... |
213 |
a.from_xml(analysis_xml, always_insert)
|
224 |
a.from_xml(analysis_xml, always_insert)
|
214 |
return HttpResponseRedirect(reverse('analysis_detail', args=(a.id,)))
|
225 |
return HttpResponseRedirect(reverse('analysis_detail', args=(a.id,)))
|
215 |
else:
|
226 |
else:
|
216 |
a.id = analysis_xml.attributes["Id"].firstChild.data
|
227 |
a.id = analysis_xml.attributes["Id"].firstChild.data
|
217 |
return HttpResponseRedirect(reverse('analysis_list'))
|
228 |
return HttpResponseRedirect(reverse('analysis_list'))
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
def create_a_my_model(request):
|
|
|
232 |
if request.method == 'POST':
|
|
|
233 |
form = MyModelForm(request.POST)
|
|
|
234 |
if form.is_valid():
|
|
|
235 |
# save the model to database, directly from the form:
|
|
|
236 |
my_model = form.save() # reference to my_model is often not needed at all, a simple form.save() is ok
|
|
|
237 |
# alternatively:
|
|
|
238 |
# my_model = form.save(commit=False) # create model, but don't save to database
|
|
|
239 |
# my.model.something = whatever # if I need to do something before saving it
|
|
|
240 |
# my.model.save()
|
|
|
241 |
else:
|
|
|
242 |
form = MyModelForm()
|
|
|
243 |
c = { 'form' : form }
|
|
|
244 |
return render(request, 'analysis/template.html', c)
|