def run(data): contact_data = data.get('contact_data') contact_data = Contacts(**contact_data) first_name = contact_data.first_name last_name = contact_data.last_name email = contact_data.email mobile_number = contact_data.mobile_number description = contact_data.description save = Contacts(first_name=first_name, last_name=last_name, email=email, mobile_number=mobile_number, description=description) save.save()
def addContact(name, surname, phone, email, company, uid): """ Function intended to add users, pass variables with values not values themselves - Pass atleast: Name, Surname && email or phone. uid not encoded """ if name and surname: try: contact = Contacts(name=name, surname=surname, phone=enc(phone), email=enc(email), company=company, uid=uid) contact.save() return True except Exception as e: print(e) return False else: return False
def getContacts(username): """ Function intended to query database for all contacts for user """ user = Users.objects.get(username=username) contacts = Contacts.objects(uid=JSONEncoder().encode(user.id)).all() return [{"id": JSONEncoder().encode(i.id), "name": i.name, "surname": i.surname,"phone": dec(i.phone), "email": dec(i.email), "company": i.company} for i in contacts]
def run(data): contact_data = data.get('contact_data') contact_data = Contacts(**contact_data) email = contact_data.email first_name = contact_data.first_name last_name = contact_data.last_name email = contact_data.email mobile_number = contact_data.mobile_number description = contact_data.description send_to_saiba(email, first_name, last_name, mobile_number, description)
def index(): """Render the index/home page.""" form = ContactForm() if form.validate_on_submit(): info = Contacts(Name=form.name.data, Email=form.email.data, Enquiry=form.enquiry.data) db.session.add(info) db.session.commit() flash('Enquiry submitted successfully!!!') return redirect(url_for('index')) return render_template('index.html', title='Home', form=form)
def admin_coment(): cont = Contacts.query.all() if request.method == 'POST': cts = Contacts( C_username=request.form['C_username'], C_email=request.form['C_email'], C_wepsite=request.form['C_wepsite'], C_company=request.form['C_company'], C_comment=request.form['C_comment'], ) db.session.add(cts) db.session.commit() return redirect('/index/contact') return render_template('main/Contacts.html')
def add_contact(username, first_name, last_name, email, phone_number): # If the username is already in here, it should fail. try: existing_info = Contacts.query.filter( Contacts.username.like(username)).first() if existing_info is None: new_contact = Contacts(username=username, first=first_name, last=last_name, email=email, phone=phone_number) db.session.add(new_contact) db.session.commit() return True else: return False except: db.session.rollback() return False
def init_user(): if current_app.config['ENVIRON'] == 'prod': username = request.environ.get('REMOTE_USER') else: username = current_app.config['TEST_USER'] session['username'] = username contact = Contacts.query.filter(Contacts.username.like(username)).first() if contact is not None: session['fullname'] = contact.first_name + ' ' + contact.last_name else: banner_info = requests.get('https://wsapi.bethel.edu/username/' + username + '/names') info_dict = ast.literal_eval(banner_info.text)['0'] primary_name = info_dict['firstName'] if len(info_dict['prefFirstName']) > 0: primary_name = info_dict['prefFirstName'] session['fullname'] = primary_name + ' ' + info_dict['lastName'] new_contact = Contacts(username=username, first=primary_name, last=info_dict['lastName'], email=username + '@bethel.edu', phone='') db.session.add(new_contact) db.session.commit()
def insert_contact(municipality, parsed_address, zip, zone_dict): from app.models import Contacts #Create a Contacts object and save z=Contacts() z.address=parsed_address z.zip=zip z.recycle_zone=zone_dict["recycle_zone"] z.recycle_day=zone_dict["recycle_day"] z.trash_zone=zone_dict["trash_zone"] z.trash_day=zone_dict["trash_day"] z.yard_zone=zone_dict["trash_zone"] z.yard_day=zone_dict["trash_day"] z.municipality=municipality z.save() #Return the primary key to access this record later in session. stackoverflow.com/questions/732952/get-primary-key-after-saving-a-modelform-in-django primary_key = z.pk return primary_key