Exemplo n.º 1
0
    def save(self):
        """ Save an user like teacher or student"""

        data = self.cleaned_data

        data.pop('password_confirmation')

        is_teacher = data['is_teacher']
        data.pop('is_teacher')

        # Crear el username
        data['username'] = data['first_name'][:1] + data['last_name'].split(
            ' ')[0]
        data['username'] = data['username'].upper()

        while User.objects.filter(username=data['username']).exists():
            data['username'] = data['username'] + str(randrange(1000, 9999))

        user = User.objects.create_user(**data)

        if is_teacher:
            teacher = Teacher(user=user)
            teacher.save()
        else:
            student = Student(user=user)
            student.save()
def addTeacherView(request):
    form = AddTeacherForm()
    if request.method == 'POST':
        form = AddTeacherForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            teacher_pin = form.cleaned_data['teacher_pin']
            designation = form.cleaned_data['designation']
            joined = form.cleaned_data['joined']
            phone = form.cleaned_data['phone']
            instance = Teacher(name=name,
                               techer_id=teacher_pin,
                               designation=designation,
                               joined=joined,
                               phone=phone)
            instance.save()
            form = AddTeacherForm()
            return redirect('/teachers/')

    else:
        form = AddTeacherForm()
    context = {
        'form': form,
    }
    return render(request, 'teachers/add_teacher.html', context)
Exemplo n.º 3
0
def generate_plan(request):
    context = {}
    # here call method to generate possible plan and
    # generate events to the students

    free_times = FreeTime.objects.filter(student=request.user)
    hobbies_user = Hobbie.objects.filter(student=request.user)
    str_hobbies = [x.name for x in hobbies_user]
    activities = Activity.objects.filter(student=request.user)
    possible_classe = []
    for free_time in free_times:
        # available classes at that time with that topic for that user
        ans = Class.objects.filter(start__gte=free_time.start,
                                   end__lte=free_time.end)
        for a in ans:
            if a.topic in str_hobbies:
                possible_classe.append(a)

    if len(possible_classe) == 0:
        Teacher.objects.all().delete()
        for row in generate_random_teachers(30):
            t = Teacher(name=row["name"],
                        email=row["email"],
                        last_name=row["last_name"])
            t.save()
            for p in row["proposals"]:
                nclass = Class(
                    teacher=t,
                    topic=p["topic"],
                    start=p["start"],
                    end=p["end"],
                    slots=p["number_of_slots"],
                )
                nclass.save()

    if len(possible_classe) == 0:
        messages.info(
            request,
            "There are not available classes that match your availability & hobbies.",
        )
        messages.info(
            request,
            "But we propose some interesting ideas, you can change them.",
        )
        possible_classe = random.sample(list(Class.objects.all()), 3)

    Class.objects.filter(student=request.user).delete()
    for p in possible_classe:
        p.student = request.user
        p.save()

    hobbies = ", ".join([h.name for h in hobbies_user])
    context["hobbies"] = hobbies
    context["free_times"] = free_times
    context["activities"] = activities
    context["classes"] = possible_classe

    return redirect("students:index")
Exemplo n.º 4
0
 def setUp(self):
     College.objects.create(name='software college')
     teacher_user = User.objects.create(
         username='******', password='******')
     teacher = Teacher(user=teacher_user, email='*****@*****.**')
     teacher.save()
     Room.objects.create(
         title='', college_id=1, description='',
         password='******', host_email_id='*****@*****.**', is_white_board=1, is_code_editor=1)
Exemplo n.º 5
0
    def handle(self, *args, **options):
        fake = Faker()

        teachers = []
        for _ in range(1000):
            teachers.append(
                Teacher(
                    first_name=fake.first_name(),
                    last_name=fake.last_name(),
                    age=random.randint(10, 100),
                ))
        Teacher.objects.bulk_create(teachers)
Exemplo n.º 6
0
 def handle(self, *args, **options):
     fake = Faker()
     specifications = ['Python', 'Javascript', 'Java', 'C++']
     count = options.get('number_of_teachers')
     for _ in range(count):
         new_teachers.append(Teacher(
             first_name=fake.first_name(),
             last_name=fake.last_name(),
             age=randint(25, 100),
             specification=choice(specifications),
             active_groups=randint(1, 5)
         ))
         Teacher.objects.bulk_create(new_teachers)
Exemplo n.º 7
0
 def handle(self, *args, **kwargs):
     fake = Faker()
     count = kwargs['count']
     teachers = []
     for _ in range(count):
         teachers.append(Teacher(
             first_name=fake.first_name(),
             last_name=fake.last_name(),
             age=random.randint(20, 60),
             teaching_subjects=fake.job(),
         ))
     Teacher.objects.bulk_create(teachers)
     self.stdout.write(f'Created {count} teachers.')
