Пример #1
0
def ajax_remind(request):
    # if this reminder isn't coming from you, make it a reminder request instead
    if not request.user.is_authenticated():
        return _invite(request)
    # if the exact form is being used, we don't need to parse the times
    elif 'time' in request.POST:
        return _remindexact(request)
    # in all other cases, parse the string to generate a task and datetime
    else:
        try:
            task = request.POST['task']
        except (KeyError):
            response = HttpResponse("Error with form")
            response.status_code = 400
            return response
        p = Parser()
        try:
            result = p.parse(str(task))
        except:
            response = HttpResponse("Parsing error")
            response.status_code = 500
            return response
        
        t = Task(task=result[0], time=result[1], sendnotification=result[2], is_approved=True)
        t.save()
        j = {'id':t.id,
             'task':result[0], 
             'from': 'you', 
             'time': result[1].strftime("%A %d %B, %Y, at %H:%M"),
            }
        response = HttpResponse(json.dumps(j))
        response.status_code = 200
        return response    
Пример #2
0
def _invite(request):
    try:
        task = request.POST['task']
        sfrom = request.POST['from']
    except KeyError:
        return HttpResponseRedirect('/')

    p = Parser()
    result = p.parse(str(task))
    t = Task(task=result[0], time=result[1], sendnotification=result[2],  \
             sentfrom=sfrom, is_approved=False)
    t.save()
    return render_to_response('success.html', {'task':t}) 
Пример #3
0
def _remindexact(request):
    try:
        task = request.POST['task']
        date = request.POST['date']
        time = request.POST['time']
    except (KeyError):
        return HttpResponse("Error with form")
    p = Parser()
    # Pass the exact date and times into an easily parsed string, then parse it
    # @TODO: refactor this to use strftime, much faster.
    result = p.parse("task on " + str(date) + " at " + str(time))
    t = Task(task=str(task), time=result[1], sendnotification=result[2])
    t.save()
    return HttpResponseRedirect('/')
Пример #4
0
def remind(request):
    # if this reminder isn't coming from you, make it a reminder request instead
    if not request.user.is_authenticated():
        return _invite(request)
    # if the exact form is being used, we don't need to parse the times
    elif 'time' in request.POST:
        return _remindexact(request)
    # in all other cases, parse the string to generate a task and datetime
    else:
        try:
            task = request.POST['task']
        except (KeyError):
            return HttpResponse("Error with form")
        p = Parser()
        result = p.parse(str(task))
        t = Task(task=result[0], time=result[1], sendnotification=result[2], is_approved=True)
        t.save()
        return HttpResponseRedirect('/')