|
a/OSSEval/analysis/views.py |
|
b/OSSEval/analysis/views.py |
|
... |
|
... |
25 |
from forms import AnalysisForm, UploadFileForm, ImportChoice
|
25 |
from forms import AnalysisForm, UploadFileForm, ImportChoice
|
26 |
from analysis.models import Analysis, Instance, UploadedFile, Answer, Methodology, MethodologyVersion, Question, Page
|
26 |
from analysis.models import Analysis, Instance, UploadedFile, Answer, Methodology, MethodologyVersion, Question, Page
|
27 |
#from methodology.models import Methodology, MethodologyVersion, Question, Page
|
27 |
#from methodology.models import Methodology, MethodologyVersion, Question, Page
|
28 |
from OSSEval.utils import xmlMinidom, TrivialJSONEncoder, SearchEngine
|
28 |
from OSSEval.utils import xmlMinidom, TrivialJSONEncoder, SearchEngine
|
29 |
|
29 |
|
|
|
30 |
def analysis_new(request):
|
|
|
31 |
if request.method == "POST":
|
|
|
32 |
form = AnalysisForm(request.POST)
|
|
|
33 |
if form.is_valid():
|
|
|
34 |
if reverse('analysis_new') in request.META['HTTP_REFERER']:
|
|
|
35 |
# creating a new
|
|
|
36 |
model_instance = form.save()
|
|
|
37 |
model_instance.visible = True
|
|
|
38 |
weight_scenarios = model_instance.methodology_version.weightscenario_set.filter(active=True)
|
|
|
39 |
if len(weight_scenarios) == 1:
|
|
|
40 |
model_instance.weight_scenario = weight_scenarios[0]
|
|
|
41 |
else:
|
|
|
42 |
raise Exception("There should be exactly one active WeightScenario for MethodologyVersion " + str(model_instance.methodology_version.id))
|
|
|
43 |
model_instance.protected = False
|
|
|
44 |
model_instance.created = timezone.now()
|
|
|
45 |
model_instance.save()
|
|
|
46 |
return HttpResponseRedirect(reverse('analysis_detail', args=(model_instance.pk,)))
|
|
|
47 |
else:
|
|
|
48 |
# editing an existing one
|
|
|
49 |
id = request.META['HTTP_REFERER'].rsplit('/')[len(request.META['HTTP_REFERER'].rsplit('/'))-1]
|
|
|
50 |
a = Analysis.objects.get(pk = id)
|
|
|
51 |
a.name = form.cleaned_data['name']
|
|
|
52 |
a.description = form.cleaned_data['description']
|
|
|
53 |
a.comment = form.cleaned_data['comment']
|
|
|
54 |
a.created = form.cleaned_data['created']
|
|
|
55 |
a.methodology_version = form.cleaned_data['methodology_version']
|
|
|
56 |
a.user_login = form.cleaned_data['user_login']
|
|
|
57 |
a.visible = form.cleaned_data['visible']
|
|
|
58 |
a.protected = form.cleaned_data['protected']
|
|
|
59 |
a.save()
|
|
|
60 |
return HttpResponseRedirect(reverse('analysis_detail', args=(a.id,)))
|
|
|
61 |
else:
|
|
|
62 |
form = AnalysisForm()
|
|
|
63 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
|
|
64 |
|
30 |
def analysis_new(request, analysis_id=0):
|
65 |
def analysis_edit(request, analysis_id):
|
31 |
if request.method == "POST":
|
66 |
if request.method == "POST":
|
32 |
form = AnalysisForm(request.POST)
|
67 |
form = AnalysisForm(request.POST)
|
33 |
if form.is_valid():
|
68 |
if form.is_valid():
|
34 |
model_instance = form.save()
|
69 |
model_instance = form.save()
|
35 |
model_instance.visible = True
|
70 |
model_instance.visible = True
|
|
... |
|
... |
40 |
raise Exception("There should be exactly one active WeightScenario for MethodologyVersion " + str(model_instance.methodology_version.id))
|
75 |
raise Exception("There should be exactly one active WeightScenario for MethodologyVersion " + str(model_instance.methodology_version.id))
|
41 |
model_instance.protected = False
|
76 |
model_instance.protected = False
|
42 |
model_instance.created = timezone.now()
|
77 |
model_instance.created = timezone.now()
|
43 |
model_instance.save()
|
78 |
model_instance.save()
|
44 |
return HttpResponseRedirect(reverse('analysis_list'))
|
79 |
return HttpResponseRedirect(reverse('analysis_list'))
|
45 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
80 |
return render(request, 'analysis/analysis_edit.html', {'form': form})
|
46 |
else:
|
81 |
else:
|
47 |
if analysis_id>0:
|
|
|
48 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
82 |
analysis = get_object_or_404(Analysis, pk=analysis_id)
|
49 |
form = AnalysisForm(request.POST or None, instance = analysis)
|
83 |
form = AnalysisForm(request.POST or None, instance = analysis)
|
50 |
return render(request, 'analysis/analysis_new.html', {'form': form, 'analysis': analysis})
|
84 |
return render(request, 'analysis/analysis_edit.html', {'form': form, 'analysis': analysis})
|
51 |
else:
|
|
|
52 |
form = AnalysisForm()
|
|
|
53 |
return render(request, 'analysis/analysis_new.html', {'form': form})
|
|
|
54 |
|
|
|
55 |
|
85 |
|
56 |
class AnalysisList(ListView):
|
86 |
class AnalysisList(ListView):
|
57 |
queryset = Analysis.objects.order_by('-created')
|
87 |
queryset = Analysis.objects.order_by('-created')
|
58 |
context_object_name = 'analises_list'
|
88 |
context_object_name = 'analises_list'
|
59 |
|
89 |
|