Esempio n. 1
0
def add_user(list_id):
    """Creates new entry in list_id with number and name. 
    Returns a JSON object of the entry or an error if it alreayd exists"""
    num = request.form.get('number')
    name = request.form.get('name')
    session = Session()
    email = ""
    try:
        phone = session.query(Phone).filter_by(number=num).one()
    except NoResultFound:
        phone = Phone(name,int(num))
        session.add(phone)
        session.commit()
        init_possible_carriers(num)
    
    entry = Entry(list_id, phone.phone_id)
    try:
        session.add(entry)
        session.commit()
    except (IntegrityError,InvalidRequestError):
        Session.rollback()
        print "Phone already exists for this list"
        return jsonify(data=Struct({'entry_id' : entry.entry_id}))
    print dumps({"entry_id" : entry.entry_id})
     
    return dumps({"entry_id" : entry.entry_id})
Esempio n. 2
0
def del_entry(entry_id):
    session = Session()
    entry = session.query(Entry).get(entry_id)
    session.delete(entry)
    session.commit()
    #session.query(Entry).filter(Entry.entry_id==entry_id).delete()
    return jsonify(data=entry)
Esempio n. 3
0
def create_list():
    """Creates a list with name and returns a JSON object of the list"""
    name = request.form.get('name')
    lst = List(name)
    
    session = Session()
    session.add(lst)
    session.commit()

    print request.url
    return jsonify(data=lst)
Esempio n. 4
0
def init_possible_carriers(number):
    session = Session()
    try:
        phone = session.query(Phone).filter_by(number=number).one()
    except NoResultFound:
        return None
    try:
        for p in providers:
            carrier = PhoneCarrier(phone.phone_id, p.replace('%s', number))
            session.add(carrier)
        session.commit()
    except Exception ,e:
        pass