Example #1
0
def get_phones():
    session = Session()
    try:
        es = session.query(Phone).all()
    except NoresultFound:
        return None
    else: 
        es = jsonify(es)
        return es
Example #2
0
def get_possible_carriers(number):
    session = Session()
    try:
        phone = session.query(Phone).filter_by(number=number).one()
        carriers = session.query(PhoneCarrier).filter_by(phone_id=phone.phone_id, possible=True).all()
    except NoResultFound:
        return None
    else:
        return carriers
Example #3
0
def get_carriers(phone_id):
    session = Session()
    try:
        es = session.query(Phone).filter_by(phone_id=phone_id).one()
    except NoresultFound:
        return None
    else: 
        carriers = session.query(PhoneCarrier).filter_by(phone_id=phone_id).all()
        return jsonify(carriers)
Example #4
0
def getPhoneEntries(phone_id):
    """Returns a list in JSON form of all entries containing phone_id"""
    session = Session()
    try:
        es = session.query(Entry).filter_by(phone_id=phone_id).all()
    except NoResultFound:
        return none
    else:
        return jsonify(data=es)
Example #5
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)
Example #6
0
    def test_create_list(self):
        list_name = "TestList"
        res = self.app.post('/lists', data=dict(
            name=list_name,
        ))

        res_list = json.loads(res.data)
        assert res_list["data"]["name"] == list_name

        # Check against the database
        session = Session()
        data_list = session.query(List).get(res_list["data"]["list_id"])
        assert data_list.name == list_name
Example #7
0
def send_text_Twilio(list_id):
    """Sends a text via the Twilio API to all entries in list_id"""
    sender = request.form.get('sender')
    print sender
    message = request.form.get('message')

    session = Session()
    lst = session.query(List).get(list_id)
    assert lst
    #attachments = request.form.get('attachments')
    print message
    for entry in lst.entries:
        print "sent message"
        sendSMS("sid placeholder","authkey placeholder", sender, entry.phone.number, message)
    return "hello"
Example #8
0
    def test_get_phone(self):
        pid = 1
        res = self.app.get('/phones/%d' % pid)

        assert res.status_code == 200 # check that the server return success
        print "The data is " + res.data
        data = json.loads(res.data)

        assert data["data"]['phone_id'] == pid

        # Get the phone object from the database
        session = Session()
        phone = session.query(Phone).get(pid)

        assert phone.name == data["data"]['name']
        assert phone.number == data["data"]['number']
Example #9
0
def send_text(list_id):
    """Sends a text via email to all entries in list_id"""
    sender = request.form.get('sender')
    message = request.form.get('message')
    method = request.form.get('method')
    session = Session()
    lst = session.query(List).get(list_id)
    #attachments = request.form.get('attachments')
    #print message
    if method == "email":
        for ent in lst.entries:
            print dir(ent)
            text_by_email(ent.phone.number, sender, message, ent.phone.textemail)
    else:
        for entry in lst.entries:
            print "sent message"
            sendSMS("AC0955b5ae6e4e14861d9e1f61e7d0680f","a4938640070b8bcaf099093da23676f0", sender, entry.phone.number, message)
    return "success"
Example #10
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)
Example #11
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
Example #12
0
def index():
    session = Session()
    res = session.query(Phone).all()
    # take list ID. display all entries in list 
    return render_template('example.html', x=res)
Example #13
0
def list_detail(list_id):
    print request.url
    session= Session()
    res = session.query(Entry).filter_by(list_id=list_id).all()
    return render_template('showEntries.html', x=res, listid=list_id)
Example #14
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})
Example #15
0
def get_all_phones():
    """Returns a list containing all phones in a JSON object"""
    session = Session()
    es = session.query(Phone).all()
    return jsonify(data=es)
Example #16
0
 def setUp(self):
     super(TestObj2JSON, self).setUp()
     session = Session()
     self.mlist = session.query(List).get(1)
     self.phone = session.query(Phone).get(1)