Example #1
0
    def mutate(self, info, input=None):
        print("ARTIST", input.artist.id)

        try:
            artist = Artist.objects.get(pk=input.artist.id)
        except Artist.DoesNotExist:
            return CreateStudent(ok=False, student=None)

        # The Student model requires an Artist AND a user
        # This looks at least surprising
        # TODO : delete user from Artist

        try:
            promotion = Promotion.objects.get(pk=input.promotion.id)
        except Promotion.DoesNotExist:
            return CreateStudent(ok=False, student=None)

        print("promo", promotion)

        student = Student(
            user=artist.user,
            promotion=promotion,
            number=input.number,
            artist=artist,
            graduate=input.graduate,
        )
        ok = True
        student.save()
        return CreateStudent(student=student, ok=ok)
Example #2
0
def preferences(request, course):
    course_obj = get_object_or_404(Course, slug=course)
    try:
        s = request.user.student_set.get()
    except Student.DoesNotExist:
        s = Student(user = request.user, email = False)
        s.save()
    c = create_context('preferences', course_obj)
    c['stuff_email'] = s.email
    return render(request, 'school/preferences.html', c)
Example #3
0
    def handle(self, *args, **options):
        with open(settings.FILE, encoding='utf-8') as file:
            reader = json.load(file)

            for item in reader:
                if item['model'] == 'school.teacher':
                    new_teacher = Teacher(name = item['fields']['name'],
                                          subject = item['fields']['subject'])
                    new_teacher.save()
                elif item['model'] == 'school.student':
                    new_student = Student(name = item['fields']['name'],
                                          teacher = Teacher.objects.all().get(id=item['fields']['teacher']),
                                          group = item['fields']['group'])
                    new_student.save()
Example #4
0
def index(request):

    logging.info('test of long key chain')
   
    season = Season.objects.all().get()
    if season is None:
        season = Season()
        season.name = '2011/12'
        season.save()
    
    logging.info('season=%s'%season)

    category = Category.objects.all().get()
    if category is None:
        category = Category(parent = season)
        category.name = 'cat1'
        category.save()
    
    logging.info('category=%s'%category)

    course = Course.objects.all().get()
    if course is None:
        course = Course(parent = category)
        course.code = 'X1'
        course.save()
   
    logging.info('course=%s'%course) 

    group = Group.objects.all().get()
    if group is None:
        group = Group(parent = course)
        group.name = 'gr1'
        group.save()

    logging.info('group=%s'%group)

    student = Student.objects.all().get()
    if student is None:
        student = Student(parent = group)
        student.name ='st1'
        student.save()

    logging.info('student=%s'%student)


    st = Student.objects.all().ancestor(course).get()

    logging.info('ancestor test:%s'%st)

    return render_to_response('school/index.html', RequestContext(request))
Example #5
0
    def _populate(self):
        fake = Faker()

        for _ in range(random.randint(10, 30)):
            school = School(name=f'{fake.last_name()[:10]}\'s school',
                            students_max_number=random.randint(10, 200),
                            established_in=random.randint(1900, 2020),
                            location=fake.street_address())
            school.save()
            for __ in range(random.randint(5, school.students_max_number)):
                student = Student(first_name=fake.first_name()[:20],
                                  last_name=fake.last_name()[:20],
                                  school=school,
                                  date_of_birth=fake.date_of_birth(),
                                  nationality=fake.country()[:20])
                student.save()
Example #6
0
    def handle(self, *args, **options):
        with open('school.json', encoding='utf-8') as jsonfile:
            school = json.load(jsonfile)
            for line in school:
                if line['model'] == "school.teacher":
                    teacher = Teacher(name=line['fields']['name'],
                                      subject=line['fields']['subject'],
                                      id=line['pk'])
                    teacher.save()
                elif line['model'] == "school.student":
                    student = Student(
                        name=line['fields']['name'],
                        group=line['fields']['group'],
                        id=line['pk'],
                    )
                    student.teacher.add(line['fields']['teacher'])

                    student.save()
