-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.py
35 lines (30 loc) · 1.18 KB
/
post.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from datetime import datetime
from db import Base
from sqlalchemy import Boolean, Column, DateTime, Float, Integer, String, TIMESTAMP, text
import json
import cgi
class Post(Base):
__tablename__ = 'post'
id = Column(Integer, primary_key=True)
created_at = Column(TIMESTAMP, server_default=text('CURRENT_TIMESTAMP'))
message = Column(String(256), nullable=False)
latitude = Column(Float, nullable=False)
longitude = Column(Float, nullable=False)
time_limit = Column(Integer, nullable=False)
sponsored = Column(Boolean, nullable=False)
def __init__(self, message, latitude, longitude, time_limit=60, sponsored=False):
self.message = cgi.escape(message) # strip html/javascript
self.latitude = latitude
self.longitude = longitude
self.time_limit = time_limit
self.sponsored = sponsored
def __repr__(self):
return json.dumps({
"id": self.id,
"created_at": self.created_at.isoformat(),
"time_limit": self.time_limit,
"message": self.message,
"latitude": self.latitude,
"longitude": self.longitude,
"sponsored": self.sponsored
})