Exemplo n.º 8
0
def add_teachers_to_db(csv_file: str, department: Model) -> None:
    with open(csv_file, 'r', encoding='utf-8') as file:
        reader = csv.DictReader(file)
        for row in reader:
            second_name = row['second_name']
            first_name = row['first_name']
            middle_name = row['middle_name']
            kstu_link = row['kstu_link']
            teacher = Teacher(second_name=second_name,
                              first_name=first_name,
                              middle_name=middle_name,
                              kstu_link=kstu_link,
                              department=department)
            teacher.save()
 def handle(self, *args, **kwargs):
     value = kwargs['value']
     fake = Faker()
     teachers = []
     for _ in range(value):
         teachers.append(
             Teacher(
                 first_name=fake.first_name(),
                 last_name=fake.last_name(),
                 age=fake.pyint(20, 90, 1),
                 number_of_hours=fake.pyint(0, 200, 1),
                 subject=fake.job(),
             ))
     Teacher.objects.bulk_create(teachers)
Exemplo n.º 10
0
 def handle(self, *args, **options):
     fake = Faker()
     count = 100
     if options.get('count'):
         if options.get('count').isdigit():
             count = int(options.get('count'))
     choices = ['High', 'Middle', 'Low']
     insert_data = []
     for _ in range(count):
         insert_data.append(Teacher(first_name=fake.first_name(),
                                    last_name=fake.last_name(),
                                    age=random.randint(22, 60),
                                    education=random.choice(choices),
                                    ))
     Teacher.objects.bulk_create(insert_data)
Exemplo n.º 11
0
 def setUp(self):
     College.objects.create(name='software college')
     teacher_user = User.objects.create_user(username='******',
                                             password='******')
     teacher = Teacher(user=teacher_user, email='*****@*****.**')
     teacher.save()
     Room.objects.create(title='',
                         college_id=1,
                         description='',
                         password='******',
                         host_email_id='*****@*****.**',
                         is_white_board=1,
                         is_code_editor=1)
     RoomCalendar.objects.create(room_id_id=1,
                                 week='1',
                                 day='3',
                                 open_time='17:30',
                                 end_time='18:30')
Exemplo n.º 12
0
    def handle(self, *args, **options):
        fake = Faker()

        course = [
            'PHP', 'Java', 'Python', 'Ruby', 'Rust', 'Swift', 'Linux',
            'Introduction'
        ]
        teacher = []

        for _ in range(100):
            teacher.append(
                Teacher(
                    first_name=fake.first_name(),
                    last_name=fake.last_name(),
                    age=random.randint(25, 45),
                    course=random.choice(course),
                ))

        Teacher.objects.bulk_create(teacher)
Exemplo n.º 13
0
def signup_view(request):
    if not request.user.admin:
        return HttpResponse(
            '<h1>You are not authorised to view this page</h1>')

    if request.method == 'POST':
        form = UserSignupForm(request.POST, request.FILES)
        form2 = StudentExtraForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password1')
            user.save()
            user = authenticate(email=email, password=password)
            role = request.POST.get('role')
            login(request, user)
            if role == 'Teacher':
                user = request.user
                user.is_teacher = True
                user.is_student = False
                user.save()
                teacher = Teacher(user=user)
                teacher.save()
                return redirect('teachers:home')
            else:
                if form2.is_valid():
                    user = request.user
                    user.is_student = True
                    user.save()
                    student = form2.save(user)
                    student.standards.add(student.current_standard)
                    student.save()
                    return redirect('students:home')

    else:
        form = UserSignupForm()
        form2 = StudentExtraForm()

    return render(request, 'admins/home.html', {
        'form': form,
        'studentForm': form2
    })
Exemplo n.º 14
0
def atomic_create_teacher(table, rows):
    """the function of admin atomic_create_teacher"""
    try:
        with transaction.atomic():
            for i in range(1, rows):
                row_values = table.row_values(i)
                teacher_user = User.objects.create_user(username=row_values[0],
                                                        password=row_values[1])
                teacher = Teacher(user=teacher_user, email=row_values[0])
                teacher.save()
    except Exception:
        data = {'code': '0003', 'msg': '导入教师账号失败'}
    else:
        teachers = Teacher.objects.all()
        data_json = json.loads(serializers.serialize("json", teachers))
        return_data = []
        for data in data_json:
            primary_key = data["pk"]
            fields = data["fields"]
            fields["pk"] = primary_key
            del fields["user"]
            return_data.append(fields)
        data = {'code': '0000', 'msg': '导入教师账号成功', 'data': return_data}
    return data
Exemplo n.º 15
0
def make_fake_teacher() -> Teacher:
    return Teacher(first_name=fake.first_name(),
                   last_name=fake.last_name(),
                   stupen=random.choice(stups))
Exemplo n.º 16
0
    droplet_student_limit=1,
)
class1.save()

class2 = Class(
    prefix="potions",
    name="Potions",
    droplet_image="ubuntu-20-04-x64",
    droplet_size="s-1vcpu-1gb",
    droplet_region="sfo3",
    droplet_student_limit=3,
    allow_registration=True,
)
class2.save()

teacher1 = Teacher(user=user1, droplet_limit=50)
teacher1.save()
teacher1.classes.add(class1)

teacher2 = Teacher(user=user2, droplet_limit=50)
teacher2.save()
teacher2.classes.add(class2)

student1 = Student(user=user3)
student1.save()
student1.classes.add(class1, class2)

student2 = Student(user=user4)
student2.save()
student2.classes.add(class1, class2)