示例#1
0
 def duplicateGrid(self, gridObj, userObj=None, gridName=None, gridType=None):
     #create new grid
     if userObj:
         if gridName != None:
             newGrid = Grid(user=userObj, description=gridObj.description, name=gridName,
                            dendogram=gridObj.dendogram, grid_type=gridObj.grid_type, usid=generateRandomString(20),
                            dateTime=datetime.utcnow().replace(tzinfo=utc))
         else:
             newGrid = Grid(user=userObj, description=gridObj.description, name=gridObj.name,
                            dendogram=gridObj.dendogram, grid_type=gridObj.grid_type, usid=generateRandomString(20),
                            dateTime=datetime.utcnow().replace(tzinfo=utc))
     else:
         if gridName != None:
             newGrid = Grid(description=gridObj.description, name=gridName, dendogram=gridObj.dendogram,
                            grid_type=gridObj.grid_type, usid=generateRandomString(20),
                            dateTime=datetime.utcnow().replace(tzinfo=utc))
         else:
             newGrid = Grid(description=gridObj.description, name=gridObj.name, dendogram=gridObj.dendogram,
                            grid_type=gridObj.grid_type, usid=generateRandomString(20),
                            dateTime=datetime.utcnow().replace(tzinfo=utc))
     if gridType != None:
         newGrid.grid_type = gridType
     if newGrid:
         try:
             newGrid.save()
             newConcerns = []
             newAlternatives = []
             oldConcerns = gridObj.concerns_set.all()
             oldAlternatives = gridObj.alternatives_set.all()
             lenOldConcerns = len(oldConcerns)
             lenOldAlternatives = len(oldAlternatives)
             for concern in oldConcerns:
                 temp = Concerns.objects.create(grid=newGrid, leftPole=concern.leftPole, rightPole=concern.rightPole,
                                                weight=concern.weight)
                 newConcerns.append(temp)
             for alternative in oldAlternatives:
                 temp = Alternatives.objects.create(grid=newGrid, name=alternative.name,
                                                    description=alternative.description)
                 newAlternatives.append(temp)
             i = 0
             j = 0
             while i < lenOldConcerns:
                 while j < lenOldAlternatives:
                     oldRating = Ratings.objects.get(concern=oldConcerns[i], alternative=oldAlternatives[j])
                     Ratings.objects.create(concern=newConcerns[i], alternative=newAlternatives[j],
                                            rating=oldRating.rating)
                     j += 1
                 j = 0
                 i += 1
             return newGrid
         except:
             #delete what ever we had
             if newGrid:
                 newGrid.delete()
     return False
示例#2
0
文件: models.py 项目: abap/RGT-tool
    def create_session(self,
                       facilitating_user,
                       original_grid,
                       name=None,
                       show_results=None):
        if name is None or name == '':
            name = 'untitled'
        if show_results is None:
            show_results = False

        facilitator, created = Facilitator.objects.get_or_create(
            user=facilitating_user)
        usid = generateRandomString(SESSION_USID_KEY_LENGTH)
        state = State.objects.getInitialState()
        invitation_key = str(uuid.uuid4())

        session = self.create(usid=usid,
                              facilitator=facilitator,
                              name=name,
                              showResult=show_results,
                              state=state,
                              invitationKey=invitation_key)
        duplicateGrid = Grid.objects.duplicateGrid(
            original_grid, gridType=Grid.GridType.SESSION_GRID)
        SessionGrid.objects.create(session=session,
                                   grid=duplicateGrid,
                                   iteration=0)

        return session
示例#3
0
文件: models.py 项目: abap/RGT-tool
class Grid(models.Model):
    # from django.contrib.auth import get_user_model
    # User = get_user_model()

    usid = models.CharField(
        max_length=20,
        unique=True,
        default=lambda: generateRandomString(GRID_USID_KEY_LENGTH))

    from django.contrib.auth.models import User

    user = models.ForeignKey(User, null=True)
    name = models.CharField(max_length=30, default='untitled')
    description = models.TextField(null=True)
    dendogram = models.TextField(null=True)
    dateTime = models.DateTimeField(auto_now_add=True, null=True)
    grid_types = (('u', 'User grid'), ('s', 'Session grid'),
                  ('ac', 'Response grid, Alternative/Concern'),
                  ('rw', 'Response grid, Ratings/Weight'), ('cg',
                                                            'Composite Grid'))
    grid_type = models.CharField(max_length=2, choices=grid_types, default='u')
    objects = GridManager()

    def get_absolute_url(self):
        # return reverse('RGT.gridMng.views.show_grid', args=[self.usid])
        return reverse('show_grid', args=[self.usid])

    def get_alternative_total_rating_tuples(self):
        """ Return a collection containing a tuple for each alternative containing that alternative and the total
         weighted rating of that alternative. E.g. in a grid for programming languages, it returns a collection as
         (['Python', 1], ['Java', 2], ['PHP', 5])
        """
        alts_and_ratings = []
        for alternative in self.alternatives_set.all():
            total_rating = alternative.get_total_rating()
            alts_and_ratings.append((alternative.name, total_rating))

        return alts_and_ratings

    def __unicode__(self):
        return self.name

    class Meta:
        ordering = ['id']
        app_label = 'gridMng'

    class GridType(object):
        USER_GRID = 'u'
        SESSION_GRID = 's'
        RESPONSE_GRID_ALTERNATIVE_CONCERN = 'ac'
        RESPONSE_GRID_RATING_WEIGHT = 'rw'
        COMPOSITE_GRID = 'cg'
