Beispiel #1
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')
Beispiel #2
0
def ajaxSaveSvgPage(request):
    if not request.user.is_authenticated():
        return redirect_to(request, '/auth/login/')
    
    template= loader.get_template('gridMng/saveSvg.html')
    context= RequestContext(request, {})
    htmlData= template.render(context)
    return HttpResponse(createXmlSuccessResponse(htmlData), content_type='application/xml')
Beispiel #3
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')
Beispiel #4
0
def ajaxGetDisplayHelpState(request):
    profile= request.user.get_profile()
    return HttpResponse(createXmlSuccessResponse(`profile.displayHelp`), content_type='application/xml')
Beispiel #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')
Beispiel #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')
Beispiel #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')