def setUp(self):
        """
        create three organizers in database
        :return:
        """
        for o in Organizer.objects.all():
            o.delete()
        for a in Appointment.objects.all():
            a.delete()
        for c in Course.objects.all():
            c.delete()
        if not (Management.objects.all()):
            m = Management(None)
            m.save()
        if not (CourseManagement.objects.all()):
            cm = CourseManagement(my_management=Management.objects.all()[0])
            cm.save()
        if not (UserManagement.objects.all()):
            um = UserManagement(my_management=Management.objects.all()[0])
            um.save()
        gro = Group.objects.create(name='Organizers')
        gro.save()
        Organizer.objects.create_user(name_of_user='******', email='*****@*****.**',
                                      s_number='s2000001')
        Organizer.objects.create_user(name_of_user='******', email='*****@*****.**',
                                      s_number='s2000002')
        Organizer.objects.create_user(name_of_user='******', email='*****@*****.**',
                                      s_number='s2000003')

        cpp = Course.objects.create(name='c++',
                                    my_course_management=CourseManagement.objects.all()[0])
        cpp.save()
        Appointment.objects.create(my_course=cpp, current_count_of_participants=0)
    def setUp(self):
        for t in Tutor.objects.all():
            t.delete()
        if not (Management.objects.all()):
            m = Management(None)
            m.save()
        if not (CourseManagement.objects.all()):
            cm = CourseManagement(my_management=Management.objects.all()[0])
            cm.save()
        if not (UserManagement.objects.all()):
            um = UserManagement(my_management=Management.objects.all()[0])
            um.save()

        gro = Group.objects.create(name='Tutors')
        gro.save()
Exemple #3
0
    def setUp(self):
        for t in Tutor.objects.all():
            t.delete()
        if not (Management.objects.all()):
            m = Management(None)
            m.save()
        if not (CourseManagement.objects.all()):
            cm = CourseManagement(my_management=Management.objects.all()[0])
            cm.save()
        if not (UserManagement.objects.all()):
            um = UserManagement(my_management=Management.objects.all()[0])
            um.save()

        gro = Group.objects.create(name='Tutors')
        gro.save()
    def setUp(self):
        """
        create three organizers in database
        :return:
        """
        for o in Organizer.objects.all():
            o.delete()
        for a in Appointment.objects.all():
            a.delete()
        for c in Course.objects.all():
            c.delete()
        if not (Management.objects.all()):
            m = Management(None)
            m.save()
        if not (CourseManagement.objects.all()):
            cm = CourseManagement(my_management=Management.objects.all()[0])
            cm.save()
        if not (UserManagement.objects.all()):
            um = UserManagement(my_management=Management.objects.all()[0])
            um.save()
        gro = Group.objects.create(name='Organizers')
        gro.save()
        Organizer.objects.create_user(name_of_user='******',
                                      email='*****@*****.**',
                                      s_number='s2000001')
        Organizer.objects.create_user(name_of_user='******',
                                      email='*****@*****.**',
                                      s_number='s2000002')
        Organizer.objects.create_user(name_of_user='******',
                                      email='*****@*****.**',
                                      s_number='s2000003')

        cpp = Course.objects.create(
            name='c++', my_course_management=CourseManagement.objects.all()[0])
        cpp.save()
        Appointment.objects.create(my_course=cpp,
                                   current_count_of_participants=0)
