Esempio n. 1
0
def example_data():
    """Mock user and contact data for testing."""

    User.query.delete()

    mary = User(username="******",
                first_name="Mary",
                last_name="Lamb",
                email="*****@*****.**",
                password="******",
                phone_number="12345678901")
    toby = User(username="******",
                first_name="Tobias",
                last_name="Funke",
                email="*****@*****.**",
                password="******",
                phone_number="12345678902")

    mary_contact = Contact(user_id=1,
                           contact_name="Joseph",
                           relationship="husband",
                           contact_phone_number="17142091862")

    toby_contact = Contact(user_id=2,
                           contact_name="George Michael",
                           relationship="nephew",
                           contact_phone_number="17142091862")

    db.session.add_all([mary, toby])
    db.session.commit()
Esempio n. 2
0
def contact_list():
    """Show all contacts and add a contact into the database."""

    contacts = Contact.query.all()

    if request.method == 'GET':
        return render_template('contact_list.html', contacts=contacts)

    elif request.method == 'POST':
        # Get form variables
        name = request.form.get('name')
        type = request.form.get('type')
        phone = request.form.get('phone')

        user_id = session.get('user_id')

        new_contact = Contact(name=name, user_id=user_id)
        new_phone = Phone(phone=phone, type=type)

        new_contact.phones.append(new_phone)

        db.session.add(new_contact)
        db.session.commit()

        flash(f"Contact {name} added.")

        return jsonify(new_contact.convert_to_dict())
Esempio n. 3
0
 def _route(self, message_data=None):
     self.raw_message_data = message_data
     self.message = email.message_from_string(message_data, Message)
     self.mailfrom = Contact.create_contacts_from_message_field('from', self.message)[0]
     self.tos = Contact.create_contacts_from_message_field('to', self.message)
     self.ccs = Contact.create_contacts_from_message_field('cc', self.message)
     self.bccs = Contact.create_contacts_from_message_field('bcc', self.message)
     self._call_routes()
Esempio n. 4
0
 def _route(self, message_data=None):
     self.raw_message_data = message_data
     self.message = email.message_from_string(message_data, Message)
     self.mailfrom = Contact.create_contacts_from_message_field('from', self.message)[0]
     self.tos = Contact.create_contacts_from_message_field('to', self.message)
     self.tos.extend( Contact.create_contacts_from_message_field('x-forwarded-to', self.message) )
     self.ccs = Contact.create_contacts_from_message_field('cc', self.message)
     self.bccs = Contact.create_contacts_from_message_field('bcc', self.message)
     self._call_routes()
Esempio n. 5
0
def example_data():
    phone = os.environ.get('MY_NUMBER')
    email = os.environ.get('MY_EMAIL')
    fb_at = os.environ.get('FB_AT')
    fb_uid = os.environ.get('FB_UID')

    # ADD USERS
    jane = User(email='*****@*****.**',
                password='******',
                fname='Jane',
                lname='Hacks',
                phone='+11234567890')
    bob = User(email='*****@*****.**',
               password='******',
               fname='Bob',
               lname='Baller',
               phone='+10987654321')
    db.session.add_all([jane, bob])
    # db.session.add(inny)
    db.session.commit()
    # ADD CONTACTS
    john = Contact(name='John Recruitor',
                   email='*****@*****.**',
                   user_id=jane.id)
    sally = Contact(name='Sally Secretary',
                    email='*****@*****.**',
                    user_id=bob.id)
    ian = Contact(name='Ian Interviewer', email='*****@*****.**', user_id=bob.id)
    db.session.add_all([john, sally, ian])
    db.session.commit()
    # ADD TEMPLATES
    fup = Template(name='follow up', text='hello there')
    ty = Template(name='thank you', text='thank you for meeting!')
    ty2 = Template(name='thank you', text='thank you for meeting!')
    fup2 = Template(name='follow up', text='hello there')
    db.session.add_all([ty, ty2, fup, fup2])
    db.session.commit()
    # ADD EVENTS
    e1 = Event(contact_id=ian.id,
               date=datetime.datetime(2017, 12, 30),
               template_id=fup.id)
    e2 = Event(contact_id=john.id, template_id=ty.id)
    e3 = Event(contact_id=ian.id, template_id=ty2.id)
    e4 = Event(contact_id=sally.id,
               date=datetime.datetime(2018, 1, 1),
               template_id=fup2.id)
    db.session.add_all([e1, e2, e3, e4])
    db.session.commit()
    # ADD CONTACTEVENT ASSOCIATIONS
    ce1 = ContactEvent(contact_id=e1.contact_id, event_id=e1.id)
    ce2 = ContactEvent(contact_id=e2.contact_id, event_id=e2.id)
    ce3 = ContactEvent(contact_id=e3.contact_id, event_id=e3.id)
    ce4 = ContactEvent(contact_id=e4.contact_id, event_id=e4.id)
    db.session.add_all([ce1, ce2, ce3, ce4])
    db.session.commit()
