示例#1
0
    def get_or_creat_nbr(self):
        ''' add operation '''

        if not self.is_complete():
            return

        number = unicode(self.number.text().replace('.', ''))
        amount = unicode(self.amount.text())
        Contact.get_or_create(number)

        data = {
            "phone_num": [
                number,
            ],
            "amount": amount,
            "code": unicode(self.password_field.text())
        }
        # print(data)
        # multiple_sender(data)
        self.number.clear()
        self.amount.clear()
        self.password_field.clear()
        self.table.refresh_()
        self.msg_field.setText(
            u"Transfert  vers ({}) a été effectué.".format(number))
        self.msg_field.setStyleSheet("color: green")
示例#2
0
def index(page=1, pagesize=10, sortby='id', sortdir='asc', search=None):
    """
    /api/contacts
    :return: list of contacts with paging information
    """
    if search is not None:
        return searchContacts(search)

    contacts = Contact.select().order_by(
        SQL(f"{sortby} COLLATE NOCASE {sortdir}")).paginate(page, pagesize)
    emails = Email.select()
    phones = Phone.select()

    contacts_with_emails_iter = prefetch(contacts, emails, phones)
    data = []
    for contact in contacts_with_emails_iter:
        data.append(
            contact.serialize()
            # {
            #     'id': contact.id,
            #     'fname': contact.fname,
            #     'lname': contact.lname,
            #     'dob': contact.dob,
            #     'emails': [ {'id': em.id, 'email': em.email } for em in contact.emails ]
            # }
        )

    return {
        'data': data,
        'numberRecords': Contact.select().count(),
        'page': page,
        'pagesize': pagesize
    }
示例#3
0
def contact():
    form = Contact(request.form)
    if request.method == 'POST' and form.validate():
        message = 'Nombre: %s\nEmail: %s\n%s' % (form.name.data,
        									form.email.data, form.text.data)
        msg = Message(subject=form.subject.data, sender=form.email.data,
        			  body=message, recipients=[''])
        mail.send(msg)
        return render_template('success.html')
    return render_template('contact-form.html',
    	form=form)
示例#4
0
def create(contact):
    """
    Create new contact

    :param contact: contact information
    :return:    matching contact
    """
    print(contact)
    fname = contact.get("fname", None)
    lname = contact.get("lname", None)
    dob = contact.get("dob", None)
    # emails = contact.get("emails", [])

    if fname is None or lname is None or dob is None:
        abort(406, f"Entries must not be empty")

    contact = Contact.create(**{
        'fname': fname,
        'lname': lname,
        'dob': dob[:10]
    })

    # if len(emails) > 0:
    #     for email in emails:
    #         Email.create(**{
    #             'contact_id': contact.id,
    #             'email': email
    #         })

    # return make_response(f"{fname} {lname} successfully created", 201)
    return contact.serialize()
示例#5
0
def _save_phone_num(phone_num):
    if db.session.query(Contact).filter_by(phone_num=phone_num).count() > 0:
        pass  # already exists
    else:
        new_contact = Contact(phone_num=phone_num)
        db.session.add(new_contact)
        db.session.commit()
示例#6
0
def sent_page():
    user_name = request.form['name']
    user_email = request.form['email']
    user_message = request.form['messege']
    msg = Contact(name=user_name, email=user_email, messege=user_message)
    session.add(msg)
    session.commit()
    return render_template('sent_page.html')
示例#7
0
def searchContacts(searchString):
    print(searchString)
    if len(searchString.split()) > 1:
        first, last = searchString.split()
        contacts = Contact.select().where((Contact.fname.contains(first))
                                          & (Contact.lname.contains(last)))
    else:
        contacts = Contact.select().where(Contact.fname.contains(searchString))

    returnList = []
    for c in contacts[:25]:
        returnList.append(c.serialize())

    return {
        'data': returnList,
        'numberRecords': len(returnList),
        'page': 1,
        'pagesize': 25
    }
示例#8
0
def index(cid):
    """
    /api/contacts/{cid}/addresses
    :return: list of a contact's addresses
    """
    contact = Contact.get(Contact.id == cid)

    addresses = []
    for address in contact.addresses:
        addresses.append(address.serialize())

    return addresses