Example #7
0
    def handle(self, *args, **options):
        with open(os.path.join(settings.BASE_DIR, 'school.json'),
                  'r') as json_file:
            data = json.load(json_file)

            for fields in data:
                model = fields['model']
                pk = fields['pk']
                field = fields['fields']

                if (model == 'school.teacher'):
                    name = field['name']
                    subject = field['subject']
                    Teacher.objects.create(id=pk, name=name, subject=subject)

                elif (model == 'school.student'):
                    name = field['name']
                    teacher = field['teacher']
                    group = field['group']
                    st = Student(id=pk, name=name, group=group)
                    st.save()
                    st.teacher.add(teacher)
Example #8
0
    def test_save_student_has_registration_order(self):
        # student requires at least first name, last name, birth date and classroom 
        s = Student()
        self.assertRaises(IntegrityError, s.save)
        s = Student(first_name='Harry',
                    last_name='Potter',
                    birth_date=datetime(2003,5,1),
                    class_room=self.classroom,
                   )
        s.save()
        # student can be saved
        self.assertTrue(s.id)
        # student registration order was generated
        self.assertEquals(1, s.registration_order)
        self.assertEquals(datetime.today().date(), s.registration_date.date())

        s = Student(first_name='Hermione',
                    last_name='Granger',
                    birth_date=datetime(2003,5,1),
                    class_room=self.classroom,
                   )
        s.save()
        self.assertEquals(2, s.registration_order)
        self.assertEquals(datetime.today().date(), s.registration_date.date())
Example #9
0
def add_student(request):
	info=request.GET['info']
	sc_id=request.GET['sc_id']
	pro_id=request.GET['pro_id']
	student=request.GET['student']
	url="student?sc_id="+sc_id+"&pro_id="+pro_id+"&page=1"
	
	if info=="insert":	
		stu=Student(school_process_id_id=pro_id,student_name=student)
		stu.save()
		return render(request,'info.html',{'info':'添加成功','url':url})
	elif info=="select":
		stu=Student.objects.filter(student_name=student,school_process_id_id=pro_id)
		if len(stu)==0:
			return render(request,'info.html',{'info':'不存在','url':url})
		else:
			return render(request,'info.html',{'stu':stu,'url':url}) 
	elif info=="delete":
		stu_id=request.GET['student_id']
		stu=Student.objects.filter(student_name=student,school_process_id_id=pro_id,student_id=stu_id)
		if len(stu)==0:
			return render(request,'info.html',{'info':'不存在','url':url})
		else:
			stu.delete()
			
			return render(request,'info.html',{'info':'删除成功','url':url})
	else:
		stu_id=request.GET['student_id']
		student_new=request.GET['student_new']
		stu=Student.objects.filter(student_name=student,school_process_id_id=pro_id,student_id=stu_id)
		if len(stu)==0:
			return render(request,'info.html',{'info':'不存在','url':url})
		else:
			stu[0].student_name=student_new
			stu[0].save()
			return render(request,'info.html',{'info':'修改成功','url':url})
Example #10
0
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            user_name = register_form.cleaned_data['email']
            pass_word = register_form.cleaned_data['password']
            # user_name = request.POST.get('email', '')
            # pass_word = request.POST.get('password', '')
            if UserProfile.objects.filter(email=user_name):
                # return render(request, 'register.html', {'register_form': register_form, 'msg': '用户已存在'})
                return HttpResponse('{"status":"fail", "msg":"用户已存在"}', content_type='application/json')
            user_profile = UserProfile()
            user_profile.username = user_name
            user_profile.email = user_name
            user_profile.is_active = False
            user_profile.password = make_password(pass_word)
            user_profile.save()

            student = Student()
            student.user = user_profile
            school = School.objects.get(id=1)
            student.school = school
            student.save()


            # 系统发送消息
            user_message = UserMessage()
            user_message.user = user_profile.id
            user_message.message = u'欢迎注册'
            user_message.save()

            #send_register_email(user_name, 'register')
            # return render(request, 'login.html')
            return HttpResponse('{"status":"success", "url":"/login/"}', content_type='application/json')
        else:
            # return render(request, 'register.html', {'register_form': register_form})
            return HttpResponse(json.dumps(register_form.errors), content_type='application/json')