示例#1
0
def send_message(format):
    if not 'message' in request.form.keys():
        return "Missing message", 400
    else:
        message = request.form['message']
        l = None
        d = None
        
        if 'location_letters' in request.form.keys():
            if request.form['location_letters']:
                try:
                    l = db_unique(Location, letters=request.form['location_letters'], numbers=int(request.form['location_numbers']))
                except Exception, e:
                    return str(e), 400
        
        if 'timestamp' in request.form.keys():
            if request.form['timestamp']:
                d = datetime.datetime.fromtimestamp(int(request.form['timestamp']))
        
        try:
            m = Message(message, l, d)
            db_session.add(m)
            db_session.commit()
        except Exception, e:
            return str(e), 400
from euskalmap.database import db_session, db_unique
from euskalmap.models import Message, Location
from datetime import datetime

for m in Message.query.all():
    db_session.delete(m)
db_session.commit()

items = [
            Message("This is a test message", db_unique(Location, letters="AK", numbers=91), datetime.now()),
            Message("Test message without location or timestamp"),
            Message("This one only has a timestamp.", None, datetime.now()),
            Message("Location, but no timestamp.", db_unique(Location, letters="AK", numbers=91))
        ]

for i in items:
    db_session.add(i)
db_session.commit()