Beispiel #1
0
def schools(request):
    """ Ajax: School autcomplete form field """
    if request.is_ajax() and request.method == 'POST' and request.POST.has_key('q'):
        query = request.POST.get('q')
        schools = School.objects.filter(name__icontains=query).distinct()
        response = {}
        if len(schools) > 0:
            response['schools'] = [(school.pk, school.name) for school in schools]
            response['status'] = 'success'
        return HttpResponse(json.dumps(response), mimetype="application/json")
    elif request.method == 'POST':
        # for creating a new school from a form
        # create new school, hasn't been implemented yet
        new_school = School()
        a_school = UsdeSchool.objects.get(id=request.POST['school_id'])
        new_school.name = a_school.institution_name
        new_school.location = u"%s, %s" % (a_school.institution_city, a_school.institution_state)
        new_school.url = a_school.institution_web_address
        new_school.save()
        request.user.get_profile().school = new_school
        request.user.get_profile().save()

        response = {}
        return HttpResponse(json.dumps(response), mimetype="application/json")
    else:
        # render the browse-schools route
        response = {}
        response['schools'] = School.objects.order_by('-karma').all()
        return render(request, 'n_browse_schools.html', response)


    raise Http404
Beispiel #2
0
def create_school():
    name = input('学校名字: ').strip()
    addr = input('学校地址: ').strip()
    school_list = [(obj.name, obj.addr)
                   for obj in School.get_obj_list()]  # 学校列表
    if (name, addr) in school_list:
        print('\033[31;1m学校名 [%s], 学校地址[%s] 已存在\033[0m' % (name, addr))
    else:
        school = School(name, addr)
        school.save()
        print('\033[33;1m学校[%s], 地址[%s] 创建成功\033[0m' % (name, addr))
def school2db(response):
    reader = csv.DictReader(StringIO(response.read().decode()))
    for row in reader:
        if row['LGA']:
            lga_name = ''.join(x.lower() for x in row['LGA'] if x.isalpha())
            school_name = row['School_name']
            post_code = str(row['Postcode'])
            latitude = str(row['Latitude'])
            longitude = str(row['Longitude'])
            school_type = str(row['Level_of_schooling'])
            school = School(lga_name, school_name, post_code, latitude, longitude, school_type)
            school.save()
Beispiel #4
0
 def post(self, request):
     """
     Create school record in database
     :param request: Key value pair data
     :return: status & respective message
     """
     data = request.data
     try:
         school = School(**data)
         school.save()
         LOGGER.info("School created successfully")
     except Exception, error:
         LOGGER.error("Error:%s", str(error))
         return Response({"status": "FAILED", "message": str(error)})
Beispiel #5
0
def create_school():
    try:
        name = input('请输入学校名字:').strip()
        addr = input('请输入学校地址:').strip()
        school_name_list = [(obj.name, obj.addr)
                            for obj in School.get_all_obj_list()]
        if (name, addr) in school_name_list:
            raise Exception(
                '\033[43;1m[%s] [%s]校区已经存在,不可重复创建,你有那么多学生吗?\033[0m' %
                (name, addr))
        obj = School(name, addr)
        obj.save()
        status = True
        error = ''
        data = '\033[33;1m[%s] [%s]校区创建成功\033[0m' % (obj.name, obj.addr)
    except Exception as e:
        status = False
        error = str(e)
        data = ''
    return {'status': status, 'error': error, 'data': data}
Beispiel #6
0
    def test_children_ask_for_leave_list(self):
      
        sch = School(school_name="_name1", classes_number=100)
        sch.save()

        twz = Classes(class_name="WeizhongTu", children_number=100,schoolkey=sch)
        twz.save()

        children = Children()
        children.Classeskey = twz
        children.nicename = "1"
        children.save() 
   
        children2 = Children()
        children2.Classeskey = twz
        children2.nicename = "2"
        children2.stats= "路途中"
        children2.save() 

        children3 = Children()
        children3.Classeskey = twz
        children3.nicename = "3"
        children3.stats= "已到达"
        children3.save() 

        leave = Children_ask_for_leave()
        leave.begin_time = datetime.datetime.now() - datetime.timedelta(hours=10)
        leave.end_time = datetime.datetime.now() + datetime.timedelta(hours=10)
        leave.Childrenkey_id = 1 
        leave.save()
        print(leave.begin_time)
        print(datetime.datetime.now())
        print(leave.end_time)


        classes = Classes.objects.get(pk=1)
        list = classes.children_ask_for_leave_list()
        list2 = classes.children_arrived_list()
        list3 = classes.children_road_list()
        count = list.count()+list2.count()+list3.count()
        self.assertEqual(list.count(), 1)
Beispiel #7
0
    if r:
	return InvalidUrl(errorMsg)

    try:
	district = City.objects.filter(province__name = out['province']).filter(name=out['city']).filter(districts__name=out['district'])
    except DoesNotExist,e:
	errorMsg='无法在%s %s找到%s,%s' % (out['province'],out['city'],out['district'],e)
	return InvalidUrl(errorMsg)
    #检查是否是学校管理员电话 
    try:
	sa = SchoolAdministrator.objects.get(telephone = out[telephone])
    except DoesNotExist,e:
	errorMsg='the current user is not a school administrator,only school administrators can create school'
	return InvalidUrl(errorMsg)
    school = School(address = out['address'],name = out['school_name'],status='EI')
    school.save()
    try:
	district.add(school)
	sa.add(school)
    except:
	errorMsg = 'can not add the current school to %s or %s' % (district.name,sa.name)
	return InvalidUrl(errorMsg)
	
    result = '成功注册学校:%s 责任人名字:%s 地区:%s,状态审核中,我们将尽快完成对该学校合法性的审核' % (out['school_name'],sa.name,district.name)
    #后台人员审核通过之后将学校状态置为审核通过
    return RightResponse(result)

def updateSchool(request):
    pass

def querySchool(request):