Esempio n. 6
0
    def getAllContacts(self):
        contactList = list([Contact])
        # List<Contact> contactList = new ArrayList<>()
        
        # db = SQLiteDatabase.getReadableDatabase() 

        # Select all contacts from the database table
        selectAll = "SELECT * FROM " + Util.TABLE_NAME 
        Cursor cursor = self.database.rawQuery(selectAll,None)

        # loop through the data
        if cursor.moveToFirst():
            ' Was originally a java do{ while { } } loop ' 
            # do:
            while cursor.moveToNext():
                contact = Contact() 
                contact.setId(Integer.parseInt(cursor.getString(0))) 
                contact.setName(cursor.getString(1)) 
                contact.setPhoneNumber(cursor.getString(2))
                
                # add contact objects to our list
                contactList.add(contact)
            # while cursor.moveToNext():
            
        cursor.close() 
        return contactList
Esempio n. 7
0
def edit_contact(contact_id):
    """Edit's a contact's info"""

    #Creates variables from the form on the contacts page
    print("Edit Contact request.json: ", request.json)
    name = request.json['name']
    phone = request.json['phone']
    email = request.json['email']
    user_id = request.json['user_id']
    contact_id = request.json['contact_id']

    if contact_id != 'new':
        ((db.session.query(Contact).filter_by(contact_id=contact_id)).update(
        {'name':name, 'email':email, 'phone':phone}))
        contact = Contact.query.filter_by(contact_id=contact_id).one()
        db.session.commit()
    else:
        new_contact = Contact(user_id=user_id, name=name, email=email, phone=phone)
        db.session.add(new_contact)
        db.session.commit()
        contact = Contact.query.order_by(Contact.contact_id.desc()).first()
        print("Edit Contact Output: ", contact)

    
    output = json.dumps({'new_contact_id': contact.contact_id})
    return output
Esempio n. 8
0
def add_contact(modal=""):
    """Adds a user's new contact's info to the dBase"""

    #Creates variables from the form on the contacts page
    name = request.form['name']
    phone = request.form['phone']
    email = request.form['email']
    #c_type = request.form['c_type']
    message = request.form['message']

    #Queries the current user
    user = User.query.filter_by(email=session['current_user']).one()

    #Creates the new Contact object, adds it to the dBase and commits the addition
    new_contact = Contact(user_id=user.user_id,
                          name=name,
                          email=email,
                          phone=phone,
                          c_message=message)
    db.session.add(new_contact)
    db.session.commit()

    #If this is first time a contact is added, the user's timezone is also saved
    if modal == "first":
        timezone = request.form['tzim']
        (db.session.query(User).filter(User.user_id == user.user_id).update(
            {'timezone': timezone}))
        db.session.commit()
        return redirect("/bs_alerts")

    #If the call came from a modal, it redirects them back to the same modal
    if modal == "modal":
        return redirect("/bs_alerts/modal")
    return redirect("/contacts")
