def after_jmp(self,response): xml = WebPage(response.body) data = dict(xml.parse(['input'],['title','value'],VERBOSE = True)) data = dict( (k.split(':')[0],k.split(':')[1].strip()) if ':' in k else (k,'') if not v else (k.split(':')[0],v.strip()) for k,v in data.items() ) print data d = data td = xml.parse(['textarea'],['text'],VERBOSE = True) print '-'*30,td,'-'*30 if td: tdetails= xml.parse(['textarea'],['text'],VERBOSE = True)[0][0] else: tdetails = '' p = Person.objects.filter(name=d['Name']) if not p: p = Person(name=d['Name'],affected_email=d['Affected E-mail'],reported_email=d['Reported E-mail']) p.save() else: p = p[0] tf = self.convertdate(d['Target Finish']) af = self.convertdate(d['Actual Finish']) tt = TicketItem(ticket=d['Incident'],owner=d['Owner'],target_finish = tf,summary=d['Summary'],owner_group=d['Owner Group'],priority=d['Internal Priority'],user=p,status=d['Status'],details=tdetails,actual_finish=af) yield(tt)
def add_person(request): for i in range(15): person = Person() person.p_name = "tom%d" % i person.p_age = i person.p_sex = i % 2 person.save() return HttpResponse("ok")
def form_valid(self, form): user = User.objects.create_user(username=form.cleaned_data['username'], password=form.cleaned_data['pwd'], email=form.cleaned_data['mail']) user.save() person = Person(user=user) person.save() return HttpResponseRedirect(self.get_success_url())
def add_person(request): for i in range(20): person = Person() flag = random.randrange(100) person.p_name = 'tom%d' % flag person.p_age = flag person.p_sex = flag % 2 person.save() return HttpResponse('批量创建成功')
def handle(self, *args, **options): print('Parsing persons.') print("Deleting all persons") Person.objects.filter(source='zakon.kz').delete() Person2Document.objects.all().delete() paginator = Paginator(MainDocuments.objects.all().order_by('-id'), 1000) for page in range(1, paginator.num_pages + 1): for md in paginator.page(page).object_list: match = re.search('Судья:(.*)', md.title) try: rezult = match.group(1) try: exist = Person.objects.get(raw_name=rezult, source='zakon.kz') except Exception as e: p = Person() p.raw_name = rezult p.role = 'СУДЬЯ' p.source = 'zakon.kz' p.save() p.parse() p2d = Person2Document() p2d.person = p p2d.document = md p2d.save() print("%s Судья ... %s" % (md.id, rezult)) except Exception as e: pass #print(str(e)) match = re.search(': (.*)Судья:', md.title) try: rezult = match.group(1) for nm in rezult.split(','): nm.replace('.', '') if len(nm) > 2: checking_words = nm.split(' ') if len(checking_words) < 5: try: exist = Person.objects.get( raw_name=rezult, source='zakon.kz') except Exception as e: p = Person() p.raw_name = nm p.role = 'ОТВЕТЧИК' p.source = 'zakon.kz' p.save() p.parse() p2d = Person2Document() p2d.person = p p2d.document = md p2d.save() print("%s Истец ... %s" % (md.id, rezult)) except Exception as e: #print(str(e)) pass
def save_page(self,data): print 'in save-page' for i,d in enumerate(data): p = Person.objects.filter(name=d['Affected Person Name']) if not p: p = Person(name=d['Affected Person Name']) p.save() tf = datetime.datetime.strptime(d['Target Finish'],'%y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S') tt = TicketItem(ticket=d['Incident'],owner=d['Owner Name'],target_finish = tf,summary=d['Summary'],owner_group=d['Owner Group'],priority=d['Internal Priority'],user=p,status=d['Status']) yield(tt)
def add_persons(request): for i in range(15): person = Person() flag = random.randrange(100) person.p_name = "Tom%d" % i person.p_age = flag person.p_sex = flag % 2 person.save() return HttpResponse("批量创建成功")
def add_person(request): per = Person() per.name = '郭靖%d' % random.randrange(100) per.sex = '男' per.age = '%d' % random.randrange(18, 40) per.save() card = Card() card.num = '413016199701219876' card.pid = per card.save() return HttpResponse('数据关联成功')
def register(request): if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): new_user = form.save() new_person = Person(user=new_user, name=new_user.username) new_person.save() return HttpResponseRedirect("/accounts/login/") else: form = UserCreationForm() return render(request, 'register.html', {'form': form})
def __store_to_db(self, content): try: Person.objects.get( name=content['name'], external_identifier=content['external_identifier']) except Person.DoesNotExist: person_to_add = Person( external_identifier=content['external_identifier'], internal_identifier=content['internal_identifier'], name=content['name'], role=content['role']) person_to_add.save()
def get_next_page(self,response): #print type(response),dir(response) xml = WebPage(response.body) data = response.meta['data'] print 'Size of data<get_next_page>:',len(data) if data: data += parse_list(xml) else: data = parse_list(xml) for i,d in enumerate(data): p = Person(name=d['Affected Person Name']) p.save() tf = datetime.datetime.strptime(d['Target Finish'],'%y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S') tt = TicketItem(ticket=d['Incident'],owner=d['Owner Name'],target_finish = tf,summary=d['Summary'],owner_group=d['Owner Group'],priority=d['Internal Priority'],user=p,status=d['Status']) yield(tt)
def save_profile(backend, user, response, *args, **kwargs): if backend.name == 'facebook': person = Person.objects.filter(user=user).first() if not person: person = Person(user=user) person.email = user.email person.user_name = user.username person.name = response.get('name') person.save() elif backend.name == 'google-oauth2': person = Person.objects.filter(user=user).first() if not person: person = Person(user=user) person.email = user.email person.user_name = user.username person.name = response.get('name') person.save()
def save_profile(backend, user, response, *args, **kwargs): if backend.name == 'facebook': profile = user try: person = Person.objects.get(user=profile) except: person = Person(user=profile) person.email = user.email person.name = response.get('name') person.save() elif backend.name == 'google-oauth2': profile = user try: person = Person.objects.get(user=profile) except: person = Person(user=profile) person.email = user.email person.name = response.get('name')['givenName'] + " " + response.get('name')['familyName'] person.save()
def save_profile(backend, user, response, *args, **kwargs): if backend.name == 'facebook': profile = user try: person = Person.objects.get(user=profile) except: person = Person(user=profile) person.email = user.email person.name = response.get('name') person.save() elif backend.name == 'google-oauth2': profile = user try: person = Person.objects.get(user=profile) except: person = Person(user=profile) person.email = user.email person.name = response.get( 'name')['givenName'] + " " + response.get('name')['familyName'] person.save()
def parse_company(c): try: city = City.objects.get(name_ru__icontains=c.city_text) c.city = city c.save() except: print('City not found') namear = c.faunders_text.split(',') p = Person() p.raw_name = namear[0] p.role = namear[1] p.source = 'flagma.kz' p.save() p.parse() p2c = Person2Company() p2c.company = c p2c.person = p p2c.save() print('Saving person %s' % namear[0])
def add_people(): for i in range(0, 1000): sex = random.choice((0, 1)) pers = Person() cites = City.objects.all() if sex: # Мужчина name = random.choice( ('Иван', 'Федор', 'Никита', 'Николай', 'Сергей', 'Ярослав')) famil = random.choice( ('Сергеев', 'Степанов', 'Кац', 'Иванов', 'Петров', 'Башаров')) otch = random.choice(('Иванович', 'Сергеевич', 'Петрович', 'Дмитриевич', 'Никитович', 'Степанович')) else: # Женщина name = random.choice( ('Нина', 'Ирина', 'Соня', 'Виктория', 'Светлана', 'Наталья')) famil = random.choice(('Сергеевна', 'Степановна', 'Кац', 'Иванова', 'Петрова', 'Башарова')) otch = random.choice(('Ивановна', 'Сергеевна', 'Петровна', 'Дмитриевна', 'Никитовна', 'Степановна')) pers.fullname = "%s %s %s" % (name, famil, otch) pers.snils = snils() pers.city = random.choice(cites) h = random_number.normalvariate(2, 2) if h < 0: h = 0 elif h > 3: h = 3 pers.health_status = h pers.birthday = datetime.datetime.now() - datetime.timedelta( days=random_number.normalvariate(45, 40) * 365) income = random_number.normalvariate(3000, 1000) if income < 0: income = 0 pers.month_income = income pers.gender = sex pers.save()
def add_person(request): """ Add new person into MySQL databases Http form MUST includes `student_number`, `name`, `pinyin` and `gender` :param request: httpRequest :return: status (success or fail), err_info and err_code """ if request.method == 'POST' and token_check(request): try: person_info = json.loads(request.body.decode('utf-8'))['person'] new_person = Person( student_number=person_info['student_number'], name=person_info['name'], pinyin=person_info['pinyin'], gender=person_info['gender'], native_province=person_info['native_province'] if 'native_province' in person_info.keys() else '', dormitory=person_info['dormitory'] if 'dormitory' in person_info.keys() else '', birthday=person_info['birthday'] if 'birthday' in person_info.keys() else '2000-01-01', phone_number=person_info['phone_number'] if 'phone_number' in person_info.keys() else '', position=person_info['position'] if 'position' in person_info.keys() else '', participation=person_info['participation'] if 'participation' in person_info.keys() else 0) new_person.save() return JsonResponse({'status': 'success'}) except DatabaseError as e: return JsonResponse({ 'status': 'fail', 'err_code': e.args[0], 'err_info': e.args[1], })
import django from app.models import Person f = open("dataPy.csv", mode='r') toBeAdded = [] # pTest = Person(ImgNumber=1, Form=18, FirstName="James", LastName="Hovet", NickName="James", NumCorrect=0, NumIncorrect=0, UnformattedName="shown 100",NumShown=100) # '2988311,"Abby ""Abby"" Hannah Kong \'17",Abby,Kong,Abby,17,F' f.readline() for line in f: d = line.strip().split(',') tmp = Person(ImgNumber=d[0], Form=d[5], FirstName=d[2], LastName=d[3], NickName=d[4], NumCorrect=0, NumIncorrect=0, UnformattedName=d[1],NumShown=0, Gender=d[6]) tmp.save()
def addperson(request): person = Person() person.p_name = 'Atom-' + str(random.randrange(1, 100)) person.save() return render(request, 'addperson.html')
def test_save(self): new_person = Person(name="New Name") new_person.save() self.assertIn(new_person, Person.all())
def test_all(self): self.assertEqual(1, Person.all().count()) new_person = Person(name="New Name") new_person.save() self.assertEquals(2, Person.all().count())
def addperson(request): person = Person() person.p_name = '小白-' + str(random.randrange(1, 100)) person.save() return HttpResponse('添加成功:' + person.p_name)
yun_hua.save() yonghua_xu.save() yinye_fan.save() admin.save() # yun_hua = User.objects.get(username='******') engineering = Department(dept_id=600800, name='技术工程部', summary='Engineering') engineering.save() admin_dept = Department(dept_id=600310, name='行政部', summary='Admin') admin_dept.save() # engineering = Department.objects.get(dept_id='600800') person1 = Person(user=yun_hua, employee_id=149, privilege=1, department=engineering) person1.save() person2 = Person(user=yonghua_xu, employee_id=61, privilege=1, department=engineering) person2.save() person3 = Person(user=yinye_fan, employee_id=99, privilege=1, department=engineering) person3.save() person_admin = Person(user=admin, employee_id=0, privilege=1, department=engineering) person_admin.save() type1 = ProjectType(typename='FA', summary='客户项目') type1.save() type2 = ProjectType(typename='BD', summary='商务拓展') type2.save() type3 = ProjectType(typename='Internal R&D', summary='内部研发') type3.save() type4 = ProjectType(typename='customer service', summary='客户服务') type4.save()