Switch to unified view

a/OSSEval/OpenSourceProject/models.py b/OSSEval/OpenSourceProject/models.py
...
...
4
from django.db import models
4
from django.db import models
5
5
6
from ohloh import OhlohProxy
6
from ohloh import OhlohProxy
7
from flossmole import FSF, FC, GC, GH
7
from flossmole import FSF, FC, GC, GH
8
from utils import Forges
8
from utils import Forges
9
from OSSEval.utils import xmlMinidom
9
10
10
class OSProject(models.Model):
11
class OSProject(models.Model):
11
    """
12
    """
12
    Must be the same name of the Django app                         ??????????????????????????????????????
13
    """
13
    """
14
    name = models.CharField(max_length=200)
14
    name = models.CharField(max_length=200)
15
    instance = models.OneToOneField('analysis.Instance', related_name='actual_instance', primary_key=True)
15
    instance = models.OneToOneField('analysis.Instance', related_name='actual_instance', primary_key=True)
16
16
17
    def __str__(self):
17
    def __str__(self):
18
        return self.name + " - " + self.instance.name
18
        return self.name + " - " + self.instance.name
19
    
19
    
20
    def to_xml(self):
21
        str_xml = "<OSProjectForges>"
22
        for osprojectforge in self.osprojectforge_set.all():
23
            str_xml += osprojectforge.to_xml()
24
        str_xml += "</OSProjectForges>"
25
        return '<OSProject Name="' + self.name + '">' + str_xml + "</OSProject>"
26
    
27
    def from_xml(self, xmldoc, instance, insert = True):
28
        self.name = xmlMinidom.getStringAttribute(xmldoc, 'Name')
29
        self.instance = instance
30
        self.save()
31
        #OSProjectForge
32
        xml_osproject_forges = xmldoc.getElementsByTagName('OSProjectForge')
33
        for xml_osproject_forge in xml_osproject_forges:
34
            ospf = OSProjectForge()
35
            ospf.from_xml(xml_osproject_forge, self, insert)
36
20
    def getInstanceInfo(self):
37
    def getInstanceInfo(self):
21
        '''
38
        '''
22
        Part of the required interface
39
        Part of the required interface
23
        i is a dictionary; each source information is within the source name key, e.g.
40
        i is a dictionary; each source information is within the source name key, e.g.
24
        i['FM']
41
        i['FM']
...
...
105
122
106
class Forge(models.Model):
123
class Forge(models.Model):
107
    name = models.CharField(max_length=50)
124
    name = models.CharField(max_length=50)
108
    url = models.CharField(max_length=200)
125
    url = models.CharField(max_length=200)
109
    os_projects = models.ManyToManyField(OSProject, through='OSProjectForge', blank=True)
126
    os_projects = models.ManyToManyField(OSProject, through='OSProjectForge', blank=True)
127
110
    def __str__(self):
128
    def __str__(self):
111
        return self.name + " - " + self.url
129
        return self.name + " - " + self.url
130
131
    def to_xml(self):
132
        return '<Forge Id="' + str(self.id) + '" Name="' + self.name + '" URL="' + self.url + '" />'
133
    #forges do not get added using xml, neither updated; they're are just a reference for OSProjectForge
134
    #hence there is no "from_xml"
112
135
113
class OSProjectForge(models.Model):
136
class OSProjectForge(models.Model):
114
    name = models.CharField(max_length=200)
137
    name = models.CharField(max_length=200)
115
    forge = models.ForeignKey(Forge)
138
    forge = models.ForeignKey(Forge)
116
    os_project = models.ForeignKey(OSProject)
139
    os_project = models.ForeignKey(OSProject)
117
    identifier_in_forge = models.CharField(max_length=200)
140
    identifier_in_forge = models.CharField(max_length=200)
118
    datasource_id = models.IntegerField()
141
    datasource_id = models.IntegerField()
142
    
143
    def to_xml(self):
144
        str_xml = self.forge.to_xml()
145
        return '<OSProjectForge Id="' + str(self.id) + '" Name="' + self.name + '" IdentifierInForge="' + str(self.identifier_in_forge) + '" DatasourceId="' + str(self.datasource_id) + '">' + str_xml + "</OSProjectForge>"
146
    
147
    def from_xml(self, xmldoc, os_project, insert = True):
148
        if not insert:
149
            self.id = xmlMinidom.getNaturalAttribute(xmldoc, 'Id')
150
        self.name = xmlMinidom.getStringAttribute(xmldoc, 'Name')
151
        self.identifier_in_forge = xmlMinidom.getStringAttribute(xmldoc, 'IdentifierInForge')
152
        self.datasource_id = xmlMinidom.getNaturalAttribute(xmldoc, 'DatasourceId')
153
        self.os_project = os_project
154
        #Forge
155
        xml_forge = xmldoc.getElementsByTagName('Forge')[0]
156
        f = Forge.objects.get(pk=xmlMinidom.getNaturalAttribute(xml_forge, 'Id'))
157
        self.forge = f
158
        self.save()
159
    
119
    def __str__(self):
160
    def __str__(self):
120
        return self.name + " - " + self.forge.name
161
        return self.name + " - " + self.forge.name
162
    
121
    def getProjectInfo(self):
163
    def getProjectInfo(self):
122
        if self.forge.id == Forges.OHLOH:
164
        if self.forge.id == Forges.OHLOH:
123
            osprojectforge_info = OhlohProxy.getProjectInfo(self.identifier_in_forge)
165
            osprojectforge_info = OhlohProxy.getProjectInfo(self.identifier_in_forge)
124
        if self.forge.id == Forges.FC:
166
        if self.forge.id == Forges.FC:
125
            osprojectforge_info = FC.getProjectInfo(self.identifier_in_forge)
167
            osprojectforge_info = FC.getProjectInfo(self.identifier_in_forge)