librelist archives

« back to archive

Help with Flask and jsonify with FullCalendar

Help with Flask and jsonify with FullCalendar

From:
Frank Rocco
Date:
2014-05-12 @ 18:49
Hello,

I am trying to port my php version of loading fullcalendar from a database.

My code is:
def dump_datetime(value):
    if value is None:
        return None
    return value.strftime("%Y-%m-%d %H:%M:%S")

class Event(db.Model):
    __tablename__ = 'events'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(128), nullable=False)
    start = db.Column(db.DateTime())
    stop = db.Column(db.DateTime())
    allDay = db.Column(db.Integer, default=False)
   
@property       
    def to_json(self):
        return dict(
            id=self.id,
            title=self.title,
            start=dump_datetime(self.start),
            end=dump_datetime(self.stop),
            allDay=self.allDay
        )

json_list=[i.to_json for i in Event.query.all()]
return render_template('calendar.html', events=str(json_list))

data looks like this in events: [{'start': '2014-05-08 14:02:00', 
'allDay': 0, 'end': '2014-05-08 18:00:00', 'id': 1L, 'title': u'Test'}]

calendar does not show unless I remove the events variable.

Regards,

Frank