Ejemplo n.º 1
0
def create_poll(request):
    # Only allowed via post
    if request.method == "POST" and request.POST['question'] and request.POST['answer'] and request.POST['userCode']:
        question = request.POST['question']
        answer = '''
        [{
            "text": "%s"
        }, {
            "text": "%s"
        }]'''

        # Check the answer
        if request.POST['answer'].lower() == 'yes/no':
            answer = answer %  ('yes', 'no')
        else:
            answer = answer % ('true', 'false')

        pd = pollAPI(uid)
        pd.setUserCode(request.POST['userCode'])

        # Create the poll
        newPollJSON = pd.createPollJSON(question, ans=answer)
        return r2r('polldaddy/create.html', {'poll': newPollJSON})
    else:
        return httpRedirect('/pd/')

    return r2r('polldaddy/create.html')
Ejemplo n.º 2
0
def edit_poll(request):
    results = {}

    if 'pid' in request.REQUEST:
        pid = request.POST['pid']
        uid = request.POST['uid']
        uCode = request.POST['userCode']
        results['pid'] = pid
        results['uid'] = uid
        results['userCode'] = uCode
        
        # get the poll belonging to pid
        pd = pollAPI(uid)
        pd.setUserCode(uCode)
        pollJSON = pd.getPollJSON(pid)
        results['poll'] = pollJSON
        return r2r('polldaddy/editpoll.html', results)
    else:
        return httpRedirect('/apitests/pd/')