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")
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 }
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)
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()
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()
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')
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 }
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
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")
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')
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
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
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()
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()
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)