本文整理汇总了Python中views_helpers.api_response函数的典型用法代码示例。如果您正苦于以下问题:Python api_response函数的具体用法?Python api_response怎么用?Python api_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了api_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_icalendar_event
def generate_icalendar_event(event_id):
"""Takes an event id and returns the event in iCal format"""
cal = Calendar()
event = icalendar.Event()
matching_event = Event.query.get(event_id)
if matching_event is None:
return api_response(status_code=404, error='Event')
event.add('summary', matching_event.name)
event.add('geo', (matching_event.latitude, matching_event.longitude))
event.add('location', matching_event.location_name)
event.add('color', matching_event.color)
event.add('dtstart', matching_event.start_time)
event.add('dtend', matching_event.end_time)
event.add('logo', matching_event.logo)
event.add('email', matching_event.email)
event.add('description', matching_event.description)
event.add('url', matching_event.event_url)
cal.add_component(event)
#Saving ical in file
filename = "event_calendar/event-calendar-" + str(event_id) + ".ics"
f = open(os.path.join(os.path.realpath('.') + '/static/', filename), 'wb')
f.write(cal.to_ical())
f.close()
return api_response(
data=jsonify(calendar=str(cal.to_ical), filename=filename),
status_code=event_status_code(event_id),
error='Event'
)
示例2: generate_icalendar_track
def generate_icalendar_track(event_id, track_id):
"""Takes a track id and returns the track in iCal format"""
cal = Calendar()
track = icalendar.Event()
matching_track = Track.query.get(track_id)
if matching_track is None:
return api_response(status_code=404, error='Track')
if matching_track.event_id != event_id:
return api_response(status_code=404, error='Event')
track.add('summary', matching_track.name)
track.add('description', matching_track.description)
track.add('url', matching_track.track_image_url)
cal.add_component(track)
return cal.to_ical()
示例3: get_languages
def get_languages(event_id):
"""Returns all event's languages"""
languages = Language.query.filter_by(event_id=event_id)
return api_response(
data=ObjectFormatter.get_json("languages", languages, request),
status_code=event_status_code(event_id),
error='Event'
)
示例4: get_microlocations
def get_microlocations(event_id):
"""Returns all event's microlocations"""
microlocations = Microlocation.query.filter_by(event_id=event_id)
return api_response(
data=ObjectFormatter.get_json("microlocations", microlocations, request),
status_code=event_status_code(event_id),
error='Event'
)
示例5: get_formats
def get_formats(event_id):
"""Returns all event's formats"""
formats = Format.query.filter_by(event_id=event_id)
return api_response(
data=ObjectFormatter.get_json("formats", formats, request),
status_code=event_status_code(event_id),
error='Event'
)
示例6: get_sponsors
def get_sponsors(event_id):
"""Returns all event's sponsors"""
sponsors = Sponsor.query.filter_by(event_id=event_id)
return api_response(
data=ObjectFormatter.get_json("sponsors", sponsors, request),
status_code=event_status_code(event_id),
error='Event'
)
示例7: get_tracks
def get_tracks(event_id):
"""Returns all event's tracks"""
tracks = Track.query.filter_by(event_id=event_id)
return api_response(
data=ObjectFormatter.get_json("tracks", tracks, request),
status_code=event_status_code(event_id),
error='Event'
)
示例8: get_sessions
def get_sessions(event_id):
"""Returns all event's sessions"""
sessions = Session.query.filter_by(event_id=event_id, is_accepted=True)
return api_response(
data=ObjectFormatter.get_json("sessions", sessions, request),
status_code=event_status_code(event_id),
error='Event'
)
示例9: get_microlocations_per_page
def get_microlocations_per_page(event_id, page):
"""Returns 20 event's microlocations"""
microlocations = Microlocation.query.filter_by(event_id=event_id)
return api_response(
data=ObjectFormatter.get_json("microlocations", microlocations, request, page),
status_code=event_status_code(event_id),
error='Event',
check_data=True
)
示例10: get_formatsper_page
def get_formatsper_page(event_id, page):
"""Returns 20 event's formats"""
formats = Format.query.filter_by(event_id=event_id)
return api_response(
data=ObjectFormatter.get_json("formats", formats, request, page),
status_code=event_status_code(event_id),
error='Event',
check_data=True
)
示例11: get_sponsors_per_page
def get_sponsors_per_page(event_id, page):
"""Returns 20 event's sponsors"""
sponsors = Sponsor.query.filter_by(event_id=event_id)
return api_response(
data=ObjectFormatter.get_json("sponsors", sponsors, request, page),
status_code=event_status_code(event_id),
error='Event',
check_data=True
)
示例12: get_speaker_by_id
def get_speaker_by_id(speaker_id):
"""Return speaker data by speaker id"""
speaker = DataGetter.get_speaker(speaker_id)
if speaker:
return jsonify(speaker.serialize)
return api_response(
status_code=404,
error='Speaker'
)
示例13: get_tracks_per_page
def get_tracks_per_page(event_id, page):
"""Returns 20 event's tracks"""
tracks = Track.query.filter_by(event_id=event_id)
return api_response(
data=ObjectFormatter.get_json("tracks", tracks, request, page),
status_code=event_status_code(event_id),
error='Event',
check_data=True
)
示例14: get_event_version
def get_event_version(event_id):
"""Returns event's the latest version"""
version = Version.query.filter_by(event_id=event_id).order_by(Version.id.desc()).first()
if version:
return jsonify(version.serialize)
return api_response(
status_code=404,
error='Version'
)
示例15: get_session_by_id
def get_session_by_id(session_id):
"""Returns a session's data by session id"""
session = DataGetter.get_session(session_id)
if session:
return jsonify(session.serialize)
return api_response(
status_code=404,
error='Session'
)