Esempio n. 9
0
 def _persist_contact(self, contact):
     if session.query(Contact).filter(
             Contact.email == contact['email']).count() == 0:
         c = Contact()
         (c.email, c.name) = (contact['email'], contact['name'])
         session.add(c)
         session.commit()
Esempio n. 10
0
 def auth(self, message_data=None, peer_ip=None, message=None):
     mailfrom = Contact.create_contacts_from_message_field('from', message)[0]
     host = re.match('[^@]*@(.*)', mailfrom.email).group(1)
     result_status = spf.check(i=peer_ip, s=mailfrom.email, h=host)[0]
     if 'pass' in result_status:
         return True
     return False
Esempio n. 11
0
    def get_contact_list(self):
        if self.contact_cache is None:
            wd = self.app.wd
            self.open_contacts_page()
            self.show_contacts_from_all_groups()
            self.contact_cache = []
            for element in wd.find_elements_by_xpath(
                    "//table[@id='maintable']/tbody/tr")[1:]:
                cells = element.find_elements_by_xpath("td")
                try:
                    homepage = cells[9].find_element_by_xpath(
                        "a/img").get_attribute("alt")
                except Exception:
                    homepage = ""

                self.contact_cache.append(
                    Contact(
                        id=element.find_element_by_name(
                            "selected[]").get_attribute("value"),
                        firstname=cells[2].text,
                        lastname=cells[1].text,
                        address=cells[3].text,
                        homepage=homepage,
                        all_emails_from_homepage=cells[4].text,
                        all_phones_from_homepage=cells[5].text,
                    ))
        return self.contact_cache
Esempio n. 12
0
 def get_contact_from_view_page(self, index):
     wd = self.app.wd
     self.open_contact_view_page_by_index(index)
     content = wd.find_element_by_id("content").text
     return Contact(home_tel=re.search("H: (.*)", content).group(1),
                    mobile_tel=re.search("M: (.*)", content).group(1),
                    work_tel=re.search("W: (.*)", content).group(1))
Esempio n. 13
0
    def get_online_users():
        user_list = []

        for user in server_data_container.user_list:
            user_list.append(
                Contact(user['user_id'], user['user_name'],
                        user['user_name'] + '.jpg'))
        return user_list
Esempio n. 14
0
    def process_request(self, req):
        """Process the request. For ClearSilver, return a (template_name,
        content_type) tuple, where `template` is the ClearSilver template to use
        (either a `neo_cs.CS` object, or the file name of the template), and
        `content_type` is the MIME type of the content. For Genshi, return a
        (template_name, data, content_type) tuple, where `data` is a dictionary
        of substitutions for the template.

        For both templating systems, "text/html" is assumed if `content_type` is
        `None`.

        Note that if template processing should not occur, this method can
        simply send the response itself and not return anything.
        """
        req.perm('contacts').assert_permission('CONTACTS_VIEW')

        add_stylesheet(req, 'common/css/admin.css')
        if re.match(r'^/contacts$', req.path_info):
            return ('contacts.html', {
                'contacts': ContactIterator(self.env),
                'can_edit': 'CONTACTS_ADMIN' in req.perm('contacts')
            }, None)

        req.perm('contacts').assert_permission('CONTACTS_ADMIN')

        #   We will be using the contact.html file, so include it's JS
        #   Get Contact ID
        params = req.path_info.split('/')
        contact_id = None
        if (len(params) > 2 and params[2].isdigit()):
            contact_id = params[2]
        contact = Contact(self.env, contact_id)

        #   Check if saving
        if req.method == 'POST' and req.args.get('addcontact'):
            contact.update_from_req(req)
            contact.save()
            if (req.args.get('redirect')):
                req.redirect(
                    req.args.get('redirect') + '?contact_id=%d' % contact.id)
            else:
                req.redirect(req.href.contacts())
            #   redirecting, so the rest of this function does not get ran

        template = {'contact': contact}
        if (len(params) > 2 and params[2].isdigit()):
            add_script(req, 'contacts/edit_contact.js')
            add_stylesheet(req, 'contacts/edit_contact.css')
            template['title'] = 'Edit %s' % contact.last_first()
            template['edit'] = True
        else:
            template['title'] = 'Add Contact'
            template['edit'] = False
        if (req.args.get('redirect')):
            template['redirect'] = req.args.get('redirect')
        else:
            template['redirect'] = None

        return ('contact.html', template, None)
