本文整理汇总了Python中models.Event.select方法的典型用法代码示例。如果您正苦于以下问题:Python Event.select方法的具体用法?Python Event.select怎么用?Python Event.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Event
的用法示例。
在下文中一共展示了Event.select方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_events
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import select [as 别名]
def get_events():
now = time.time() * 1000
one_week = 1000 * 60 * 60 * 24 * 7
time_from = request.args.get("from", now)
time_to = request.args.get("to", now + one_week)
datetime_from = datetime.datetime.utcfromtimestamp(float(time_from)/1000)
datetime_to = datetime.datetime.utcfromtimestamp(float(time_to)/1000)
if g.user and g.user.is_authenticated():
events = Event.select().where((Event.timestamp >= datetime_from)
& (Event.timestamp <= datetime_to)
).order_by(Event.timestamp)
else:
events = Event.select().where((Event.timestamp >= datetime_from)
& (Event.timestamp <= datetime_to)
& (Event.members_only == False) #noqa
).order_by(Event.timestamp)
to_ret = {"success": 1, "result": []}
for event in events:
if event.members_only:
cls = "members_only"
else:
cls = "public"
strt = (event.timestamp - EPOCH).total_seconds()
end = strt + (60 * 60) * event.duration
to_ret['result'].append(
{"id": event.id,
"title": event.title,
"url": event.id,
"class": cls,
"start": strt * 1000,
"end": end * 1000, })
return dumps(to_ret)
示例2: render_event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import select [as 别名]
def render_event(event_id):
_event = get_object_or_404(Event.select(), Event.id == event_id)
if _event.members_only and not (g.user or g.user.is_authenticated()):
abort(404)
ts = _event.timestamp
end = (ts - EPOCH).total_seconds() + (60**2) * _event.duration
event = _event.as_dict()
event['start'] = ts.strftime("%I:%M %p %m/%d/%Y")
event['end'] = datetime.datetime.utcfromtimestamp(end).strftime(
"%I:%M %p %m/%d/%Y")
return render_template_with_user("event.html", event=event)
示例3: get_events
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import select [as 别名]
def get_events():
"""Return list of events
Params
since ("YYYY-mm-dd"): datetime
until ("YYYY-mm-dd"): datetime
q (string): search string
Fields
data (list): List of Event objects
"""
allowed_filters = [
("since", lambda x: Event.start_time >= datetime.datetime.strptime(x, "%Y-%m-%d")),
("until", lambda x: Event.start_time <= datetime.datetime.strptime(x, "%Y-%m-%d")),
("q", lambda x: Event.name.contains(x))
]
events = Event.select()
filters = [f(request.args[param]) for param, f in allowed_filters if param in request.args]
if filters:
events = events.where(*filters)
return json.jsonify(data=[evt.serialized() for evt in events])
示例4: events
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import select [as 别名]
def events(self):
events = []
for event in Event.select():
events.append(event.dict())
return events