示例#4
0
    def create_session(self, facilitating_user, original_grid, name=None, show_results=None):
        if name is None or name == '':
            name = 'untitled'
        if show_results is None:
            show_results = False

        facilitator, created = Facilitator.objects.get_or_create(user=facilitating_user)
        usid = generateRandomString(SESSION_USID_KEY_LENGTH)
        state = State.objects.getInitialState()
        invitation_key = str(uuid.uuid4())

        session = self.create(usid=usid, facilitator=facilitator, name=name, showResult=show_results, state=state, invitationKey=invitation_key)
        duplicateGrid = Grid.objects.duplicateGrid(original_grid, gridType=Grid.GridType.SESSION_GRID)
        SessionGrid.objects.create(session=session, grid=duplicateGrid, iteration=0)

        return session
示例#5
0
文件: models.py 项目: abap/RGT-tool
 def duplicateGrid(self,
                   gridObj,
                   userObj=None,
                   gridName=None,
                   gridType=None):
     # create new grid
     if userObj:
         if gridName is not None:
             newGrid = Grid(user=userObj,
                            description=gridObj.description,
                            name=gridName,
                            dendogram=gridObj.dendogram,
                            grid_type=gridObj.grid_type,
                            usid=generateRandomString(20),
                            dateTime=datetime.utcnow().replace(tzinfo=utc))
         else:
             newGrid = Grid(user=userObj,
                            description=gridObj.description,
                            name=gridObj.name,
                            dendogram=gridObj.dendogram,
                            grid_type=gridObj.grid_type,
                            usid=generateRandomString(20),
                            dateTime=datetime.utcnow().replace(tzinfo=utc))
     else:
         if gridName is not None:
             newGrid = Grid(description=gridObj.description,
                            name=gridName,
                            dendogram=gridObj.dendogram,
                            grid_type=gridObj.grid_type,
                            usid=generateRandomString(20),
                            dateTime=datetime.utcnow().replace(tzinfo=utc))
         else:
             newGrid = Grid(description=gridObj.description,
                            name=gridObj.name,
                            dendogram=gridObj.dendogram,
                            grid_type=gridObj.grid_type,
                            usid=generateRandomString(20),
                            dateTime=datetime.utcnow().replace(tzinfo=utc))
     if gridType is not None:
         newGrid.grid_type = gridType
     if newGrid:
         try:
             newGrid.save()
             newConcerns = []
             newAlternatives = []
             oldConcerns = gridObj.concerns_set.all()
             oldAlternatives = gridObj.alternatives_set.all()
             lenOldConcerns = len(oldConcerns)
             lenOldAlternatives = len(oldAlternatives)
             for concern in oldConcerns:
                 temp = Concerns.objects.create(grid=newGrid,
                                                leftPole=concern.leftPole,
                                                rightPole=concern.rightPole,
                                                weight=concern.weight)
                 newConcerns.append(temp)
             for alternative in oldAlternatives:
                 temp = Alternatives.objects.create(
                     grid=newGrid,
                     name=alternative.name,
                     description=alternative.description)
                 newAlternatives.append(temp)
             i = 0
             j = 0
             while i < lenOldConcerns:
                 while j < lenOldAlternatives:
                     oldRating = Ratings.objects.get(
                         concern=oldConcerns[i],
                         alternative=oldAlternatives[j])
                     Ratings.objects.create(concern=newConcerns[i],
                                            alternative=newAlternatives[j],
                                            rating=oldRating.rating)
                     j += 1
                 j = 0
                 i += 1
             return newGrid
         except:
             # delete what ever we had
             if newGrid:
                 newGrid.delete()
     return False