Beispiel #1
0
def createPoll(request):
    if not request.POST:
        folders = utils.getDateList()
        if utils.getNowH() >= utils.dinnerH:
            meal = "dinner"
        else:
            meal = "lunch"
        return render_to_response("createpoll.html", {
            "folders": folders,
            "meal": meal
        })
    codeLen = 8
    codeChars = string.ascii_uppercase + string.ascii_lowercase + string.digits
    code = ""
    while True:
        code = "".join(random.choice(codeChars) for _ in range(codeLen))
        if not Poll.objects.filter(code=code):
            break
    owner = utils.escapeHtml(request.POST["owner"])
    if not owner:
        owner = utils.getMaskedIp(request)
    title = utils.escapeHtml(request.POST["title"])
    if not title:
        title = "%s's poll" % owner
    open = "open" in request.POST
    p = Poll(owner=owner,
             title=title,
             open=open,
             parent=utils.getToday(),
             code=code,
             count=0)
    result = {}
    result["0_-1"] = []  # any
    result["9_-1"] = []  # 9 any
    result["22_-1"] = []  # 22 any
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists()
    if utils.getNowH() >= utils.dinnerH:
        dish9 = [int(x.split(".")[0]) for x in dinner9]
        dish22 = [int(x.split(".")[0]) for x in dinner22]
    else:
        dish9 = [int(x.split(".")[0]) for x in lunch9]
        dish22 = [int(x.split(".")[0]) for x in lunch22]
    for d in dish9:
        result["9_" + str(d)] = []
    for d in dish22:
        result["22_" + str(d)] = []
    p.result = json.dumps(result)
    p.save()
    return redirect("/poll/%s/" % code)
Beispiel #2
0
def createPoll(request):
    if not request.POST:
        folders = utils.getDateList()
        if utils.getNowH() >= utils.dinnerH:
            meal = "dinner"
        else:
            meal = "lunch"
        return render_to_response("createpoll.html", {"folders":folders, "meal":meal})
    codeLen = 8
    codeChars = string.ascii_uppercase+string.ascii_lowercase+string.digits
    code = ""
    while True:
        code = "".join(random.choice(codeChars) for _ in range(codeLen))
        if not Poll.objects.filter(code=code):
            break
    owner = utils.escapeHtml(request.POST["owner"])
    if not owner:
        owner = utils.getMaskedIp(request)
    title = utils.escapeHtml(request.POST["title"])
    if not title:
        title = "%s's poll" % owner
    open = "open" in request.POST
    p = Poll(owner=owner, title=title, open=open, parent=utils.getToday(), code=code, count=0)
    result = {}
    result["0_-1"] = []  # any
    result["9_-1"] = []  # 9 any
    result["22_-1"] = []  # 22 any
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists()
    if utils.getNowH() >= utils.dinnerH:
        dish9 = [int(x.split(".")[0]) for x in dinner9]
        dish22 = [int(x.split(".")[0]) for x in dinner22]
    else:
        dish9 = [int(x.split(".")[0]) for x in lunch9]
        dish22 = [int(x.split(".")[0]) for x in lunch22]
    for d in dish9:
        result["9_"+str(d)] = []
    for d in dish22:
        result["22_"+str(d)] = []
    p.result = json.dumps(result)
    p.save()
    return redirect("/poll/%s/" % code)
Beispiel #3
0
def comment(request, date=None):
    res = ""
    if request.POST.has_key("context") and len(request.POST["context"])>0:
        maxLen = Comment._meta.get_field("context").max_length
        author = utils.escapeHtml(request.POST["author"])
        if len(author) == 0:
            author = utils.getMaskedIp(request)
        if author == "admin@mars":
            res = "<dt><font color=\"orange\">%s</font></dt>" % "admin"
        else:
            res = "<dt>%s</dt>" % author
        context = utils.escapeHtml(request.POST["context"].replace("\r\n", "\n"))
        for line in context.split("\n"):
            res += "\r\n<dd>%s</dd>" % line
        res = res[0:maxLen-55]
        context = res
        parent = utils.getToday()
        cmt = Comment(author=author, context=context, parent=parent)
        cmt.save()
        res += utils.getPdate(cmt.date)
    return HttpResponse(res)
Beispiel #4
0
def comment(request, date=None):
    res = ""
    if request.POST.has_key("context") and len(request.POST["context"]) > 0:
        maxLen = Comment._meta.get_field("context").max_length
        author = utils.escapeHtml(request.POST["author"])
        if len(author) == 0:
            author = utils.getMaskedIp(request)
        if author == "admin@mars":
            res = "<dt><font color=\"orange\">%s</font></dt>" % "admin"
        else:
            res = "<dt>%s</dt>" % author
        context = utils.escapeHtml(request.POST["context"].replace(
            "\r\n", "\n"))
        for line in context.split("\n"):
            res += "\r\n<dd>%s</dd>" % line
        res = res[0:maxLen - 55]
        context = res
        parent = utils.getToday()
        cmt = Comment(author=author, context=context, parent=parent)
        cmt.save()
        res += utils.getPdate(cmt.date)
    return HttpResponse(res)
Beispiel #5
0
def vote(request):
    if not request.POST:
        return HttpResponseNotFound(utils.notFound % request.path_info)
    code = utils.escapeHtml(request.POST["code"])
    rs = Poll.objects.filter(code=code)
    if not rs:
        return HttpResponseNotFound(utils.notFound % request.path_info)  # to be tested
    voter = utils.escapeHtml(request.POST["voter"])
    if not voter:
        voter = utils.getMaskedIp(request)
    dish = utils.escapeHtml(request.POST["voteDish"])
    poll = rs[0]
    res = json.loads(poll.result)
    if res[dish]:
        added = ", " + voter
    else:
        added = ": " + voter
    res[dish].append(voter)
    poll.result = json.dumps(res)
    poll.count += 1
    poll.save()
    return HttpResponse(added)
Beispiel #6
0
def vote(request):
    if not request.POST:
        return HttpResponseNotFound(utils.notFound % request.path_info)
    code = utils.escapeHtml(request.POST["code"])
    rs = Poll.objects.filter(code=code)
    if not rs:
        return HttpResponseNotFound(utils.notFound %
                                    request.path_info)  # to be tested
    voter = utils.escapeHtml(request.POST["voter"])
    if not voter:
        voter = utils.getMaskedIp(request)
    dish = utils.escapeHtml(request.POST["voteDish"])
    poll = rs[0]
    res = json.loads(poll.result)
    if res[dish]:
        added = ", " + voter
    else:
        added = ": " + voter
    res[dish].append(voter)
    poll.result = json.dumps(res)
    poll.count += 1
    poll.save()
    return HttpResponse(added)