|
a/OSSEval/analysis/views.py |
|
b/OSSEval/analysis/views.py |
|
... |
|
... |
28 |
def analysis_new(request):
|
28 |
def analysis_new(request):
|
29 |
if request.method == "POST":
|
29 |
if request.method == "POST":
|
30 |
form = AnalysisForm(request.POST)
|
30 |
form = AnalysisForm(request.POST)
|
31 |
if form.is_valid():
|
31 |
if form.is_valid():
|
32 |
if reverse('analysis_new') in request.META['HTTP_REFERER']:
|
32 |
if reverse('analysis_new') in request.META['HTTP_REFERER']:
|
|
|
33 |
methodology_version = MethodologyVersion.objects.get(pk=request.POST['methodology_version'])
|
|
|
34 |
weight_scenarios = methodology_version.weightscenario_set.filter(active=True)
|
|
|
35 |
if len(weight_scenarios) != 1:
|
|
|
36 |
raise Exception("There should be exactly one active WeightScenario for MethodologyVersion " + str(methodology_version.id))
|
33 |
# creating a new
|
37 |
# creating a new
|
34 |
model_instance = form.save()
|
38 |
a = Analysis()
|
35 |
model_instance.visible = True
|
39 |
a.name = form.cleaned_data['name']
|
36 |
weight_scenarios = model_instance.methodology_version.weightscenario_set.filter(active=True)
|
40 |
a.description = form.cleaned_data['description']
|
37 |
if len(weight_scenarios) == 1:
|
41 |
a.comment = form.cleaned_data['comment']
|
|
|
42 |
a.created = form.cleaned_data['created']
|
|
|
43 |
a.methodology_version = form.cleaned_data['methodology_version']
|
38 |
model_instance.weight_scenario = weight_scenarios[0]
|
44 |
a.weight_scenario = weight_scenarios[0]
|
39 |
else:
|
45 |
a.user_login = form.cleaned_data['user_login']
|
40 |
raise Exception("There should be exactly one active WeightScenario for MethodologyVersion " + str(model_instance.methodology_version.id))
|
|
|
41 |
model_instance.protected = False
|
|
|
42 |
model_instance.created = timezone.now()
|
|
|
43 |
model_instance.save()
|
46 |
a.save()
|
44 |
return HttpResponseRedirect(reverse('analysis_detail', args=(model_instance.pk,)))
|
47 |
return HttpResponseRedirect(reverse('analysis_detail', args=(a.id,)))
|
45 |
else:
|
48 |
else:
|
46 |
# editing an existing one
|
49 |
# editing an existing one
|
47 |
id = request.META['HTTP_REFERER'].rsplit('/')[len(request.META['HTTP_REFERER'].rsplit('/'))-1]
|
50 |
id = request.META['HTTP_REFERER'].rsplit('/')[len(request.META['HTTP_REFERER'].rsplit('/'))-1]
|
48 |
a = Analysis.objects.get(pk = id)
|
51 |
a = Analysis.objects.get(pk = id)
|
49 |
a.name = form.cleaned_data['name']
|
52 |
a.name = form.cleaned_data['name']
|
50 |
a.description = form.cleaned_data['description']
|
53 |
a.description = form.cleaned_data['description']
|
51 |
a.comment = form.cleaned_data['comment']
|
54 |
a.comment = form.cleaned_data['comment']
|
52 |
a.created = form.cleaned_data['created']
|
55 |
a.created = form.cleaned_data['created']
|
53 |
a.methodology_version = form.cleaned_data['methodology_version']
|
56 |
a.methodology_version = form.cleaned_data['methodology_version']
|
54 |
a.user_login = form.cleaned_data['user_login']
|
57 |
a.user_login = form.cleaned_data['user_login']
|
55 |
a.visible = form.cleaned_data['visible']
|
|
|
56 |
a.protected = form.cleaned_data['protected']
|
|
|
57 |
a.save()
|
58 |
a.save()
|
58 |
return HttpResponseRedirect(reverse('analysis_detail', args=(a.id,)))
|
59 |
return HttpResponseRedirect(reverse('analysis_detail', args=(a.id,)))
|
59 |
else:
|
60 |
else:
|
60 |
form = AnalysisForm()
|
61 |
form = AnalysisForm()
|
61 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
62 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
|
... |
|
... |
69 |
weight_scenarios = model_instance.methodology_version.weightscenario_set.filter(active=True)
|
70 |
weight_scenarios = model_instance.methodology_version.weightscenario_set.filter(active=True)
|
70 |
if len(weight_scenarios) == 1:
|
71 |
if len(weight_scenarios) == 1:
|
71 |
model_instance.weight_scenario = weight_scenarios[0]
|
72 |
model_instance.weight_scenario = weight_scenarios[0]
|
72 |
else:
|
73 |
else:
|
73 |
raise Exception("There should be exactly one active WeightScenario for MethodologyVersion " + str(model_instance.methodology_version.id))
|
74 |
raise Exception("There should be exactly one active WeightScenario for MethodologyVersion " + str(model_instance.methodology_version.id))
|
74 |
model_instance.protected = False
|
|
|
75 |
model_instance.created = timezone.now()
|
75 |
model_instance.created = timezone.now()
|
76 |
model_instance.save()
|
76 |
model_instance.save()
|
77 |
return HttpResponseRedirect(reverse('analysis_list'))
|
77 |
return HttpResponseRedirect(reverse('analysis_list'))
|
78 |
return render(request, 'analysis/analysis_edit.html', {'form': form})
|
78 |
return render(request, 'analysis/analysis_edit.html', {'form': form})
|
79 |
else:
|
79 |
else:
|
|
... |
|
... |
206 |
exec(query.eval_site)
|
206 |
exec(query.eval_site)
|
207 |
search_count = str(SearchEngine.search_count(q, sites))
|
207 |
search_count = str(SearchEngine.search_count(q, sites))
|
208 |
search_url = SearchEngine.search_url(q, sites)
|
208 |
search_url = SearchEngine.search_url(q, sites)
|
209 |
search_engine_name = SearchEngine.search__engine_name()
|
209 |
search_engine_name = SearchEngine.search__engine_name()
|
210 |
description += "<a target='_blank' href='" + search_url + "'>'" + SearchEngine.readable_query(q, sites) + "' on " + search_engine_name + ": (" + search_count + " results)</a><br>"
|
210 |
description += "<a target='_blank' href='" + search_url + "'>'" + SearchEngine.readable_query(q, sites) + "' on " + search_engine_name + ": (" + search_count + " results)</a><br>"
|
211 |
# eval_description and eval_value might use the results from the above queries so have to be run after them
|
211 |
# eval_description and eval_value might use the results from the above queries so have to be run after them
|
|
|
212 |
try:
|
212 |
exec(question.eval_description)
|
213 |
exec(question.eval_description)
|
|
|
214 |
except Exception as ex:
|
|
|
215 |
print str(ex)
|
|
|
216 |
try:
|
213 |
exec(question.eval_value)
|
217 |
exec(question.eval_value)
|
|
|
218 |
except:
|
|
|
219 |
pass
|
214 |
q = {}
|
220 |
q = {}
|
215 |
q["question_id"] = question.id
|
221 |
q["question_id"] = question.id
|
216 |
print "question.id: " + str(question.id)
|
222 |
print "question.id: " + str(question.id)
|
217 |
q["description"] = description
|
223 |
q["description"] = description
|
218 |
q["value"] = value
|
224 |
q["value"] = value
|