Esempio n. 15
0
    def search_users(keyword):
        user_list = []

        db = MySQL()
        results = db.select("SELECT * FROM User WHERE username LIKE %s",
                            "%" + keyword + "%")
        for result in results:
            user_list.append(Contact(result[0], result[1], result[1] + ".jpg"))

        return user_list
Esempio n. 16
0
    def test_contact_creation(self):
        """Test user creation"""

        new_contact = Contact(contact_first_name='Unittest',
                              contact_last_name='Test', lang_id=2, user_id=1,
                              contact_phone='4153417706')

        db.session.add(new_contact)
        db.session.commit()

        query_db = Contact.query.filter_by(contact_first_name='Unittest').first()
        self.assertIsNotNone(query_db)
  def get(self, request):
    entity_id = request.id
    if not entity_id:
      message = 'Request should specify an id.' % entity_id
      raise endpoints.BadRequestException(message)

    entry = Contact.get_by_id(entity_id)
    
    if not entry:
      message = 'No entity with the id "%s" exists.' % entity_id
      raise endpoints.NotFoundException(message)

    return _BuildContactMessage(entry)
Esempio n. 18
0
def add_fb_conctacts(contacts_list):
    """If a user registers in via OAuth, add their FB friends as contacts."""
    user_id = session['user_id']
    for thing in contacts_list:
        try:
            name = thing[0].encode('utf-8')
            pic_url = thing[1]
            c = Contact(name=name, pic_url=pic_url, user_id=user_id)
            db.session.add(c)
            db.session.commit()
            print "{} add to DB for user_id={}".format(name, user_id)
        except:
            pass
Esempio n. 19
0
def addcontact():
    form = ContactForm()
    if form.validate_on_submit():
        contact = Contact(name=form.name.data,
                          value=form.value.data,
                          show_on_footer="show_on_footer" in request.form,
                          show_on_contact="show_on_contact" in request.form)
        db.session.add(contact)
        db.session.commit()
        return redirect(url_for("addcontact"))
    template = render_template("admin/contact/contacts/addcontact.html",
                               form=form)
    return checkLogin(template)
Esempio n. 20
0
    def process_request(self, req):
        """Process the request. For ClearSilver, return a (template_name,
        content_type) tuple, where `template` is the ClearSilver template to use
        (either a `neo_cs.CS` object, or the file name of the template), and
        `content_type` is the MIME type of the content. For Genshi, return a
        (template_name, data, content_type) tuple, where `data` is a dictionary
        of substitutions for the template.

        For both templating systems, "text/html" is assumed if `content_type` is
        `None`.

        Note that if template processing should not occur, this method can
        simply send the response itself and not return anything.
        """
        req.perm('contacts').assert_permission('CONTACTS_VIEW')

        add_stylesheet(req, 'common/css/admin.css')
        if re.match(r'^/contacts$', req.path_info):
            return ('contacts.html', 
                {   'contacts': ContactIterator(self.env),
                    'can_edit': 'CONTACTS_ADMIN' in req.perm('contacts')
                }, None)

        req.perm('contacts').assert_permission('CONTACTS_ADMIN')

        #   We will be using the contact.html file, so include it's JS
        #   Get Contact ID
        params = req.path_info.split('/')
        contact_id = None
        if (len(params) > 2 and params[2].isdigit()):
            contact_id = params[2]
        contact = Contact(self.env, contact_id)

        #   Check if saving
        if req.method == 'POST' and req.args.get('addcontact'):
            contact.update_from_req(req)
            contact.save()
            if (req.args.get('redirect')):
                req.redirect(req.args.get('redirect') + '?contact_id=%d' % contact.id)
            else:
                req.redirect(req.href.contacts())
            #   redirecting, so the rest of this function does not get ran

        template = {'contact': contact}
        if (len(params) > 2 and params[2].isdigit()):
            add_script(req, 'contacts/edit_contact.js')
            add_stylesheet(req, 'contacts/edit_contact.css')
            template['title'] = 'Edit %s' % contact.last_first()
            template['edit'] = True
        else:
            template['title'] = 'Add Contact'
            template['edit'] = False
        if (req.args.get('redirect')):
            template['redirect'] = req.args.get('redirect')
        else:
            template['redirect'] = None

        return ('contact.html', template, None)
