Exemplo n.º 1
0
def dataupdate(request,command_id):
      
    try:
             
        
        #myjson=json.loads(request.body)
        if request.user.is_authenticated():
            intermediary_id=request.user.email
        else:
            result={}
            result["R00"]={'F1':-6,'F0':"Access denied"}# a code used when an intermediary is not logged in
            status=json.JSONEncoder().encode(result)
            status=json.JSONEncoder().encode(result)
            if command_id =="SA":
                pass# This is an upload from a pedometer. 
            else:
                return HttpResponse(status, mimetype='application/json')   
         
        myjson={'Username':intermediary_id}
       
        obj=RetrieveIntermediary(myjson)
        status=obj.isAssignedBeneficiary()
        status=json.loads(status)
        beneficiary_id=status["Id"]
        #return HttpResponse(status, mimetype='application/json') 
        
    except Exception as e: 
        beneficiary_id=None 
        result={}
        message="iYou don't have a family member assigned to your account"
        #message=e.message
        result["R00"]={'F1':-5,'F0':message}# a code used when a beneficiary doesn't exist
        status=json.JSONEncoder().encode(result)
        status=json.JSONEncoder().encode(result)
        if command_id =="SA":
            pass# This is an upload from a pedometer.
        else:
            return HttpResponse(status, mimetype='application/json')
    
  
    try:
        myjson=json.loads(request.body)
        obj=SavePoints(myjson)
        status=obj.savePointsInDB()
        
        obj=SaveLogs(myjson)
        status=obj.saveLogsInDB()
        #return HttpResponse(status, mimetype='application/json')
    except Exception as e:
        #errorcode={}
        #errorcode["error"]=e.message
        #status=json.JSONEncoder().encode(errorcode)
        #return HttpResponse(status, mimetype='application/json')
        pass
    
          
    
    if command_id =="SW":
        #SW means retrieve save weight
        myjson =json.loads(request.body)
        status=saveWeight(myjson,beneficiary_id)
        return HttpResponse(status, mimetype='application/json')
    
    elif command_id == "SM":
        #result={}
        #SM means save meal
        myjson =json.loads(request.body)
        status=saveMeal(myjson,beneficiary_id) 
        return HttpResponse(status, mimetype='application/json') 

        #result["message"]="The food was recorded sucessfully"
        #return HttpResponse(json.JSONEncoder().encode(result), mimetype='application/json')
        
    elif command_id =="SA":
        
        myjson=json.loads(request.body)
        status=uploadActivity(myjson)
        return HttpResponse(status, content_type='application/json')
    
    elif command_id =="SC":
        
        myjson=json.loads(request.body)
        status=saveComment(myjson,beneficiary_id)
        return HttpResponse(status, content_type='application/json')
         
    
    elif command_id == "SAG":
        myjson=json.loads(request.body)
        status=saveActivityGoal(myjson,beneficiary_id)
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode)        
        return HttpResponse(status, content_type='application/json')
    
    elif command_id == "SMG":
        myjson=json.loads(request.body)
        status=saveMealsGoal(myjson,beneficiary_id)
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode)         
        return HttpResponse(status, content_type='application/json')      
