Esempio n. 1
0
def ajaxGenerateDendogram(request):
    if not request.user.is_authenticated():
        return redirect_to(request, '/auth/login/')
    if request.POST.has_key('gridUSID'):
        grid1= Grid.objects.filter(user= request.user, usid= request.POST['gridUSID'])
        if len(grid1) >= 1:
            try:
                grid1= grid1[0]
                if grid1.dendogram != None and grid1.dendogram != '':
                    return HttpResponse(grid1.dendogram, content_type='application/xml')
                else:
                    try:     
                        imgData= createDendogram(grid1)
                        return HttpResponse(imgData, content_type='application/xml')
                    except:
                        print "Exception in user code:"
                        print '-'*60
                        traceback.print_exc(file=sys.stdout)
                        print '-'*60
                        return HttpResponse(createXmlErrorResponse('Unknown dendrogram error'), content_type='application/xml')
            except:
                print "Exception in user code:"
                print '-'*60
                traceback.print_exc(file=sys.stdout)
                print '-'*60
                return HttpResponse(createXmlErrorResponse('Unknown error'), content_type='application/xml')
        else:
            return HttpResponse(createXmlErrorResponse('Could not find the grid to generate the dendrogram'), content_type='application/xml')
    else:
        return HttpResponse(createXmlErrorResponse('Invalid request, request is missing argument(s)'), content_type='application/xml')
Esempio n. 2
0
def ajaxDeleteGrid(request):
    if not request.user.is_authenticated():
        return redirect_to(request, '/auth/login/')
    if request.POST.has_key('gridUSID'):
        gridUSID= request.POST['gridUSID']
        grid= None
        try:
            grid= Grid.objects.get(user= request.user, usid= gridUSID)
        except:
            HttpResponse(createXmlErrorResponse('couldn\'t find grid'), content_type='application/xml')
        if grid != None:
            grid.delete()
            return HttpResponse(createXmlSuccessResponse('Grid was deleted'), content_type='application/xml')
    else:
        return HttpResponse(createXmlErrorResponse('Invalid request, request is missing arguments'), content_type='application/xml')
Esempio n. 3
0
def getCreateMyGridPage(request):
    if not request.user.is_authenticated():
        return redirect_to(request, '/auth/login/')
    try:
        tableOnly= False
        if request.REQUEST.has_key('tableOnly'):
            if request.REQUEST['tableOnly'] == 'true':
                tableOnly= True
    
        gridTableTemplate= GridTableData(generateGridTable(None))
        gridTableTemplate.changeRatingsWeights= True
        gridTableTemplate.changeCornAlt= True
        gridTableTemplate.tableId= randomStringGenerator()
             
        context= None 
        #RequestContext(request, {'data': gridTableTemplate })
        if tableOnly:
            template= loader.get_template('gridMng/createMyGridBase.html')
            templateData= CreateMyGridBaseData(gridTableTemplate)
            context= RequestContext(request, {'data': templateData })
            htmlData= template.render(context)
            return HttpResponse(createXmlSuccessResponse(htmlData), content_type='application/xml')
        else:
            templateData= CreateMyGridData(CreateMyGridBaseData(gridTableTemplate))
            context= RequestContext(request, {'data': templateData })
            return render(request, 'gridMng/createMyGrid.html', context_instance=context)

    except:
        #do nothing
        print "Exception in user code:"
        print '-'*60
        traceback.print_exc(file=sys.stdout)
        print '-'*60
        return HttpResponse(createXmlErrorResponse('unknown error'), content_type='application/xml')