Esempio n. 21
0
def process_users_contact_info():
    """Save user's contact information to our database"""

    # getting current user in session
    current_user = session.get("user_id")

    contact_phone_number = request.form.get("contact_phone_number")
    relationship = request.form.get("relationship").title()
    contact_name = request.form.get("contact_name").title()

    phone_check = re.search(
        r"\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]??\d{4}",
        contact_phone_number)

    if phone_check is None:
        flash(
            "Invalid phone number. Please enter the number in the following format '555 555 5555'"
        )
        return render_template("add-contact.html")

    # TODO: allow a user to add back a contact even if that phone number has
    # already been added before (but was 'deleted')

    # if the contact is already in our database, will return True
    # import pdb; pdb.set_trace()
    check_contact_phone_number = Contact.query.filter(
        Contact.contact_phone_number == contact_phone_number,
        Contact.user_id == current_user).first()

    # if above query returns None (i.e. phone number not in database)
    if not check_contact_phone_number:
        new_contact = Contact(user_id=current_user,
                              contact_name=contact_name,
                              relationship=relationship,
                              contact_phone_number=contact_phone_number,
                              status="Active")

        db.session.add(new_contact)
        db.session.commit()
        flash("Your contact has been added.")

        print("\n\n\nCONTACT ADDED\n\n\n")

        return redirect("/my-contacts")

    else:
        flash(
            "It looks like you've already added a contact with this phone number."
        )
        return redirect("/my-contacts")
Esempio n. 22
0
 def get_contact_list(self):
     list = []
     with (self.connection.cursor()) as cursor:
         cursor.execute(
             "select id, firstname, lastname, address from addressbook where deprecated='0000-00-00 00:00:00'"
         )
         for row in cursor:
             id, firstname, lastname, address = row
             list.append(
                 Contact(id=str(id),
                         firstname=firstname,
                         lastname=lastname,
                         address=address))
     return list
Esempio n. 23
0
  def get(self, request):
    #TODO(abahgat): would this work with placeholders? /_ah/spi/contacts/entity_id
    entity_id = request.id
    if not entity_id:
      message = 'Request should specify an id.' % entity_id
      raise endpoints.BadRequestException(message)

    entry = Contact.get_by_id(entity_id)
    
    if not entry:
      message = 'No entity with the id "%s" exists.' % entity_id
      raise endpoints.NotFoundException(message)

    return _BuildContactMessage(entry)
Esempio n. 24
0
def load_contacts():
    """Load contacts from contact_data into database."""

    for line in open("seed_data/contact_data"):
        line = line.rstrip()
        contact_id, user_id, fname, lname = line.split(",")

        contact = Contact(contact_id=contact_id,
                          user_id=user_id,
                          fname=fname,
                          lname=lname)

        db.session.add(contact)

    db.session.commit()
Esempio n. 25
0
 def convert(contact):
     return Contact(id=str(contact.id),
                    firstname=contact.firstname,
                    lastname=contact.lastname,
                    company=contact.company,
                    home_tel=contact.home_tel,
                    mobile_tel=contact.mobile_tel,
                    work_tel=contact.work_tel,
                    sec_tel=contact.sec_tel,
                    email=contact.email,
                    email2=contact.email2,
                    email3=contact.email3,
                    note=contact.note,
                    address=contact.address,
                    homepage=contact.homepage)