示例#9
0
文件: home.py 项目: fadiga/waritchi
    def get_or_creat_nbr(self):
        ''' add operation '''

        if not self.is_complete():
            return

        number = unicode(self.number.text().replace('.', ''))
        amount = unicode(self.amount.text())
        Contact.get_or_create(number)

        data = {"phone_num": [number, ], "amount": amount,
                "code": unicode(self.password_field.text())}
        # print(data)
        # multiple_sender(data)
        self.number.clear()
        self.amount.clear()
        self.password_field.clear()
        self.table.refresh_()
        self.msg_field.setText(
            u"Transfert  vers ({}) a été effectué.".format(number))
        self.msg_field.setStyleSheet("color: green")
示例#10
0
def contactus():
	user=get_current_user()
	if request.method=='POST':
		if user:
			companyn=session.query(Company.name).filter_by(id=user.company_id).first()
			requests=Contact(name=user.name, email=user.email, mobile=user.mobile, message=request.form['message'], company=companyn.name, completed=0)
			name=user.name
			email=user.email
			print name, email
		else:
			requests=Contact(name=request.form['name'], email=request.form['email'], mobile=request.form['mobile'], message=request.form['message'], company=request.form['company'], completed=0)
			name=request.form['name']
			email=request.form['email']
	
		session.add(requests)
		session.commit()
		emailfunc2(email,name)
		emailfunc3()
		return 'successfull contact'
	if request.method=='GET':
		return redirect('/#contact')
示例#11
0
def index(cid):
    """
    /api/contacts/{cid}/phones
    :return: list of a contact's phones
    """
    contact = Contact.get(Contact.id == cid)

    phones = []
    for phone in contact.phones:
        phones.append(phone.serialize())

    return phones
示例#12
0
def index(cid):
    """
    /api/contacts/{cid}/emails
    :return: list of a contact's emails
    """
    contact = Contact.get(Contact.id == cid)

    emails = []
    for email in contact.emails:
        emails.append(email.serialize())

    return emails
示例#13
0
def read(cid):
    """
    Read one contact identified by cid

    :param cid: id of the contact to retrieve
    :return:    matching contact
    """
    try:
        contact = Contact.get(Contact.id == cid)
    except StopIteration:
        abort(404, f"Contact with id {cid} not found")

    return contact.serialize()
示例#14
0
def delete(cid):
    """
    Delete contact identified by cid

    :param cid:     id of the contact to retrieve
    :param contact: new contact information
    :return:        matching contact
    """
    try:
        contact = Contact.get(Contact.id == cid)
    except DoesNotExist:
        abort(404, f"Contact with id {cid} not found")

    contact.delete_instance(recursive=True)

    return contact.serialize()
示例#15
0
def update(cid, contact):
    """
    Update contact identified by cid

    :param cid:     id of the contact to retrieve
    :param contact: new contact information
    :return:        matching contact
    """
    try:
        theContact = Contact.get(Contact.id == cid)
    except DoesNotExist:
        abort(404, f"Contact with id {cid} not found")

    # update with new information
    print(contact)
    if contact.get('fname', None):
        theContact.fname = contact.get('fname')
    if contact.get('lname', None):
        theContact.lname = contact.get('lname')
    if contact.get('dob', None):
        theContact.dob = contact.get('dob')
    theContact.save()

    return theContact.serialize()
user1 = User(username='******', email='*****@*****.**', password='******')

user2 = User(username='******', email='*****@*****.**', password='******')
user3 = User(username='******', email='*****@*****.**', password='******')

session.add(user)
session.add(user1)
session.add(user2)
session.add(user3)

print("Users Done :)")

######################

cnt1 = Contact(name='wassim',
               mail='*****@*****.**',
               sub='I want to check in ..',
               msg='qsdjqksldqsdkqsdlkqsdqsd')
cnt2 = Contact(name='ayman',
               mail='*****@*****.**',
               sub='I want your help ..',
               msg='qsdjqksldqsdkqsdlkqsdqsd')
cnt3 = Contact(name='wassim',
               mail='*****@*****.**',
               sub='can you help me ..',
               msg='qsdjqksldqsdkqsdlkqsdqsd')
cnt4 = Contact(name='asaad',
               mail='*****@*****.**',
               sub='best sales in surf',
               msg='qsdjqksldqsdkqsdlkqsdqsd')

session.add(cnt1)