Parent: [831432] (diff)

Download this file

views.py    131 lines (114 with data), 6.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# This Source Code Form of OSSEval is subject to the terms of the GNU AFFERO
# GENERAL PUBLIC LICENSE, v. 3.0. If a copy of the AGPL was not
# distributed with this file, You can obtain one at http://www.gnu.org/licenses/agpl.txt
#
# OSSeval is powered by the SOS Open Source AGPL edition.
# The AGPL requires that you do not remove the SOS Open Source attribution and copyright
# notices from the user interface (see section 5.d below).
# OSSEval Copyright 2014 Bitergium SLL
# SOS Open Source Copyright 2012 Roberto Galoppini
# Author: Davide Galletti
from pprint import pformat
from django.conf import settings
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render, get_object_or_404
from analysis.models import Analysis, Instance
from forms import SearchForm
from flossmole import FSF, FC, GC, GH
from doap import Apache, Eclipse
from OpenSourceProject.models import OSProjectForge, OSProject, Forge
from ohloh import OhlohProxy
from utils import Forges
import OpenSourceProject
def test(request):
return HttpResponse(OpenSourceProject.record_limit)
def instance_list_html(request, analysis_id):
'''
Part of the required interface
'''
analysis = Analysis.objects.get(pk=analysis_id)
context = {'analysis': analysis}
return render(request, 'OSProject/detail.html', context)
def search_html_form(request, analysis_id):
'''
Part of the required interface
'''
form = SearchForm(initial={'analysis_id': analysis_id}) # An unbound form
return render(request, 'OSProject/search.html', {'form': form})
def search_html(request):
'''
Part of the required interface
'''
form = SearchForm(request.POST)
if form.is_valid(): # All validation rules pass
target = int(str(form.cleaned_data['target']))
name = str(form.cleaned_data['name'])
analysis_id = str(form.cleaned_data['analysis_id'])
projects = []
if target == Forges.FC or target == Forges.ALL:
projects += FC.search(name)
if target == Forges.FSF or target == Forges.ALL:
projects += FSF.search(name)
if target == Forges.GC or target == Forges.ALL:
projects += GC.search(name)
if target == Forges.GH or target == Forges.ALL:
projects += GH.search(name)
if target == Forges.OHLOH or target == Forges.ALL:
projects += OhlohProxy.search(name)
if target == Forges.APACHE or target == Forges.ALL:
projects += Apache.search(name)
if target == Forges.ECLIPSE or target == Forges.ALL:
projects += Eclipse.search(name)
return render(request, 'OSProject/search_results.html', {'projects': projects, 'analysis_id': analysis_id})
def OSProjectForge_delete(request, osprojectforge_id, analysis_id):
pf = get_object_or_404(OSProjectForge, pk=osprojectforge_id)
osp = pf.os_project
i = osp.instance
pf.delete()
if len(osp.osprojectforge_set.all()) == 0:
osp.delete()
i.delete()
return HttpResponseRedirect(reverse('analysis_detail', args=(analysis_id,)))
def OSProjectForge_add(request):
#TODO: check there's just one per forge
analysis_id = int(request.POST.get("analysis_id", ""))
id_forge = int(request.POST.get("id_forge", ""))
datasource_id = request.POST.get("datasource_id", "")
# I strip the project name as it is used in jquery tabs; some project names contain \n which breaks jquery tabs rendering
project_name = request.POST.get("project_name", "").strip()
identifier_in_forge = request.POST.get("identifier_in_forge", "")
id_selected_instance = int(request.POST.get("id_selected_instance", ""))
#id_selected_instance is -1 if I have to create a new instance; otherwise it tells to which instance I should add it
if id_selected_instance > 0:
instance = Instance.objects.get(pk=id_selected_instance)
osp=OSProject.objects.get(instance = instance)
for ospf in osp.osprojectforge_set.all():
if ospf.forge.id == id_forge:
return HttpResponseRedirect(reverse('analysis_detail', args=(analysis_id,)))
else:
analysis = get_object_or_404(Analysis, pk=analysis_id)
instance=Instance.objects.create(name=project_name, name_for_search="", analysis=analysis)
osp=OSProject.objects.create(name=project_name, instance=instance)
forge=Forge.objects.get(pk=id_forge)
pf=OSProjectForge(name=project_name, os_project=osp, forge=forge, identifier_in_forge=identifier_in_forge, datasource_id=datasource_id)
pf.save()
return HttpResponseRedirect(reverse('analysis_detail', args=(analysis_id,)))
def OSProjectForgeFromResultList_detail(request):
identifier_in_forge = request.POST.get("identifier_in_forge", "")
id_forge = int(request.POST.get("id_forge", ""))
pf = OSProjectForge(identifier_in_forge=identifier_in_forge, forge_id=id_forge)
osprojectforge_info = pf.getProjectInfo()
osprojectforge_info_nice_print = pformat(osprojectforge_info)
return render(request, 'OSProject/osprojectforge_detail.html', {'osprojectforge_info': osprojectforge_info, 'osprojectforge_info_nice_print': osprojectforge_info_nice_print})
def OSProjectForge_detail(request, osprojectforge_id):
pf = get_object_or_404(OSProjectForge, pk=osprojectforge_id)
osprojectforge_info = pf.getProjectInfo()
osprojectforge_info_nice_print = pformat(osprojectforge_info)
return render(request, 'OSProject/osprojectforge_detail.html', {'osprojectforge_info': osprojectforge_info, 'osprojectforge_info_nice_print': osprojectforge_info_nice_print})
def OSProject_detail(request, osproject_id):
osp = get_object_or_404(OSProject, pk=osproject_id)
osproject_info = osp.getInstanceInfo()
osproject_info_nice_print = pformat(osproject_info)
return render(request, 'OSProject/osproject_detail.html', {'osprojectforge_info': osproject_info, 'osprojectforge_info_nice_print': osproject_info_nice_print})