Esempio n. 26
0
def registracija_post():
    username = bottle.request.forms.getunicode('username')
    if username in uporabniki:
        napaka = USERNAME_TAKEN
        return bottle.template('registracija.html', obvestilo=napaka)
    passwd = bottle.request.forms.getunicode('passwd')
    h = hashlib.blake2b()
    h.update(passwd.encode(encoding='utf-8'))
    password = h.hexdigest()
    user = User(username, password, Contact())
    uporabniki[username] = user
    bottle.response.set_cookie('username',
                               user.username,
                               path='/',
                               secret=skrivnost)
    bottle.redirect('/imenik/')
Esempio n. 27
0
def add_contact():
    name = request.form['name']
    phone = request.form['phone']
    email = request.form['email']
    c_type = request.form['c_type']
    message = request.form['message']
    user = User.query.filter_by(email=session['current_user']).one()
    new_contact = Contact(user_id=user.user_id,
                          name=name,
                          email=email,
                          phone=phone,
                          c_type=c_type,
                          c_message=message)
    db.session.add(new_contact)
    db.session.commit()
    return redirect("/contacts")
Esempio n. 28
0
def handle_event_form():
    """Validates and adds new event and template to DB."""
    # Need to add the contact and template before creating an event
    name = request.form.get('contact_name')
    email = request.form.get('contact_email')
    phone = request.form.get('contact_phone')
    address = request.form.get('contact_address')
    user_id = session.get("user_id")
    new_contact = Contact(name=name,
                          email=email,
                          phone=phone,
                          address=address,
                          user_id=user_id)
    db.session.add(new_contact)
    db.session.commit()
    greet = "Hi"
    sign_off = "Yours"
    body = request.form.get('body')
    user_fname = User.query.get(user_id).fname
    contact_fname = name.encode('utf-8').split()[0]
    template_text = "{} {}, \n{} \n{},\n{}".format(greet, contact_fname, body,
                                                   sign_off, user_fname)

    # add template
    template_name = request.form.get('template_name')
    new_template = Template(name=template_name, text=template_text)
    db.session.add(new_template)
    db.session.commit()

    # add event
    contact_id = new_contact.id
    date = request.form.get('date')
    new_event = Event(contact_id=contact_id,
                      user_id=user_id,
                      template_id=new_template.id,
                      date=date)
    db.session.add(new_event)
    db.session.commit()

    # add ContactEvent association
    ce = ContactEvent(contact_id=contact_id, event_id=new_event.id)
    db.session.add(ce)
    db.session.commit()

    # redirect to user profile
    flash("You have successfully added a new event for {}!".format(name))
    return redirect('/profile')
Esempio n. 29
0
 def get_contacts_count(self, count):
     return [
         Contact(
             firstname=random_string("", self.name_max_len),
             lastname=random_string("", self.name_max_len),
             company=random_string("", self.data_max_len),
             home_tel=random_phone("", self.tel_max_len),
             mobile_tel=random_phone("", self.tel_max_len),
             work_tel=random_phone("", self.tel_max_len),
             sec_tel=random_phone("", self.tel_max_len),
             email=random_email("", self.email_max_len),
             email2=random_email("", self.email_max_len),
             email3=random_email("", self.email_max_len),
             note=random_string("", self.data_max_len),
             address=random_string("", self.data_max_len),
             homepage=random_string("", self.data_max_len),
         ) for _ in range(count)
     ]
