def new_contact(): if request.method == 'GET': contact = Contact() return render_template('admin/edit_contact.jinja2', contact=contact) if not flask_login.current_user.is_authenticated(): return current_app.login_manager.unauthorized() contact = Contact() db.session.add(contact) return save_contact(contact)
def contacts(db): for c in TEST_CONTACTS: # create some contacts contact = Contact() contact.name = c[0] contact.url = c[1] contact.image = c[2] contact.social = c[3] contact.nicks = [Nick(name=n) for n in c[4]] db.session.add(contact) db.session.commit()
from redwind.models import Contact, Nick, AddressBook from redwind import db from redwind.util import filter_empty_keys for name, entry in AddressBook().entries.items(): contact = Contact() contact.name = name contact.image = entry.get('photo') contact.url = entry.get('url') contact.social = filter_empty_keys({ 'twitter': entry.get('twitter'), 'facebook': entry.get('facebook') }) if 'twitter' in entry: nick = Nick() nick.name = entry.get('twitter') contact.nicks = [nick] db.session.add(nick) db.session.add(contact) db.session.commit()
from redwind.models import Contact, Nick, AddressBook from redwind import db from redwind.util import filter_empty_keys for name, entry in AddressBook().entries.items(): contact = Contact() contact.name = name contact.image = entry.get('photo') contact.url = entry.get('url') contact.social = filter_empty_keys( {'twitter': entry.get('twitter'), 'facebook': entry.get('facebook')}) if 'twitter' in entry: nick = Nick() nick.name = entry.get('twitter') contact.nicks = [nick] db.session.add(nick) db.session.add(contact) db.session.commit()