def show_form_login(request):
    """
    This view shows our login-site and initializes our database if necessary.\n
    When the login-site is loaded, this view checks if groups have been stored\n
    within our database and creates them if necessary to ensure full\n
    login-functionality.\n
    \n
    For testing purposes, this view may create some accounts, courses and appointments. \n

    :param request: the incoming request
    :return: rendered login-site
    """

    # logout user if he or she navigates back to this page from an executive-view
    logout(request)

    # define account for exception handling
    account = Executive
    # tutor_account_1 = Tutor
    # tutor_account_2 = Tutor
    app1 = Appointment
    app2 = Appointment

    # initialize our User Groups...
    count_of_organizers = len(Group.objects.filter(name="Organizers"))
    count_of_tutors = len(Group.objects.filter(name="Tutors"))
    if count_of_organizers is 0:
        Group.objects.create(name="Organizers")
    if count_of_tutors is 0:
        Group.objects.create(name="Tutors")

    # initialize management objects...
    if not(Management.objects.all()):
        m = Management(None)
        m.save()
    if not(CourseManagement.objects.all()):
            cm = CourseManagement(my_management=Management.objects.all()[0])
            cm.save()
    if not(UserManagement.objects.all()):
        um = UserManagement(my_management=Management.objects.all()[0])
        um.save()

    # if management has been initialized,
    # create a test Organizer and two Tutors for testing
    else:
        if not Organizer.objects.all():
            # create a unique organizer account with the custom UserManager
            # try:


            account = Organizer.objects.create_user(
                email="*****@*****.**",
                password="******",
                name_of_user="******",
                s_number="s196456"
            )

            # not catching these exceptions anymore, vvvvvvvv
            # if something goes wrong i want to know vvvvvvvv

            # catch exception when UNIQUE constraint fails
            # except IntegrityError as e:
            #     print(e.__cause__)
            # # catch exception when account could not be created
            # except (KeyError, account.DoesNotExist):
            #     print("account exception 2")
            # # if everything went well, proceed to model-object creation
            # else:
            #     print("account success")

        # for test purposes, we create a course with several appointments and assign tutors to it
        if not (Course.objects.all()):
            test_course = Course(name="Django unchained",
                                 my_course_management=CourseManagement.objects.all()[0],
                                 is_visible=True)
            test_course.save()
            app1 = Appointment(my_course=test_course,
                               weekday="Monday",
                               lesson="1.DS",
                               location="here",
                               attendance=15,
                               additional_information="nstr",
                               is_visible=True)
            app1.save()
            app2 = Appointment(my_course=test_course,
                               weekday="Monday",
                               lesson="5.DS",
                               location="over there",
                               attendance=15,
                               additional_information="nstr",
                               is_visible=True)
            app2.save()

        if not Tutor.objects.all() and Appointment.objects.all().count() > 0:
            print("Tutors!")
            # create a unique user account with the custom UserManager


            # try:
            tutor_account_1 = Tutor.objects.create_user(
                email="*****@*****.**",
                password="******",
                name_of_user="******",
                s_number="s198385"
            )

            # not catching these exceptions anymore, vvvvvvvv
            # if something goes wrong i want to know vvvvvvvv


            # # catch exception when UNIQUE constraint fails
            # except IntegrityError as e:
            #     print(e.__cause__)
            # # catch exception when account could not be created
            # except (KeyError, tutor_account_1.DoesNotExist):
            #     print("account exception 2")
            # # if everything went well, proceed to model-object creation
            # else:
            #     print("account success t1")

            # create a unique user account with the custom UserManager
            # try:
            tutor_account_2 = Tutor.objects.create_user(
                email="*****@*****.**",
                password="******",
                name_of_user="******",
                s_number="s195585"
            )
            # # catch exception when UNIQUE constraint fails
            # except IntegrityError as e:
            #     print(e.__cause__)
            # # catch exception when account could not be created
            # except (KeyError, tutor_account_2.DoesNotExist):
            #     print("account exception 2")
            # # if everything went well, proceed to model-object creation
            # else:
            #     print("account success t2")

            # lets assign tutor 1 to both appointments
            if tutor_account_1 and app1:
                app1.add_tutor(tutor_account_1)
                if app2:
                    app2.add_tutor(tutor_account_1)

    form = None
    return render(request, 'cmanagement/login.html', {'form': form})