Exemplo n.º 2
0
def dataloader(request,command_id):
    #myjsonpoints={"points":3}
    #myjsonclickscounter={"clickscounter":1}
    
     
    try:
        try:
            
            #intermediary_id=request.session['username']
            if request.user.is_authenticated():
                intermediary_id=request.user.email
            else:
                raise Exception("Access denied")
                
                
        except Exception as e:
            result={}
            result["R00"]={'F1':-6,'F0':e}# a code used when a beneficiary doesn't exist
            status=json.JSONEncoder().encode(result)
            status=json.JSONEncoder().encode(result)
            return HttpResponse(status, mimetype='application/json')
            
        
        #myjson=json.loads(request.body)
        myjson={'Username':intermediary_id}
        obj=RetrieveIntermediary(myjson)
        status=obj.isAssignedBeneficiary()
        status=json.loads(status)
        beneficiary_id=status["Id"]
        #return HttpResponse(status, mimetype='application/json') 
        
    except Exception as e: 
        beneficiary_id=None 
        #result={}
        activity_tuples={"Today":{},"This week":{},"Last week":{},"This month":{},"Last month":{},"Last three months":{}}
        meals_tuples={"Today":{},"This week":{},"Last week":{},"This month":{},"Last month":{},"Last three months":{}}
        weight_tuples={"This month":{},"Last month":{},"Last three months":{}}
        score_tuples={"Today":{},"This week":{},"Last week":{},"This month":{},"Last month":{},"Last three months":{}}
        meals_goal_tuple={"Goal":{}} 
        activity_goal_tuple={"Goal":{}} 

        for day,activity_tuple in activity_tuples.iteritems():
            result={}
            result["R00"]={'F1':-5,'F0':"You don't have a family member assigned to your account"}
            temp=result
            activity_tuples[day]=OrderedDict(sorted(temp.items(), key=lambda t: t[0]))
        
            
        for day,meals_tuple in meals_tuples.iteritems():
            result={}
            myjson={"Day":day}
            result["P00"]={'D1':-5,'D0':"You don't have a family member assigned to your account"}
            temp=result
            meals_tuples[day]=OrderedDict(sorted(temp.items(), key=lambda t: t[0]))
            
        for day,weight_tuple in weight_tuples.iteritems():
            result={}
            myjson={"Day":day}
            result["R00"]={'F1':-5,'F0':"You don't have a family member assigned to your account"}
            temp=result
            weight_tuples[day]=OrderedDict(sorted(temp.items(), key=lambda t: t[0]))        
            
          
        for day,score_tuple in score_tuples.iteritems():
            result={}
            myjson={"Day":day}
            result["R00"]={'D1':-5,'D0':"You don't have any beneficiary assigned to you. You can't be part of this game"}
            temp=result
            score_tuples[day]=OrderedDict(sorted(temp.items(), key=lambda t: t[0]))
            
            
        for goal,meals_goal in meals_goal_tuple.iteritems():
            result={}
            result["Starch"]="None"
            result["Fruits"]="None"
            result["Fat"]="None"
            result["Protein"]="None"
            result["Dairy"]="None" 
            temp=result
            meals_goal_tuple[goal]=OrderedDict(sorted(temp.items(), key=lambda t: t[0]))
        
        for goal,activity_goal in activity_goal_tuple.iteritems():
            result={}
            result["Goal"]={'Steps':-5}
            temp=result
            activity_goal_tuple[goal]=OrderedDict(sorted(temp.items(), key=lambda t: t[0]))
        
        alldata={}
        
        alldata["Activity"]=activity_tuples
        alldata["Meals"]=meals_tuples
        alldata["Weight"]=weight_tuples
        alldata["MealsGoal"]=meals_goal_tuple
        alldata["ActivityGoal"]=activity_goal_tuple
        alldata["ScoreBoard"]=score_tuples
        
        status=(json.JSONEncoder().encode(OrderedDict(sorted(alldata.items(), key=lambda t: t[0]))))

        return HttpResponse(status, mimetype='application/json')
    
    
    

    try:
        myjson=json.loads(request.body)
        obj=SavePoints(myjson,intermediary_id)
        status=obj.savePointsInDB()
        
        obj=SaveLogs(myjson,intermediary_id)
        status=obj.saveLogsInDB()
        #return HttpResponse(status, mimetype='application/json')
    except Exception as e:
        #errorcode={}
        #errorcode["error"]=e.message
        #status=json.JSONEncoder().encode(errorcode)
        #return HttpResponse(status, mimetype='application/json')
        pass
    
    if command_id =="RAD":
        alldata=retriveAllData(beneficiary_id,intermediary_id)
        return HttpResponse(alldata, mimetype='application/json')
    
    if command_id =="RMG":
        #RMG means retrieve meals goal
        goal=retrieveMealGoal(beneficiary_id)
        return HttpResponse(goal, mimetype='application/json')

    elif command_id =="RAG":
        #RAG means retrieve activity goal
        goal=retrieveActivityGoal(beneficiary_id)
        return HttpResponse(goal, mimetype='application/json') 
    
    elif command_id =="PAG":
        #PAG means plot activity graph
        myjson =json.loads(request.body)  
        datapoints=plotActivityGraph(myjson,beneficiary_id)
        return HttpResponse(datapoints, mimetype='application/json')
    
    elif command_id == "PMG":
        #PMG means plot meal graph or chart
        myjson =json.loads(request.body)  
        datapoints=plotMealGraph(myjson,beneficiary_id)
        return HttpResponse(datapoints, mimetype='application/json')        
    
    elif command_id =="RW":
        #RW means retrieve weight
        myjson =json.loads(request.body)  
        weight=retrieveWeight(myjson,beneficiary_id)
        return HttpResponse(weight, mimetype='application/json')
    
    elif command_id =="PWG":
        #WG means plot activity graph
        myjson =json.loads(request.body)  
        datapoints=plotWeightGraph(myjson,beneficiary_id)
        return HttpResponse(datapoints, mimetype='application/json')
    elif command_id=="RSB":
        #Retrieve score board
        #myjson={"Username":intermediary_id,"Day":"Last week"}
        myjson =json.loads(request.body) 
        status=retrieveScoreBoard(myjson,intermediary_id)
        return HttpResponse(status, mimetype='application/json')
    elif command_id=="RSG":
        #result={}
        #Retrieve score gardens
        #myjson={"Day":"Today"}

        #myjson =json.loads(request.body) 
        status=retrieveScoreGardens(myjson,intermediary_id)
        return HttpResponse(status, mimetype='application/json')
        #result["message"]="Got here%s"%intermediary_id
        #return HttpResponse(json.JSONEncoder().encode(result), mimetype='application/json')
    elif command_id=="RST":
        #result={}
        #Retrieve score gardens
        #myjson={"Day":"Today"}

        #myjson =json.loads(request.body) 
        status=retrieveScoreGardens(myjson,intermediary_id)
        return HttpResponse(status, mimetype='application/json')
