db.session.add(Gender(name="Male")) db.session.add(Gender(name="Female")) db.session.commit() except: db.session.rollback() f = open("NAMES.DIC", "rb") names_list = [x.strip() for x in f.readlines()] f.close() for i in range(1, 100): c = Contact() c.name = get_random_name(names_list, random.randrange(2, 6)) c.address = "Street " + names_list[random.randrange( 0, len(names_list))].decode("utf-8") c.personal_phone = random.randrange(1111111, 9999999) c.personal_celphone = random.randrange(1111111, 9999999) c.contact_group_id = random.randrange(1, 4) c.gender_id = random.randrange(1, 3) year = random.choice(range(1900, 2012)) month = random.choice(range(1, 12)) day = random.choice(range(1, 28)) c.birthday = datetime(year, month, day) db.session.add(c) try: db.session.commit() print("inserted", c) except: db.session.rollback()
f.close() j = 1 for i in range(1, 100): c = Contact() c.name = get_random_name(names_list, random.randrange(2, 6)) c.address = 'Street ' + names_list[random.randrange(0, len(names_list))] c.personal_phone = random.randrange(1111111, 9999999) c.personal_celphone = random.randrange(1111111, 9999999) c.contact_group_id = random.randrange(1, 4) c.gender_id = random.randrange(1, 3) year = random.choice(range(1900, 2012)) month = random.choice(range(1, 12)) day = random.choice(range(1, 28)) c.birthday = datetime(year, month, day) c.changed_on = datetime.now() c.created_on = datetime.now() if j == 1: j+=1 _user = user1 elif j == 2: j+=1 _user = user2 else: j = 1 _user = user3 c.created_by = _user c.changed_by = _user
def index(): form = ContactForm() if form.validate_on_submit(): contact = Contact() contact.first_name = form.first_name.data contact.last_name = form.last_name.data contact.middle_name = form.middle_name.data contact.prefix = form.prefix.data contact.suffix = form.suffix.data contact.legal_name = contact.first_name + " " + contact.middle_name + " " + contact.last_name contact.about = form.about.data contact.country_code = form.country_code.data contact.home_phone = form.home_phone.data contact.work_phone = form.work_phone.data contact.other_phone = form.other_phone.data contact.email = form.email.data contact.email2 = form.email2.data contact.street1 = form.street1.data contact.city1 = form.city1.data contact.postal_code1 = form.postal_code1.data contact.state1 = form.state1.data contact.street2 = form.street2.data contact.city2 = form.city2.data contact.postal_code2 = form.postal_code2.data contact.state2 = form.state2.data contact.company_name = form.company_name.data contact.company_street = form.company_street.data contact.company_city = form.company_city.data contact.company_state = form.company_state.data contact.company_postal = form.company_postal.data contact.company_country = form.company_country.data contact.company_title = form.company_title.data contact.company_department = form.company_department.data contact.birthday = form.birthday.data contact.home_anniversary = form.home_anniversary.data contact.agent = form.agent.data contact.vendor = form.vendor.data contact.investor = form.investor.data contact.loan_officer = form.loan_officer.data contact.talent = form.talent.data contact.builder = form.builder.data contact.reo = form.reo.data contact.short_sale = form.short_sale.data contact.expired = form.expired.data contact.fsbo = form.fsbo.data contact.sphere = form.sphere.data contact.allied_resource = form.allied_resource.data contact.referral_sources = form.referral_sources.data contact.first_time = form.first_time.data contact.tags = form.tags.data contact.notes = form.notes.data contact.facebook = form.facebook.data contact.twitter = form.twitter.data contact.linkedin = form.linkedin.data contact.google = form.google.data contact.pintrest = form.pintrest.data contact.instagram = form.instagram.data db.session.add(contact) db.session.commit() message = Markup( '<div class="mt-3 alert alert-success alert-dismissible"><button type="button" class="close" data-dismiss="alert">×</button>Contact <strong>{}</strong> added successfully.</div>' .format(contact.legal_name)) flash(message) return redirect(url_for('contacts')) return render_template('index.html', form=form)