Exemple #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)
Exemple #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)
Exemple #3
0
def onDate(request, date=None, page=None):
    if date == None:
        date = utils.getToday()
    if page and page != "lunch" and page != "dinner":
        return HttpResponseNotFound(utils.notFound % request.path_info)
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists(date)
    lunch9cnt, lunch22cnt, dinner9cnt, dinner22cnt = {}, {}, {}, {}
    folders = utils.getDateList()
    dateObj = utils.getDateObj(date)
    useSp = dateObj > utils.dateSp  # sharepoint
    if not useSp:
        for file in lunch9:
            lunch9cnt[file] = getPicCnt(file)
        for file in lunch22:
            lunch22cnt[file] = getPicCnt(file)
        for file in dinner9:
            dinner9cnt[file] = getPicCnt(file)
        for file in dinner22:
            dinner22cnt[file] = getPicCnt(file)
    showDinner = (dinner9cnt
                  or dinner22cnt) and utils.getNowH() >= utils.dinnerH
    if page == "lunch":
        showDinner = False
    elif page == "dinner":
        showDinner = True
    cmts = []
    allcmts = Comment.objects.order_by("-id")[0:50]
    groupSize = 10
    group = []
    for i, x in enumerate(allcmts):
        if i % groupSize == 0:
            if i > 0:
                cmts.append(group)
            group = []
        group.append(x.context + utils.getPdate(x.date))
    if group:
        cmts.append(group)
    if not useSp:
        return render_to_response(
            "index.html", {
                "folders": folders,
                "date": date,
                "lunch9cnt": lunch9cnt,
                "lunch22cnt": lunch22cnt,
                "dinner9cnt": dinner9cnt,
                "dinner22cnt": dinner22cnt,
                "cmts": cmts,
                "showDinner": showDinner
            })
    isToday = date == utils.getToday()
    lunch9info, lunch22info, dinner9info, dinner22info = {}, {}, {}, {}
    for file in lunch9:
        lunch9info[file] = getDishInfo(file, date)
    for file in lunch22:
        lunch22info[file] = getDishInfo(file, date)
    for file in dinner9:
        dinner9info[file] = getDishInfo(file, date)
    for file in dinner22:
        dinner22info[file] = getDishInfo(file, date)
    meal = ""
    if isToday and (lunch9info or lunch22info or dinner9info or dinner22info):
        if utils.getNowH() >= utils.dinnerH:
            meal = "dinner"
        else:
            meal = "lunch"
    showDinner = (dinner9info
                  or dinner22info) and utils.getNowH() >= utils.dinnerH
    if page == "lunch":
        showDinner = False
    elif page == "dinner":
        showDinner = True
    polls = getOpenPolls()
    dateTtl = dateObj.strftime("%m.%d")
    return render_to_response(
        "indexSp.html", {
            "folders": folders,
            "date": date,
            "meal": meal,
            "lunch9info": lunch9info,
            "lunch22info": lunch22info,
            "dinner9info": dinner9info,
            "dinner22info": dinner22info,
            "cmts": cmts,
            "showDinner": showDinner,
            "polls": polls,
            "dateTtl": dateTtl
        })
Exemple #4
0
def onDate(request, date=None, page=None):
    if date == None:
        date = utils.getToday()
    if page and page!="lunch" and page!="dinner":
        return HttpResponseNotFound(utils.notFound % request.path_info)
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists(date)
    lunch9cnt, lunch22cnt, dinner9cnt, dinner22cnt = {}, {}, {}, {}
    folders = utils.getDateList()
    dateObj = utils.getDateObj(date)
    useSp = dateObj > utils.dateSp  # sharepoint
    if not useSp:
        for file in lunch9:
            lunch9cnt[file] = getPicCnt(file)
        for file in lunch22:
            lunch22cnt[file] = getPicCnt(file)
        for file in dinner9:
            dinner9cnt[file] = getPicCnt(file)
        for file in dinner22:
            dinner22cnt[file] = getPicCnt(file)
    showDinner = (dinner9cnt or dinner22cnt) and utils.getNowH() >= utils.dinnerH
    if page=="lunch":
        showDinner = False
    elif page=="dinner":
        showDinner = True
    cmts = []
    allcmts = Comment.objects.order_by("-id")[0:50]
    groupSize = 10
    group = []
    for i, x in enumerate(allcmts):
        if i%groupSize == 0:
            if i>0:
                cmts.append(group)
            group = []
        group.append(x.context + utils.getPdate(x.date))
    if group:
        cmts.append(group)
    if not useSp:
        return render_to_response("index.html", {"folders":folders, "date":date, 
                                             "lunch9cnt":lunch9cnt, "lunch22cnt":lunch22cnt, 
                                             "dinner9cnt":dinner9cnt, "dinner22cnt":dinner22cnt,
                                             "cmts":cmts, "showDinner":showDinner})
    isToday = date==utils.getToday()
    lunch9info, lunch22info, dinner9info, dinner22info = {}, {}, {}, {}
    for file in lunch9:
        lunch9info[file] = getDishInfo(file, date)
    for file in lunch22:
        lunch22info[file] = getDishInfo(file, date)
    for file in dinner9:
        dinner9info[file] = getDishInfo(file, date)
    for file in dinner22:
        dinner22info[file] = getDishInfo(file, date)
    meal = ""
    if isToday and (lunch9info or lunch22info or dinner9info or dinner22info):
        if utils.getNowH() >= utils.dinnerH:
            meal = "dinner"
        else:
            meal = "lunch"
    showDinner = (dinner9info or dinner22info) and utils.getNowH() >= utils.dinnerH
    if page=="lunch":
        showDinner = False
    elif page=="dinner":
        showDinner = True
    polls = getOpenPolls()
    dateTtl = dateObj.strftime("%m.%d")
    return render_to_response("indexSp.html", {"folders":folders, "date":date, "meal":meal,
                                             "lunch9info":lunch9info, "lunch22info":lunch22info, 
                                             "dinner9info":dinner9info, "dinner22info":dinner22info, 
                                             "cmts":cmts, "showDinner":showDinner,
                                             "polls":polls, "dateTtl":dateTtl})