Exemplo n.º 3
0
def dataupdate(request,command_id):
      
    try:
             
        
        #myjson=json.loads(request.body)
        if request.user.is_authenticated():
            intermediary_id=request.user.username
            intermediary_id=intermediary_id.replace(".","") 
            #if intermediary_id=="ntwakatule":
            #    intermediary_id="*****@*****.**"
        else:
            result={}
            result["R00"]={'F1':-6,'F0':"Access denied"}# a code used when an intermediary is not logged in
            status=json.JSONEncoder().encode(result)
            status=json.JSONEncoder().encode(result)
            if command_id =="SA":
                pass# This is an upload from a pedometer. 
            else:
                return HttpResponse(status, mimetype='application/json')   
         
        myjson={'Username':intermediary_id}
       
        obj=RetrieveIntermediary(myjson)
        status=obj.isAssignedBeneficiary()
        status=json.loads(status)
        beneficiary_id=status["Id"]
        #return HttpResponse(status, mimetype='application/json') 
        
    except Exception as e: 
        beneficiary_id=None 
        result={}
        message="iYou don't have a family member assigned to your account"
        #message=e.message
        result["R00"]={'F1':-5,'F0':message}# a code used when a beneficiary doesn't exist
        status=json.JSONEncoder().encode(result)
        status=json.JSONEncoder().encode(result)
        if command_id =="SA":
            pass# This is an upload from a pedometer.
        else:
            return HttpResponse(status, mimetype='application/json')
    
  
    try:
        myjson=json.loads(request.body)
        obj=SavePoints(myjson)
        status=obj.savePointsInDB()
        
        obj=SaveLogs(myjson)
        status=obj.saveLogsInDB()
        #return HttpResponse(status, mimetype='application/json')
    except Exception as e:
        #errorcode={}
        #errorcode["error"]=e.message
        #status=json.JSONEncoder().encode(errorcode)
        #return HttpResponse(status, mimetype='application/json')
        pass
    
          
    
    if command_id =="SW":
        #SW means retrieve save weight
        myjson =json.loads(request.body)
        status=saveWeight(myjson,beneficiary_id)
        return HttpResponse(status, mimetype='application/json')
    
    elif command_id == "SM":
        #result={}
        #SM means save meal
        myjson =json.loads(request.body)
        status=saveMeal(myjson,beneficiary_id) 
        return HttpResponse(status, mimetype='application/json') 

        #result["message"]="The food was recorded sucessfully"
        #return HttpResponse(json.JSONEncoder().encode(result), mimetype='application/json')
        
    elif command_id =="SA":
        
        myjson=json.loads(request.body)
        status=uploadActivity(myjson)
        return HttpResponse(status, content_type='application/json')
    
    elif command_id =="SC":
        
        myjson=json.loads(request.body)
        status=saveComment(myjson,beneficiary_id,intermediary_id)
        return HttpResponse(status, content_type='application/json')
         
    
    elif command_id == "SAG":
        myjson=json.loads(request.body)
        status=saveActivityGoal(myjson,beneficiary_id)
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode)        
        return HttpResponse(status, content_type='application/json')
    
    elif command_id == "SMG":
        myjson=json.loads(request.body)
        status=saveMealsGoal(myjson,beneficiary_id)
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode)         
        return HttpResponse(status, content_type='application/json')      
    #Queue notification 
    elif command_id == "SN":
        myjson=json.loads(request.body)
        #myjson={"EventObject":"Aquarium","EventUrl":"http://ict4d01.cs.uct.ac.za/","DateDisplayed":"22nd September","ObjectOwner":"8"}

        status=queueNotification(myjson,beneficiary_id);
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode) 
        return HttpResponse(status, content_type='application/json')
    elif command_id == "CTN":
        myjson=json.loads(request.body)
        myjson["BeneficiaryID"]=beneficiary_id
        status=saveTeamName(myjson)
        return HttpResponse(status,content_type='application/json')
    elif command_id  == "CAV":
        myjson=json.loads(request.body)
        myjson["IntermediaryId"]=intermediary_id
        status=saveAvatar(myjson)
        return HttpResponse(status, content_type='application/json')
