Exemplo n.º 1
0
def testing(req):
    checkadmin(req)
    now = datetime.datetime.now()
    current_slot_id = Slot.objects.filter(start_hour=now.hour,
                                          start_minute__lt=now.minute,
                                          end_minute__gt=now.minute)

    current_slot_id = -1 if not current_slot_id else current_slot_id[0].id

    current_bookings = Booking.objects.filter(
        slot_id=current_slot_id,
        booking_date=datetime.date.today()).select_related()
    current_mids = list([-1]) if not current_bookings else [
        current_booking.account.board.mid
        for current_booking in current_bookings
    ]

    boards = Board.objects.filter(online=1)
    allotment_mode = "Random" if Board.can_do_random_allotment(
    ) else "Workshop"
    return render(req, 'admin/testexp.html', {
        "boards": boards,
        "allotment_mode": allotment_mode,
        "mids": current_mids
    })
Exemplo n.º 2
0
def index(req):
    checkadmin(req)
    boards = Board.objects.order_by('online').all()
    allotment_mode = "Random" if Board.can_do_random_allotment(
    ) else "Workshop"
    return render(req, 'admin/index.html', {
        "boards": boards,
        "allotment_mode": allotment_mode
    })
Exemplo n.º 3
0
def create(req):
    error = []

    name        = req.POST.get("name").strip()
    email       = req.POST.get("email").strip()
    username    = req.POST.get("username").strip()
    roll_number = req.POST.get("roll_number").strip()
    password    = req.POST.get("password")
    confirm     = req.POST.get("confirm")
    institute   = req.POST.get("institute").strip()
    department  = req.POST.get("department").strip()
    position    = req.POST.get("position").strip()

    error = error + (["Please enter a name."] if name == "" else [])
    error = error + (["Please enter an email."] if email == "" else [])
    error = error + (["Please enter an username."] if username == "" else [])
    error = error + (["Please enter a roll_number."] if roll_number == "" else [])
    
    error = error + (["Please enter a password."] if password == "" else [])
    error = error + (["Password confirmation does not match."] if password != confirm else [])

    error = error + (["Please enter an institute."] if institute == "" else [])
    error = error + (["Please enter a department."] if department == "" else [])
    error = error + (["Please enter a position."] if position == "" else [])

    try:
        validate_email(email)
    except ValidationError:
        error = error + ["Please enter a valid email."]

    email_exists = Account.objects.filter(email=email).count()
    error = error + (["Account with given email already exists."] if email_exists > 0 else [])

    username_exists = Account.objects.filter(username=username).count()
    error = error + (["Account with given username already exists."] if username_exists > 0 else [])

    if error != []:
        messages.add_message(req, messages.ERROR, "<br>".join(error))
        return redirect(index)

    # try:
    account = Account(
                name=name,
                username=username,
                email=email,
                board_id=Board.allot_board()
            )
    account.set_password(password)
    account.save()
    account.send_confirmation()
    print "Done"
    messages.add_message(req, messages.SUCCESS, "You have been registered successfully. Please check your email for confirmation.")
    return redirect(index)
Exemplo n.º 4
0
def toggle_allotment_mode(req):
    checkadmin(req)
    Board.toggle_random_allotment()
    return redirect(index)
Exemplo n.º 5
0
def create(req):
    """ Creates a new user account.
        Generate user alerts if:
            Any of the fields is not entered.
            Entered email-id is invalid.
            Entered username or email-id is existing.
            Alloted board id is -1, because of no boards being available online.
            If the user credentials cross all checks and hence a successful account is created.
        Input: s:request object.
        Output: HttpResponseRedirect object returned by redirect() function.
    """
    error = []

    name = req.POST.get("name").strip()
    email = req.POST.get("email").strip()
    username = req.POST.get("username").strip()
    roll_number = req.POST.get("roll_number").strip()
    password = req.POST.get("password")
    confirm = req.POST.get("confirm")
    institute = req.POST.get("institute").strip()
    department = req.POST.get("department").strip()
    position = req.POST.get("position").strip()

    error = error + (["Please enter a name."] if name == "" else [])
    error = error + (["Please enter an email."] if email == "" else [])
    error = error + (["Please enter an username."] if username == "" else [])
    error = error + (["Please enter a roll_number."]
                     if roll_number == "" else [])

    error = error + (["Please enter a password."] if password == "" else [])
    error = error + (["Password confirmation does not match."]
                     if password != confirm else [])

    error = error + (["Please enter an institute."] if institute == "" else [])
    error = error + (["Please enter a department."]
                     if department == "" else [])
    error = error + (["Please enter a position."] if position == "" else [])

    try:
        validate_email(email)
    except ValidationError:
        error = error + ["Please enter a valid email."]

    email_exists = Account.objects.filter(email=email).count()
    error = error + (["Account with given email already exists."]
                     if email_exists > 0 else [])

    username_exists = Account.objects.filter(username=username).count()
    error = error + (["Account with given username already exists."]
                     if username_exists > 0 else [])

    if error != []:
        messages.add_message(req, messages.ERROR, "<br>".join(error))
        return redirect(index)

    # try:

    # check if a board could be allocated
    allocated_board_id = Board.allot_board()
    if allocated_board_id == -1:
        messages.add_message(
            req, messages.ERROR,
            "Sorry!! No boards online at this moment. Try again in some time.")
        return redirect(index)

    account = Account(name=name,
                      username=username,
                      email=email,
                      board_id=allocated_board_id,
                      last_login=datetime.now().strftime("%Y-%m-%d %H:%M"))
    account.set_password(password)
    account.save()
    account.send_confirmation()
    print "Done"
    messages.add_message(
        req, messages.SUCCESS,
        "You have been registered successfully. Please check your email for confirmation."
    )
    return redirect(index)