コード例 #1
0
def commitWeekendGrant(request):
    # Allows the CO to grant a weekend to a person who would not be eligible for one

    # Second check - make sure the user is CO
    if re.match("CO", request.user.username) is not None:
        name = request.user.username.split("_")
        cCompany = name[1]
    else:
        return HttpResponseRedirect("/")
    # End of second check

    # date assignment block
    cDate = date.today()
    cNextWeekendBeg = None
    cNextWeekendEnd = None

    if request.method != "POST":
        return HttpResponseRedirect("/")

    alpha = request.POST["alpha"]
    cLocation = request.POST["location"]

    if alpha != "null":
        cMid = Mid.objects.get(alpha=alpha)

        if cMid.rank == "3" or cMid.rank == "4":
            cNextWeekendBeg = date.today() + timedelta(days=(6 - cDate.isoweekday()))
            cNextWeekendEnd = cNextWeekendBeg + timedelta(days=1)
        else:
            cNextWeekendBeg = date.today() + timedelta(days=(5 - cDate.isoweekday()))
            cNextWeekendEnd = cNextWeekendBeg + timedelta(days=2)

        cWeekend = Weekend(
            mid=cMid,
            startDate=cNextWeekendBeg,
            endDate=cNextWeekendEnd,
            status="A",
            location=cLocation,
            contactNumber=cMid.phoneNumber,
        )

        cWeekend.save()

    return HttpResponseRedirect(reverse("weekends:grantWeekends"))
コード例 #2
0
def reqWeekend(request):
    # Requests a weekend

    # Safety feature, makes sure we POST data to this view
    if request.method != "POST":
        return HttpResponseRedirect("/")

    cLocation = request.POST["location"]

    alpha = request.user.username.split("m")
    alpha = alpha[1]
    cMid = Mid.objects.get(alpha=alpha)

    cDate = date.today()
    cNextWeekendBeg = None
    cNextWeekendEnd = None

    if cMid.rank == "3" or cMid.rank == "4":
        cNextWeekendBeg = date.today() + timedelta(days=(6 - cDate.isoweekday()))
        cNextWeekendEnd = cNextWeekendBeg + timedelta(days=1)
    else:
        cNextWeekendBeg = date.today() + timedelta(days=(5 - cDate.isoweekday()))
        cNextWeekendEnd = cNextWeekendBeg + timedelta(days=2)

    cWeekend = Weekend(
        mid=cMid,
        startDate=cNextWeekendBeg,
        endDate=cNextWeekendEnd,
        status="P",
        location=cLocation,
        contactNumber=cMid.phoneNumber,
    )

    cWeekend.save()

    return HttpResponseRedirect(reverse("weekends:weekendIndex"))