Esempio n. 30
0
    def getContact(self,Contact):
        
        contact = Contact.getContact(uid)
        db = SQLiteDatabase.getReadableDatabase()
        
        cursor = SQLiteDatabase.cursor()
        
        # cursor is used to iterate through db table elements
        cursor = db.query(Util.TABLE_NAME,list((Util.KEY_ID,Util.KEY_NAME, Util.KEY_PHONE_NUMBER)),Util.KEY_ID +"=?", list(String.valueOf(id)),None,None,None) 

        if cursor != None:
            cursor.moveToFirst() 

        contact = Contact() 
        contact.setId(Integer.parseInt(cursor.getString(0))) 
        contact.setName(cursor.getString(1)) 
        contact.setPhoneNumber(cursor.getString(2)) 

        cursor.close() 

        return contact 
Esempio n. 31
0
def add_contact():
    """Add contact to database."""

    # Get information from form
    fname = request.form.get("fname")
    lname = request.form.get("lname")

    # Get existing contact with form info
    existing_contact = Contact.query.filter_by(user_id=g.user_id,
                                               fname=fname,
                                               lname=lname).first()

    # Make new contact with form info
    new_contact = Contact(user_id=g.user_id, fname=fname, lname=lname)

    # Check if existing contact is in database, add new contact if it isn't
    check_and_add(existing_contact, new_contact)

    return redirect(request.referrer)
def parse_contacts(user, contacts_xml=None):
    parser = etree.XMLParser(ns_clean=True, recover=True, encoding="utf-8")
    root = etree.fromstring(contacts_xml.encode("utf-8"), parser)
    elms = root.findall("{http://www.w3.org/2005/Atom}entry")
    contacts = []
    
    for elm in elms:
        contact_name = get_contacts_name(elm)
        contact_phone = get_contacts_phone(elm)
        language = user.language.lang_id
        existing_contact = Contact.query.filter_by(user_id=user.user_id, contact_phone=contact_phone).all()
        if contact_phone != None:
            if not existing_contact:
                gmail_contact = Contact(contact_first_name=contact_name[0], 
                                    contact_last_name=contact_name[1],
                                    contact_phone=contact_phone, lang_id=language, user_id=user.user_id)
                db.session.add(gmail_contact)

    db.session.commit()
Esempio n. 33
0
 def get_test_selection(self):
     return [
         Contact(
             firstname=firstname,
             lastname=lastname,
             company=random_string("", self.data_max_len),
             home_tel=random_phone("", self.tel_max_len),
             mobile_tel=random_phone("", self.tel_max_len),
             work_tel=random_phone("", self.tel_max_len),
             sec_tel=random_phone("", self.tel_max_len),
             email=random_email("", self.email_max_len),
             email2=random_email("", self.email_max_len),
             email3=random_email("", self.email_max_len),
             note=random_string("", self.data_max_len),
             address=address,
             homepage=random_string("", self.data_max_len),
         ) for firstname in ["", random_string("", self.name_max_len)]
         for lastname in ["", random_string("", self.name_max_len)]
         for address in ["", random_string("", self.data_max_len)]
     ]
Esempio n. 34
0
def load_contacts():
    """Load contacts from contact-example into database."""

    print("Loading contacts...")

    # Delete all rows in table to make sure there are no duplicates
    Contact.query.delete()

    # Read user file and insert data
    for row in open("data/contact-example.txt"):
        row = row.rstrip()
        fname, lname, company_id = row.split("|")

        contact = Contact(fname=fname, lname=lname, company_id=company_id)

        # Add to the session or it won't ever be stored
        db.session.add(contact)

    # Once we're done, we should commit our work
    db.session.commit()
Esempio n. 35
0
 def list(self, request):
   contact_messages = []
   for contact in Contact.query().fetch():
     contact_messages.append(_BuildContactMessage(contact))
   return GetContactsResponse(contacts=contact_messages)
Esempio n. 36
0
 def test_create_contacts_from_message_field_successfully_creates_contact_object(self):
     contacts = Contact.create_contacts_from_message_field('to', self.message)
     self.assertEqual(contacts[0].email, '*****@*****.**')
 def list(self, request):
   contact_messages = []
   for contact in Contact.query().fetch():