Esempio n. 4
0
def ajaxCreateGrid(request):
    if not request.user.is_authenticated():
        return redirect_to(request, '/auth/login/')

    if request.method == 'POST':
        
        #for key in request.REQUEST.keys():
        #    print 'key: ' + key + ' values: ' + request.REQUEST[key]
        #print '------'
        
        gridType= None
        userObj= request.user
        isConcernAlternativeResponseGrid= False
        #check the if the inputs are correct
        if request.POST.has_key('nAlternatives') and request.POST.has_key('nConcerns'): #and request.POST.has_key('gridName')
            if request.POST.has_key('gridType'):
                if request.POST['gridType'] == 'response':
                    return HttpResponse(createXmlErrorResponse("Invalid request, unsupported operation"), content_type='application/xml') 
                elif request.POST['gridType'] == 'user':
                    gridType= Grid.GridType.USER_GRID
                else:
                    return HttpResponse(createXmlErrorResponse("Unsupported grid type"), content_type='application/xml')
            else:
                #if the gridType key is not found assume it is a user grid
                gridType= Grid.GridType.USER_GRID
        else:
            return HttpResponse(createXmlErrorResponse("Invalid request, request is missing argument(s)"), content_type='application/xml')

        #lets validate the data
        try:                
            obj= __validateInputForGrid__(request, isConcernAlternativeResponseGrid)
        except KeyError as error:
            print "Exception in user code:"
            print '-'*60
            traceback.print_exc(file=sys.stdout)
            print '-'*60
            return HttpResponse(createXmlErrorResponse(error.args[0]), content_type='application/xml')
        except ValueError as error:
            print "Exception in user code:"
            print '-'*60
            traceback.print_exc(file=sys.stdout)
            print '-'*60
            return HttpResponse(createXmlErrorResponse(error.args[0]), content_type='application/xml')
        except:
            print "Exception in user code:"
            print '-'*60
            traceback.print_exc(file=sys.stdout)
            print '-'*60
            return HttpResponse(createXmlErrorResponse('Unknown error'), content_type='application/xml')
        nConcerns, nAlternatives, concernValues, alternativeValues, ratioValues= obj
        gridName= None
        if request.POST.has_key('gridName'):
            result= validateName(request.POST['gridName'])
            if  type(result) == StringType:
                gridName= result
            else:
                return result
        try:
            createGrid(userObj, gridType,  gridName, nConcerns, nAlternatives, concernValues, alternativeValues, ratioValues, True)
        except:
            #return render_to_response('gridMng/createGrid.html', {'existingProjectName': request.REQUEST['grid']}, context_instance=RequestContext(request))
            return HttpResponse(createXmlErrorResponse("Could not create grid."), content_type='application/xml')
    #return an empty grid page
    return getCreateMyGridPage(request)
Esempio n. 5
0
def ajaxUpdateGrid(request):
    if not request.user.is_authenticated():
        return redirect_to(request, '/auth/login/')
    
    for key in request.REQUEST.keys():
        print 'key: ' + key + ' values: ' + request.REQUEST[key]
    print '------'
    
    user1= request.user
    gridObj= None
    isConcernAlternativeResponseGrid= False
    
    #lets determine what type of grid we are dealing with here
    if request.POST.has_key('gridType'):
        gridType= request.POST['gridType']
        if gridType == 'session':
            if request.POST.has_key('sessionUSID') and request.POST.has_key('iteration'):
                facilitatorObj= Facilitator.objects.isFacilitator(request.user)
                if facilitatorObj :
                    session= facilitatorObj.session_set.filter(usid= request.POST['sessionUSID'])
                    if len(session) >= 1:
                        session= session[0]
                        sessionGridRelation= session.sessiongrid_set.filter(iteration= request.POST['iteration'])
                        if len(sessionGridRelation) >= 1:
                            if session.state.name == State.CHECK:
                                gridObj= sessionGridRelation[0].grid
                            else:
                                return HttpResponse(createXmlErrorResponse("Grid can\t be changed in the current session state"), content_type='application/xml')
                        else:
                            return HttpResponse(createXmlErrorResponse("Grid was not found"), content_type='application/xml')
                    else:
                        return HttpResponse(createXmlErrorResponse("Session was not found"), content_type='application/xml')
                else:
                    return HttpResponse(createXmlErrorResponse("You are not a facilitator, can't change grid"), content_type='application/xml')
            else:
                return HttpResponse(createXmlErrorResponse("Invalid request, request is missing argument(s)"), content_type='application/xml')
        elif gridType == 'response':
            return HttpResponse(createXmlErrorResponse("Invalid request, unsupported operation"), content_type='application/xml')
        elif gridType == 'user':
            gridObj= Grid.objects.get(user= user1, usid= request.POST['gridUSID'])
    else:
        try:
            gridObj= Grid.objects.get(user= user1, usid= request.POST['gridUSID'])
        except:
            pass

    if request.POST.has_key('gridName'):
        gridCheckNameResult= validateName(request.POST['gridName'])
        if  type(gridCheckNameResult) == StringType:
            gridObj.name= gridCheckNameResult
        else:
            #if the grid name isn't a string than it is an error
            return gridCheckNameResult
    #because django will save stuff to the database even if .save() is not called, we need to validate everything before starting to create the objects that will be used to populate the db
    obj= None
    try:
        obj= __validateInputForGrid__(request, isConcernAlternativeResponseGrid)
    except KeyError as error:
        print "Exception in user code:"
        print '-'*60
        traceback.print_exc(file=sys.stdout)
        print '-'*60
        return HttpResponse(createXmlErrorResponse(error.args[0]), content_type='application/xml')
    except ValueError as error:
        print "Exception in user code:"
        print '-'*60
        traceback.print_exc(file=sys.stdout)
        print '-'*60
        return HttpResponse(createXmlErrorResponse(error.args[0]), content_type='application/xml')
    except:
        print "Exception in user code:"
        print '-'*60
        traceback.print_exc(file=sys.stdout)
        print '-'*60
        return HttpResponse(createXmlErrorResponse('Unknown error'), content_type='application/xml')
    nConcerns, nAlternatives, concernValues, alternativeValues, ratioValues= obj     
    
    #update the grid
    if gridObj != None: 
        try:   
            isGridCreated= updateGrid(gridObj , nConcerns, nAlternatives, concernValues, alternativeValues, ratioValues, isConcernAlternativeResponseGrid)
            if isGridCreated:
                return HttpResponse(createXmlSuccessResponse('Grid was saved', createDateTimeTag(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))), content_type='application/xml')
        except:
            print "Exception in user code:"
            print '-'*60
            traceback.print_exc(file=sys.stdout)
            print '-'*60
            return HttpResponse(createXmlErrorResponse('Unknown error'), content_type='application/xml')
    else:
        return HttpResponse(createXmlErrorResponse("No grid found"), content_type='application/xml')