Exemple #6
0
def show_form_login(request):
    """
    This view shows our login-site and initializes our database if necessary.\n
    When the login-site is loaded, this view checks if groups have been stored\n
    within our database and creates them if necessary to ensure full\n
    login-functionality.\n
    \n
    For testing purposes, this view may create some accounts, courses and appointments. \n

    :param request: the incoming request
    :return: rendered login-site
    """

    # logout user if he or she navigates back to this page from an executive-view
    logout(request)

    # define account for exception handling
    account = Executive
    # tutor_account_1 = Tutor
    # tutor_account_2 = Tutor
    app1 = Appointment
    app2 = Appointment

    # initialize our User Groups...
    count_of_organizers = len(Group.objects.filter(name="Organizers"))
    count_of_tutors = len(Group.objects.filter(name="Tutors"))
    if count_of_organizers is 0:
        Group.objects.create(name="Organizers")
    if count_of_tutors is 0:
        Group.objects.create(name="Tutors")

    # initialize management objects...
    if not (Management.objects.all()):
        m = Management(None)
        m.save()
    if not (CourseManagement.objects.all()):
        cm = CourseManagement(my_management=Management.objects.all()[0])
        cm.save()
    if not (UserManagement.objects.all()):
        um = UserManagement(my_management=Management.objects.all()[0])
        um.save()

    # if management has been initialized,
    # create a test Organizer and two Tutors for testing
    else:
        if not Organizer.objects.all():
            # create a unique organizer account with the custom UserManager
            # try:

            account = Organizer.objects.create_user(
                email="*****@*****.**",
                password="******",
                name_of_user="******",
                s_number="s196456")

            # not catching these exceptions anymore, vvvvvvvv
            # if something goes wrong i want to know vvvvvvvv

            # catch exception when UNIQUE constraint fails
            # except IntegrityError as e:
            #     print(e.__cause__)
            # # catch exception when account could not be created
            # except (KeyError, account.DoesNotExist):
            #     print("account exception 2")
            # # if everything went well, proceed to model-object creation
            # else:
            #     print("account success")

        # for test purposes, we create a course with several appointments and assign tutors to it
        if not (Course.objects.all()):
            test_course = Course(
                name="Django unchained",
                my_course_management=CourseManagement.objects.all()[0],
                is_visible=True)
            test_course.save()
            app1 = Appointment(my_course=test_course,
                               weekday="Monday",
                               lesson="1.DS",
                               location="here",
                               attendance=15,
                               additional_information="nstr",
                               is_visible=True)
            app1.save()
            app2 = Appointment(my_course=test_course,
                               weekday="Monday",
                               lesson="5.DS",
                               location="over there",
                               attendance=15,
                               additional_information="nstr",
                               is_visible=True)
            app2.save()

        if not Tutor.objects.all() and Appointment.objects.all().count() > 0:
            print("Tutors!")
            # create a unique user account with the custom UserManager

            # try:
            tutor_account_1 = Tutor.objects.create_user(
                email="*****@*****.**",
                password="******",
                name_of_user="******",
                s_number="s198385")

            # not catching these exceptions anymore, vvvvvvvv
            # if something goes wrong i want to know vvvvvvvv

            # # catch exception when UNIQUE constraint fails
            # except IntegrityError as e:
            #     print(e.__cause__)
            # # catch exception when account could not be created
            # except (KeyError, tutor_account_1.DoesNotExist):
            #     print("account exception 2")
            # # if everything went well, proceed to model-object creation
            # else:
            #     print("account success t1")

            # create a unique user account with the custom UserManager
            # try:
            tutor_account_2 = Tutor.objects.create_user(
                email="*****@*****.**",
                password="******",
                name_of_user="******",
                s_number="s195585")
            # # catch exception when UNIQUE constraint fails
            # except IntegrityError as e:
            #     print(e.__cause__)
            # # catch exception when account could not be created
            # except (KeyError, tutor_account_2.DoesNotExist):
            #     print("account exception 2")
            # # if everything went well, proceed to model-object creation
            # else:
            #     print("account success t2")

            # lets assign tutor 1 to both appointments
            if tutor_account_1 and app1:
                app1.add_tutor(tutor_account_1)
                if app2:
                    app2.add_tutor(tutor_account_1)

    form = None
    return render(request, 'cmanagement/login.html', {'form': form})