Exemplo n.º 4
0
def dataupdate(request, command_id):

    try:

        #myjson=json.loads(request.body)
        if request.user.is_authenticated():
            intermediary_id = request.user.email
        else:
            result = {}
            result["R00"] = {
                'F1': -6,
                'F0': "Access denied"
            }  # a code used when an intermediary is not logged in
            status = json.JSONEncoder().encode(result)
            status = json.JSONEncoder().encode(result)
            if command_id == "SA":
                pass  # This is an upload from a pedometer.
            else:
                return HttpResponse(status, mimetype='application/json')

        myjson = {'Username': intermediary_id}

        obj = RetrieveIntermediary(myjson)
        status = obj.isAssignedBeneficiary()
        status = json.loads(status)
        beneficiary_id = status["Id"]
        #return HttpResponse(status, mimetype='application/json')

    except Exception as e:
        beneficiary_id = None
        result = {}
        message = "iYou don't have a family member assigned to your account"
        #message=e.message
        result["R00"] = {
            'F1': -5,
            'F0': message
        }  # a code used when a beneficiary doesn't exist
        status = json.JSONEncoder().encode(result)
        status = json.JSONEncoder().encode(result)
        if command_id == "SA":
            pass  # This is an upload from a pedometer.
        else:
            return HttpResponse(status, mimetype='application/json')

    try:
        myjson = json.loads(request.body)
        obj = SavePoints(myjson)
        status = obj.savePointsInDB()

        obj = SaveLogs(myjson)
        status = obj.saveLogsInDB()
        #return HttpResponse(status, mimetype='application/json')
    except Exception as e:
        #errorcode={}
        #errorcode["error"]=e.message
        #status=json.JSONEncoder().encode(errorcode)
        #return HttpResponse(status, mimetype='application/json')
        pass

    if command_id == "SW":
        #SW means retrieve save weight
        myjson = json.loads(request.body)
        status = saveWeight(myjson, beneficiary_id)
        return HttpResponse(status, mimetype='application/json')

    elif command_id == "SM":
        #result={}
        #SM means save meal
        myjson = json.loads(request.body)
        status = saveMeal(myjson, beneficiary_id)
        return HttpResponse(status, mimetype='application/json')

        #result["message"]="The food was recorded sucessfully"
        #return HttpResponse(json.JSONEncoder().encode(result), mimetype='application/json')

    elif command_id == "SA":

        myjson = json.loads(request.body)
        status = uploadActivity(myjson)
        return HttpResponse(status, content_type='application/json')

    elif command_id == "SC":

        myjson = json.loads(request.body)
        status = saveComment(myjson, beneficiary_id)
        return HttpResponse(status, content_type='application/json')

    elif command_id == "SAG":
        myjson = json.loads(request.body)
        status = saveActivityGoal(myjson, beneficiary_id)
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode)
        return HttpResponse(status, content_type='application/json')

    elif command_id == "SMG":
        myjson = json.loads(request.body)
        status = saveMealsGoal(myjson, beneficiary_id)
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode)
        return HttpResponse(status, content_type='application/json')
