def profile(request): record = DBSession.query(Shelter).filter(Shelter.auth_id==request.user.id).first() if record is None: record = Shelter(auth_id=request.user.id) form = ProfileForm(request.POST, obj=record) if request.method == 'POST' and form.validate(): record = merge_session_with_post(record, request.POST.items()) record.auth_id = request.user.id if record.id: DBSession.merge(record) else: DBSession.add(record) DBSession.flush() #raise HTTPFound(location=request.route_url('index')) raise HTTPFound(location=request.route_url('profile')) return {'form': form}
def create_mailbox(shelter_phone, mailbox_number): print 'creating mailbox', mailbox_number mailbox = MailboxGreeting(shelter_phone=shelter_phone, mailbox=mailbox_number) DBSession.add(mailbox) DBSession.commit()