def slice_courseware(courseware): #catname, catname_en = db_util.get_category_names(courseware.category_id) return { 'id': courseware.id, 'provider_id': courseware.book_provider.id, 'provider_name': courseware.book_provider.name, 'provider_name_en': courseware.book_provider.name_en, 'category_id': courseware.category.id, 'category_name': courseware.category.name_ch, 'category_name_en': courseware.category.name_en, 'grade_id': courseware.grade, 'grade_name': common_def.get_grade_display(courseware.grade), 'volume_id': courseware.volume_id, 'name': courseware.name, 'name_en': '', 'course_id': courseware.course.id, 'course_name': courseware.course.course_name, # courseware.get_course_name(), 'course_name_en': courseware.course.english_name, 'image': courseware.get_image_url(), 'description': courseware.description, 'url': courseware.get_absolute_url(), 'password': courseware.password, 'new': courseware.new, 'downloaded': courseware.downloaded, 'teacher': courseware.teacher.first_name, 'upload_time': courseware.modified_time.strftime('%Y-%m-%d %H:%M:%S') }
def get_teacher_courselist(user): course_refs = common_models.TeacherClassCourse.objects.select_related( 'course', 'myclass').filter(teacher=user, myclass__is_active=True).order_by( '-myclass__year', 'course') #=========================================================================== # ret = [] # for c in courses: # ret.append((c.myclass.get_grade(), c.myclass, c.course)) # sorted(ret, lambda x: x[0]) # return [{str(x):common_def.get_grade_display(x), \ # str(y.id):y.name, str(z.id):z.name} for (x,y,z) in ret] #=========================================================================== ret = [] for cr in course_refs: grade = cr.myclass.get_grade() ret.append({ 'grade_id': grade, 'grade_name': common_def.get_grade_display(grade), 'class_id': cr.myclass.id, 'class_name': cr.myclass.name, 'course_id': cr.course.id, 'course_name': cr.course.course_name }) return ret
def user_properties(request, token, uid): try: profile = common_models.UserProfile.objects.select_related( 'school', 'myclass').get(user__pk=uid) age = profile.get_age() if age is None: age = 0 data = { 'user_type': profile.get_usertype(), 'school_id': profile.school_id, 'school_name': profile.school and profile.school.name or '', 'name': profile.user.first_name, 'sex': profile.get_gender(), 'age': age, 'tel': profile.telphone, 'address': profile.address } if profile.usertype == common_def.USERTYPE_STUDENT: grade = profile.myclass.get_grade() data.update({ 'grade_id': grade, 'grade_name': common_def.get_grade_display(grade), 'class_id': profile.myclass.id, 'class_name': profile.myclass.name, }) except User.DoesNotExist: data = {} return HttpResponse(json.dumps(data, ensure_ascii=False))
def json_from_class(classes): ret = [] for cid, year, date, name in classes: grade = util.calc_grade(year, date) ret.append({ 'class_id': cid, 'class_name': name, 'grade_id': grade, 'grade_name': common_def.get_grade_display(grade) }) return ret
def get_teacher_courses(user, clss): course_refs = models.TeacherClassCourse.objects.select_related( 'course', 'myclass').filter(teacher=user, myclass__is_active=True).order_by( '-myclass__year', 'course') if clss > 0: course_refs = course_refs.filter(myclass=clss) old = () ret = [] just_first_class = clss and clss < 0 for c in course_refs: grade = c.myclass.get_grade() if clss and clss < 0: clss = c.myclass.id if just_first_class and int(clss) != c.myclass.id: break if (grade, c.course.id) != old: ret.append(c.course) c.course.name = common_def.get_grade_display( grade) + c.course.course_name old = (grade, c.course.id) return ret, clss
def grade_name(grade): return common_def.get_grade_display(grade)