Exemplo n.º 5
0
def dataloader(request, command_id):
    #myjsonpoints={"points":3}
    #myjsonclickscounter={"clickscounter":1}

    try:
        try:

            #intermediary_id=request.session['username']
            if request.user.is_authenticated():
                intermediary_id = request.user.email
            else:
                raise Exception("Access denied")

        except Exception as e:
            result = {}
            result["R00"] = {
                'F1': -6,
                'F0': e
            }  # a code used when a beneficiary doesn't exist
            status = json.JSONEncoder().encode(result)
            status = json.JSONEncoder().encode(result)
            return HttpResponse(status, mimetype='application/json')

        #myjson=json.loads(request.body)
        myjson = {'Username': intermediary_id}
        obj = RetrieveIntermediary(myjson)
        status = obj.isAssignedBeneficiary()
        status = json.loads(status)
        beneficiary_id = status["Id"]
        #return HttpResponse(status, mimetype='application/json')

    except Exception as e:
        beneficiary_id = None
        #result={}
        activity_tuples = {
            "Today": {},
            "This week": {},
            "Last week": {},
            "This month": {},
            "Last month": {},
            "Last three months": {}
        }
        meals_tuples = {
            "Today": {},
            "This week": {},
            "Last week": {},
            "This month": {},
            "Last month": {},
            "Last three months": {}
        }
        weight_tuples = {
            "This month": {},
            "Last month": {},
            "Last three months": {}
        }
        score_tuples = {
            "Today": {},
            "This week": {},
            "Last week": {},
            "This month": {},
            "Last month": {},
            "Last three months": {}
        }
        meals_goal_tuple = {"Goal": {}}
        activity_goal_tuple = {"Goal": {}}

        for day, activity_tuple in activity_tuples.iteritems():
            result = {}
            result["R00"] = {
                'F1': -5,
                'F0': "You don't have a family member assigned to your account"
            }
            temp = result
            activity_tuples[day] = OrderedDict(
                sorted(temp.items(), key=lambda t: t[0]))

        for day, meals_tuple in meals_tuples.iteritems():
            result = {}
            myjson = {"Day": day}
            result["P00"] = {
                'D1': -5,
                'D0': "You don't have a family member assigned to your account"
            }
            temp = result
            meals_tuples[day] = OrderedDict(
                sorted(temp.items(), key=lambda t: t[0]))

        for day, weight_tuple in weight_tuples.iteritems():
            result = {}
            myjson = {"Day": day}
            result["R00"] = {
                'F1': -5,
                'F0': "You don't have a family member assigned to your account"
            }
            temp = result
            weight_tuples[day] = OrderedDict(
                sorted(temp.items(), key=lambda t: t[0]))

        for day, score_tuple in score_tuples.iteritems():
            result = {}
            myjson = {"Day": day}
            result["R00"] = {
                'D1':
                -5,
                'D0':
                "You don't have any beneficiary assigned to you. You can't be part of this game"
            }
            temp = result
            score_tuples[day] = OrderedDict(
                sorted(temp.items(), key=lambda t: t[0]))

        for goal, meals_goal in meals_goal_tuple.iteritems():
            result = {}
            result["Starch"] = "None"
            result["Fruits"] = "None"
            result["Fat"] = "None"
            result["Protein"] = "None"
            result["Dairy"] = "None"
            temp = result
            meals_goal_tuple[goal] = OrderedDict(
                sorted(temp.items(), key=lambda t: t[0]))

        for goal, activity_goal in activity_goal_tuple.iteritems():
            result = {}
            result["Goal"] = {'Steps': -5}
            temp = result
            activity_goal_tuple[goal] = OrderedDict(
                sorted(temp.items(), key=lambda t: t[0]))

        alldata = {}

        alldata["Activity"] = activity_tuples
        alldata["Meals"] = meals_tuples
        alldata["Weight"] = weight_tuples
        alldata["MealsGoal"] = meals_goal_tuple
        alldata["ActivityGoal"] = activity_goal_tuple
        alldata["ScoreBoard"] = score_tuples

        status = (json.JSONEncoder().encode(
            OrderedDict(sorted(alldata.items(), key=lambda t: t[0]))))

        return HttpResponse(status, mimetype='application/json')

    try:
        myjson = json.loads(request.body)
        obj = SavePoints(myjson, intermediary_id)
        status = obj.savePointsInDB()

        obj = SaveLogs(myjson, intermediary_id)
        status = obj.saveLogsInDB()
        #return HttpResponse(status, mimetype='application/json')
    except Exception as e:
        #errorcode={}
        #errorcode["error"]=e.message
        #status=json.JSONEncoder().encode(errorcode)
        #return HttpResponse(status, mimetype='application/json')
        pass

    if command_id == "RAD":
        alldata = retriveAllData(beneficiary_id, intermediary_id)
        return HttpResponse(alldata, mimetype='application/json')

    if command_id == "RMG":
        #RMG means retrieve meals goal
        goal = retrieveMealGoal(beneficiary_id)
        return HttpResponse(goal, mimetype='application/json')

    elif command_id == "RAG":
        #RAG means retrieve activity goal
        goal = retrieveActivityGoal(beneficiary_id)
        return HttpResponse(goal, mimetype='application/json')

    elif command_id == "PAG":
        #PAG means plot activity graph
        myjson = json.loads(request.body)
        datapoints = plotActivityGraph(myjson, beneficiary_id)
        return HttpResponse(datapoints, mimetype='application/json')

    elif command_id == "PMG":
        #PMG means plot meal graph or chart
        myjson = json.loads(request.body)
        datapoints = plotMealGraph(myjson, beneficiary_id)
        return HttpResponse(datapoints, mimetype='application/json')

    elif command_id == "RW":
        #RW means retrieve weight
        myjson = json.loads(request.body)
        weight = retrieveWeight(myjson, beneficiary_id)
        return HttpResponse(weight, mimetype='application/json')

    elif command_id == "PWG":
        #WG means plot activity graph
        myjson = json.loads(request.body)
        datapoints = plotWeightGraph(myjson, beneficiary_id)
        return HttpResponse(datapoints, mimetype='application/json')
    elif command_id == "RSB":
        #Retrieve score board
        #myjson={"Username":intermediary_id,"Day":"Last week"}
        myjson = json.loads(request.body)
        status = retrieveScoreBoard(myjson, intermediary_id)
        return HttpResponse(status, mimetype='application/json')
    elif command_id == "RSG":
        #result={}
        #Retrieve score gardens
        #myjson={"Day":"Today"}

        #myjson =json.loads(request.body)
        status = retrieveScoreGardens(myjson, intermediary_id)
        return HttpResponse(status, mimetype='application/json')
        #result["message"]="Got here%s"%intermediary_id
        #return HttpResponse(json.JSONEncoder().encode(result), mimetype='application/json')
    elif command_id == "RST":
        #result={}
        #Retrieve score gardens
        #myjson={"Day":"Today"}

        #myjson =json.loads(request.body)
        status = retrieveScoreGardens(myjson, intermediary_id)
        return HttpResponse(status, mimetype='application/json')
