def setUp(self): """ Have to manually create users and assign relationships for initial testing. """ testuser = User.objects.create(username='******', password='******', is_active=True, is_staff=True, is_superuser=True) adminrole=Role.objects.get(pk=1) user_role = User_Roles(name="test", user_userid=testuser, role_roleid=adminrole) user_role.save() testuser2 = User.objects.create(username="******", password="******", is_active=True, is_staff=True, is_superuser=True) user_role2 = User_Roles(name="test", user_userid=testuser2, role_roleid=adminrole) user_role2.save() mainorganisation = Organisation.objects.get(pk=1) user_organisation = User_Organisations(user_userid=testuser, organisation_organisationid=mainorganisation) user_organisation.save() user_organisation2 = User_Organisations(user_userid=testuser2, organisation_organisationid=mainorganisation) user_organisation2.save() school1 = School(school_name="TestSchool", school_desc="This is the desc of the TestSchool",organisation_id=1) school1.save() allclass1 = Allclass(allclass_name="TestAllClassTableTest1", allclass_desc="TestAllClass1 Desc", allclass_location="Test Land" ,school=school1) allclass1.save() allclass2 = Allclass(allclass_name="TestAllClassTableTest2", allclass_desc="TestAllClass1 Desc", allclass_location="Test Land") allclass2.save() """
def add_school(request): info=request.GET['info'] school=request.GET['school'] url='school?page=1' if info=="insert": sc=School.objects.filter(school_name=school) if len(sc)>0: return render(request,'info.html',{'info':'学校已存在','url':url}) else: sc=School(school_name=school) sc.save() return render(request,'info.html',{'info':'学校添加成功','url':url}) elif info=="select": sc=School.objects.filter(school_name=school) if len(sc)==0: return render(request,'info.html',{'info':'学校不存在','url':url}) else: return render(request,'info.html',{'sc':sc,'url':url}) else: school_new=request.GET['school_new'] sc=School.objects.filter(school_name=school) if len(sc)==0: return render(request,'info.html',{'info':'学校不存在','url':url}) else: sc[0].school_name=school_new sc[0].save() return render(request,'info.html',{'info':'修改成功','url':url})
def school_create(request, template_name='school/school_create.html', rstate=''): form = SchoolForm(request.POST or None) #organisations = Organisation.objects.all() organisations=[] organisation = User_Organisations.objects.get(user_userid=request.user).organisation_organisationid; organisations.append(organisation) data = {} data['object_list'] = organisations if request.method == 'POST': post = request.POST; #try: if 1 > 0: name = post['school_name'] print(name) school_count = School.objects.filter(school_name=name).count() #if not school_exists(post['school_name']): print("school_count:") print(school_count) if school_count == 0: print("Creating the School..") print("Creating school object") school_name = post['school_name'] school_desc = post['school_desc'] #organisationid = post['organisationid'] #currentorganisation=Organisation.objects.get(pk=organisationid) currentorganisation=organisation school = School(school_name=school_name, school_desc=school_desc, organisation=currentorganisation) school.save() print("Creating organisation school mapping..") print("Organisation School mapping success.") state="The School has been created." data['state']=state if 'submittotable' in request.POST: return render(request, 'school/confirmation.html', data) #return render(request, 'school/school_table.html', data) #return redirect('school_table') if 'submittonew' in request.POST: return render(request, template_name, data,context_instance=RequestContext(request)) #return redirect('school_new') else: return redirect ('school_table') else: #Show message that the school name already exists in our database. state="The School Name already exists.." data['state']=state return render(request, template_name, data) #return redirect('school_table', state) #except: else: #pass print('Something went wrong') #data['state']=rstate; return render(request, template_name, data)
def get_school(self, area, school_name): try: school = School.objects.get(name=school_name, area=area) except: school = School(name=school_name, area=area) school.save() return school
def setUp(self): # Create a school with a list of students school = School(name='instituto hebreo', principal='Juan Perez', location='Santiago') school.save() # ahora creo estudiantes Student.objects.create(name='ilan', age=28, school=school) Student.objects.create(name='sigal', age=22, school=school)
def setUp(self): """ Have to manually create users and assign relationships for initial testing. """ testuser1= User.objects.create(username='******', password='******', is_active=True, is_staff=True, is_superuser=True) testuser1.save() adminrole=Role.objects.get(pk=1) user_role1 = User_Roles(name="test", user_userid=testuser1, role_roleid=adminrole) user_role1.save() testuser2 = User.objects.create(username="******", password="******", is_active=True, is_staff=True, is_superuser=True) testuser2.save() user_role2 = User_Roles(name="test", user_userid=testuser2, role_roleid=adminrole) user_role2.save() mainorganisation = Organisation.objects.get(pk=1) user_organisation1 = User_Organisations(user_userid=testuser1, organisation_organisationid=mainorganisation) user_organisation1.save() user_organisation2 = User_Organisations(user_userid=testuser2, organisation_organisationid=mainorganisation) user_organisation2.save() testuser3 = User.objects.create(username='******', password='******', is_active=True, is_staff=True, is_superuser=True) testuser3.save() user_role3 = User_Roles(name="test", user_userid=testuser3, role_roleid=adminrole) user_role3.save() user_organisation3 = User_Organisations(user_userid=testuser3, organisation_organisationid=mainorganisation) user_organisation3.save() testuser4 = User.objects.create(username='******', password='******', is_active=True, is_staff=True, is_superuser=True) testuser4.save() user_role4 = User_Roles(name="test", user_userid=testuser4, role_roleid=adminrole) user_role4.save() user_organisation4 = User_Organisations(user_userid=testuser4, organisation_organisationid=mainorganisation) user_organisation4.save() school1 = School(school_name="TestSchool", school_desc="This is the desc of the TestSchool",organisation_id=1) school1.save() allclass1 = Allclass(allclass_name="TestAllClassTableTest1", allclass_desc="TestAllClass1 Desc", allclass_location="Test Land" ,school=school1) allclass1.save() #allclass2 = Allclass(allclass_name="TestAllClassTableTest2", allclass_desc="TestAllClass1 Desc", allclass_location="Test Land") #allclass2.save() course1 = Course(name="TestCourse", description="This is a test Course", category="Tests", publisher=testuser1, organisation=mainorganisation, success="YES") course1.save() course2 = Course(name="TestCourse2", description="This is a test Course", category="Tests", publisher=testuser1, organisation=mainorganisation, success="YES") course2.save() """
def setUp(self): """ Have to manually create users and assign relationships for initial testing. """ testuser1= User.objects.create(username='******', password='******', is_active=True, is_staff=True, is_superuser=True) testuser1.save() adminrole=Role.objects.get(pk=1) user_role1 = User_Roles(name="test", user_userid=testuser1, role_roleid=adminrole) user_role1.save() mainorganisation = Organisation.objects.get(pk=1) user_organisation1 = User_Organisations(user_userid=testuser1, organisation_organisationid=mainorganisation) user_organisation1.save() school1 = School(school_name="TestSchool", school_desc="This is the desc of the TestSchool",organisation_id=1) school1.save()
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()
def migrateSchoolToDatabase(): schools = user.getAllSchools() pattern = re.compile(r'\{"[^\}]*"\}') results = pattern.finditer(schools) for item in results: oneSchool = item.group() namePattern = re.compile(r'(?<="yxsmc":")([^"]+?)(?=")') name = namePattern.search(oneSchool).group() print name engNamePattern = re.compile(r'(?<="yxsywmc":")([^"]+?)(?=")') try: engName = engNamePattern.search(oneSchool).group() except: engName = '' numberPattern = re.compile(r'(?<="yxsh":")([^"]+?)(?=")') number = numberPattern.search(oneSchool).group() schoolObj = School(name=name, englishName=engName, number=number) schoolObj.save()
def migrateSchoolToDatabase(): schools = user.getAllSchools() pattern = re.compile(r'\{"[^\}]*"\}') results = pattern.finditer(schools) for item in results: oneSchool = item.group() namePattern = re.compile(r'(?<="yxsmc":")([^"]+?)(?=")') name = namePattern.search(oneSchool).group() print name engNamePattern = re.compile(r'(?<="yxsywmc":")([^"]+?)(?=")') try: engName = engNamePattern.search(oneSchool).group() except: engName = '' numberPattern = re.compile(r'(?<="yxsh":")([^"]+?)(?=")') number = numberPattern.search(oneSchool).group() schoolObj = School(name=name, englishName=engName, number=number) schoolObj.save();
def setUp(self): """ Have to manually create users and assign relationships for initial testing. """ testuser1= User.objects.create(username='******', password='******', is_active=True, is_staff=True, is_superuser=True) testuser1.save() adminrole=Role.objects.get(pk=1) user_role1 = User_Roles(name="test", user_userid=testuser1, role_roleid=adminrole) user_role1.save() mainorganisation = Organisation.objects.get(pk=1) user_organisation1 = User_Organisations(user_userid=testuser1, organisation_organisationid=mainorganisation) user_organisation1.save() testuser2 = User.objects.create(username='******', password='******', is_active=True, is_staff=True, is_superuser=True) testuser2.save() user_role2 = User_Roles(name='test', user_userid=testuser2, role_roleid=adminrole) user_role2.save() user_organisation2 = User_Organisations(user_userid=testuser2, organisation_organisationid=mainorganisation) user_organisation2.save() school1 = School(school_name="TestSchool", school_desc="This is the desc of the TestSchool",organisation_id=1) school1.save() course1 = Course(name="TestCourse", description="This is a test Course", category="Tests", publisher=testuser1, organisation=mainorganisation, success="YES") course1.save() course2 = Course(name="TestCourse2", description="This is a test Course", category="Tests", publisher=testuser1, organisation=mainorganisation, success="YES") course2.save() document1 = Document(elpid='elpid001', name='TestDocument1', url='/link/to/TestDocument1/',uid='uid001',success='YES',publisher=testuser1) document1.save() document2 = Document(elpid='elpid002', name='TestDocument2', url='/link/to/TestDocument2/',uid='uid002',success='YES',publisher=testuser1) document2.save() allclass1 = Allclass(allclass_name="TestAllClass1", allclass_desc="TestAllClass1 Desc", allclass_location="Test Land" ,school=school1) allclass1.save() allclass2 = Allclass(allclass_name="TestAllClass2", allclass_desc="TestAllClass2 Desc", allclass_location="Test Land" ,school=school1) allclass2.save()
from location.models import Location from school.models import School import csv with open('dataframe_v1.csv') as csvfile: spamreader = csv.reader(csvfile, delimiter=',') for row in spamreader: row[2] = row[2].split(row[3])[0][0:-2] try: int(row[1].split(' ')[0]) row[1] = ' '.join(row[1].split(' ')[1:]) except ValueError: pass loc = Location(endereco=row[2], bairro=row[3], latitude=row[4], longitude=row[5]) loc.save() scho = School(nro_entidade=row[0], name=row[1], location=loc) scho.save() print(row)
def __unicode__(self): return School.__unicode__(self.school)
def get_save_school(self): self.log(logging.INFO, "Getting school parameters") node = self.xml['STS_EDT'].find("./PARAMETRES/UAJ") try: school = School.objects.get(code=node.get("CODE")) except ObjectDoesNotExist: self.log(logging.INFO, "Unknown school, creating it") school = School() school.code = node.get("CODE") academy_code = node.find("./ACADEMIE/CODE").text try: academy = Academy.objects.get(code=academy_code) except ObjectDoesNotExist: academy = Academy(code=academy_code, title=node.find("./ACADEMIE/LIBELLE")) academy.save() school.academy = academy sigle = self._gtb(node, "SIGLE", "") denomp = self._gtb(node, "DENOM_PRINC", "") denomc = self._gtb(node, "DENOM_COMPL", "") school.shortname = "%s %s" % (sigle, denomc) school.fullname = "%s %s" % (denomp, denomc) school.categ = self._gtb(node, "CODE_CATEGORIE", "") school.address = self._gtb(node, "ADRESSE", "") school.city = self._gtb(node, "COMMUNE", "") school.postcode = self._gtb(node, "CODE_POSTAL", "") school.pobox = self._gtb(node, "BOITE_POSTALE", "") school.cedex = (self._gtb(node, "CEDEX", "N") == "O") school.phone = self._gtb(node, "TELEPHONE", "") school.status = self._gtb(node, "STATUT", "") school.save() self.log(logging.INFO, "New school created") self.school = school
continue res = -1 while res < 0: res = getaddress(school) sleep(5) if res < 0: sleep(20) continue else: school['address'] = res['address'] print school s = School( name= school['name'], rank= school['rank'], suburb= school['suburb'], score= school['score'], link= school['link'], address= school['address'] ) s.save() except KeyError as e: print e i = i - 1 if i <= 0: break