Esempio n. 6
0
def ajaxGetGrid(request):
    if not request.user.is_authenticated():
        return redirect_to(request, '/auth/login/')
    user1= request.user
    
    #####view mode values########################################################################
    # all: show the concerns/alternatives and ratings/weights                                   #
    # ac: show only alternatives and concerns (only works with write mode read)                 #
    #############################################################################################
    
    #####write mode values#######################################
    # read: can only see the values                             #
    # write: can see and change the values                      #
    #############################################################
    
    #####check table values#######################################
    # true: will call the javascript function isTableSaved()     #
    # false: will not call the javascript function isTableSaved()#
    ##############################################################
    
    checkForTableIsSave= False
    changeRatingsWeights= False
    changeCornAlt= False
    showRatingWhileFalseChangeRatingsWeights= True
    error= None;
    
    #validate the options
    gridUSID = None
    viewMode = None
    writeMode = None
    try:
        gridUSID= request.REQUEST['gridUSID']
        viewMode= request.REQUEST['viewMode']
        writeMode= request.REQUEST['writeMode']
    except KeyError:
        error = 'Invalid arguments.'
    
    #variable check
    try:
        if not gridUSID:
            error= 'name of the grid was not specified'
        if not viewMode:
            viewMode= 'all'
        if not writeMode:
            writeMode= 'write'
            
        if writeMode == 'write':
            changeCornAlt= True
            changeRatingsWeights= True
            if viewMode == 'ac':
                showRatingWhileFalseChangeRatingsWeights= False
        
        if request.REQUEST.has_key('checkTable'):
            if request.REQUEST['checkTable'] == 'true':
                checkForTableIsSave= True
    except:
        print "Exception in user code:"
        print '-'*60
        traceback.print_exc(file=sys.stdout)
        print '-'*60
        error= 'one or more variables were not found'
    
    if not error:
        # create the table for the template
        grids= user1.grid_set
        gridObj= grids.filter(usid= gridUSID) #gridObj is first a list 
        if len(gridObj) > 0:
            gridObj= gridObj[0]
            try:
                templateData= GridTableData(generateGridTable(gridObj))
                templateData.tableId= randomStringGenerator()
                templateData.changeRatingsWeights= changeRatingsWeights
                templateData.changeCornAlt= changeCornAlt
                templateData.showRatingWhileFalseChangeRatingsWeights= showRatingWhileFalseChangeRatingsWeights
                templateData.checkForTableIsSave= checkForTableIsSave
                #dic= __generateGridTable__(gridObj)
                template= loader.get_template('gridMng/gridTable.html')
                context= RequestContext(request, {'data': templateData})
                htmlData= template.render(context)
                return HttpResponse(createXmlSuccessResponse(htmlData), content_type='application/xml')
                #return render_to_response('gridMng/gridTable.html', {'table' : table, 'tableHeader': header, 'hiddenFields': hidden, 'weights':concernWeights, 'showRatings':showRatings, 'readOnly':readOnly, 'checkForTableIsSave':checkForTableIsSave }, context_instance=RequestContext(request))
            except:
                print "Exception in user code:"
                print '-'*60
                traceback.print_exc(file=sys.stdout)
                print '-'*60
                return HttpResponse(createXmlErrorResponse('unknown error'), content_type='application/xml')                
        else:
            return HttpResponse(createXmlErrorResponse('Grid was not found'), content_type='application/xml')
    else:
        return HttpResponse(createXmlErrorResponse(error), content_type='application/xml')
Esempio n. 7
0
def rgtHelp(request, helpMessageId = ''):
    if helpMessageId in HELP_MESSAGES:
        return HttpResponse(createXmlSuccessResponse(HELP_MESSAGES[helpMessageId]), content_type='application/xml')

    return HttpResponse(createXmlErrorResponse('Help topic not found'), content_type='application/xml')