Exemplo n.º 6
0
def dataupdate(request, command_id):

    try:

        #myjson=json.loads(request.body)
        if request.user.is_authenticated():
            intermediary_id = request.user.username
            intermediary_id = intermediary_id.replace(".", "")
            #if intermediary_id=="ntwakatule":
            #    intermediary_id="*****@*****.**"
        else:
            result = {}
            result["R00"] = {
                'F1': -6,
                'F0': "Access denied"
            }  # a code used when an intermediary is not logged in
            status = json.JSONEncoder().encode(result)
            status = json.JSONEncoder().encode(result)
            if command_id == "SA":
                pass  # This is an upload from a pedometer.
            else:
                return HttpResponse(status, mimetype='application/json')

        myjson = {'Username': intermediary_id}

        obj = RetrieveIntermediary(myjson)
        status = obj.isAssignedBeneficiary()
        status = json.loads(status)
        beneficiary_id = status["Id"]
        #return HttpResponse(status, mimetype='application/json')

    except Exception as e:
        beneficiary_id = None
        result = {}
        message = "iYou don't have a family member assigned to your account"
        #message=e.message
        result["R00"] = {
            'F1': -5,
            'F0': message
        }  # a code used when a beneficiary doesn't exist
        status = json.JSONEncoder().encode(result)
        status = json.JSONEncoder().encode(result)
        if command_id == "SA":
            pass  # This is an upload from a pedometer.
        else:
            return HttpResponse(status, mimetype='application/json')

    try:
        myjson = json.loads(request.body)
        obj = SavePoints(myjson)
        status = obj.savePointsInDB()

        obj = SaveLogs(myjson)
        status = obj.saveLogsInDB()
        #return HttpResponse(status, mimetype='application/json')
    except Exception as e:
        #errorcode={}
        #errorcode["error"]=e.message
        #status=json.JSONEncoder().encode(errorcode)
        #return HttpResponse(status, mimetype='application/json')
        pass

    if command_id == "SW":
        #SW means retrieve save weight
        myjson = json.loads(request.body)
        status = saveWeight(myjson, beneficiary_id)
        return HttpResponse(status, mimetype='application/json')

    elif command_id == "SM":
        #result={}
        #SM means save meal
        myjson = json.loads(request.body)
        status = saveMeal(myjson, beneficiary_id)
        return HttpResponse(status, mimetype='application/json')

        #result["message"]="The food was recorded sucessfully"
        #return HttpResponse(json.JSONEncoder().encode(result), mimetype='application/json')

    elif command_id == "SA":

        myjson = json.loads(request.body)
        status = uploadActivity(myjson)
        return HttpResponse(status, content_type='application/json')

    elif command_id == "SC":

        myjson = json.loads(request.body)
        status = saveComment(myjson, beneficiary_id, intermediary_id)
        return HttpResponse(status, content_type='application/json')

    elif command_id == "SAG":
        myjson = json.loads(request.body)
        status = saveActivityGoal(myjson, beneficiary_id)
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode)
        return HttpResponse(status, content_type='application/json')

    elif command_id == "SMG":
        myjson = json.loads(request.body)
        status = saveMealsGoal(myjson, beneficiary_id)
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode)
        return HttpResponse(status, content_type='application/json')
    #Queue notification
    elif command_id == "SN":
        myjson = json.loads(request.body)
        #myjson={"EventObject":"Aquarium","EventUrl":"http://ict4d01.cs.uct.ac.za/","DateDisplayed":"22nd September","ObjectOwner":"8"}

        status = queueNotification(myjson, beneficiary_id)
        #errorcode={}
        #errorcode["message"]="gfgfgfg"
        #status=json.JSONEncoder().encode(errorcode)
        return HttpResponse(status, content_type='application/json')
    elif command_id == "CTN":
        myjson = json.loads(request.body)
        myjson["BeneficiaryID"] = beneficiary_id
        status = saveTeamName(myjson)
        return HttpResponse(status, content_type='application/json')
    elif command_id == "CAV":
        myjson = json.loads(request.body)
        myjson["IntermediaryId"] = intermediary_id
        status = saveAvatar(myjson)
        return HttpResponse(status, content_type='application/json')