Esempio n. 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()
Esempio n. 3
0
    
    if "id" not in request.form.keys():
        return "You must specify which message to report.", 400
    
    if "message" in request.form.keys():
        message = request.form['message']
        
    id = int(request.form['id'])

    try:
        m = Message.query.filter_by(id=id).one()
    except Exception, e:
        return str(e), 400
        
    r = AbuseNotice(m, message)
    db_session.add(r)
    
    try:
        db_session.commit()
        return "Abuse report stored."
    except:
        return "DB error", 500

@app.route('/<format>/reports/get')
def get_reports(format):
    return filter_and_output(AbuseNotice.query, None, format)

@app.route('/<format>/comments/post', methods=['POST'])
def post_comment(format):
    if not "id" in request.form.keys():
        return "You must specify the message.", 400