本文整理汇总了Python中sugar.get_object_or_404函数的典型用法代码示例。如果您正苦于以下问题:Python get_object_or_404函数的具体用法?Python get_object_or_404怎么用?Python get_object_or_404使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_object_or_404函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_request_funding
def check_request_funding(meeting_id):
sugar.get_object_or_404(models.Meeting, id=meeting_id)
category_id = flask.request.form['category_id']
country_code = flask.request.form['country_code']
resp = {'request_funding': False}
category = sugar.get_person_category_or_404(
meeting_id,
category_id=category_id
)
try:
country = models.Country.get(data__contains={'iso': country_code})
except models.Country.DoesNotExist:
country = None
if category.data.get('request_funding', False):
resp['request_funding'] = True
if category.data.get('credentials_file', False):
resp['credentials_file'] = True
if (category.data.get('request_funding_with_country', False)
and country
and country.data.get('request_funding', False)):
resp['request_funding'] = True
if (category.data.get('credentials_file_with_country', False)
and country
and country.data.get('request_funding', False)):
resp['credentials_file'] = True
return flask.jsonify(resp)
示例2: settings_category_add
def settings_category_add(meeting_id):
sugar.get_object_or_404(models.Meeting, id=meeting_id)
categories = flask.request.form.getlist('categories')
for categ in categories:
models.CategoryMeeting.create(meeting_id=meeting_id, category_id=categ)
return flask.redirect(flask.url_for('.settings_category_index',
meeting_id=meeting_id))
示例3: event_delete
def event_delete(meeting_id, event_id):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
event = sugar.get_object_or_404(models.Event, id=event_id)
event.delete_instance()
return flask.jsonify({
'status': 'success',
'url': flask.url_for('.events', meeting_id=meeting_id)
})
示例4: questions_delete
def questions_delete(meeting_id, question_id):
sugar.get_object_or_404(models.Meeting, id=meeting_id)
question = sugar.get_object_or_404(models.Question, id=question_id,
meeting_id=meeting_id)
question.delete_instance()
return flask.jsonify({
'status': 'success',
'url': flask.url_for('.questions', meeting_id=meeting_id)
})
示例5: update_attendance
def update_attendance(meeting_id, person_id, field):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
person = sugar.get_person_or_404(meeting_id, person_id)
person_meeting = sugar.get_object_or_404(models.PersonMeeting,
person=person_id, meeting=meeting_id)
status = person_meeting.data['meeting_flags_%s' % field]
person_meeting.data['meeting_flags_%s' % field] = '1' if not status else ''
person_meeting.save()
return flask.jsonify({'status': 'success'})
示例6: settings_fee_index
def settings_fee_index(meeting_id):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
fees = meeting.get_fees
return {
'fees': fees,
'meeting': meeting,
}
示例7: questions
def questions(meeting_id):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
questions = meeting.get_questions()
return {
'meeting': meeting,
'questions': questions
}
示例8: media_file
def media_file(meeting_id, file_type, media_person_id=None, person_id=None):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
if media_person_id:
person = sugar.get_media_person_or_404(meeting_id, media_person_id)
redirect_url = flask.url_for('.view', meeting_id=meeting.id,
media_person_id=person.id)
elif person_id:
person = sugar.get_person_or_404(meeting_id, person_id)
redirect_url = flask.url_for('participant.view',
meeting_id=meeting.id,
person_id=person.id)
else:
flask.abort(400)
app = flask.current_app
media_file = flask.request.files[file_type]
if media_file:
# delete old file
if person.data.get(file_type):
try:
app.config['UPLOADED_FILES_DEST'].joinpath(
person.data[file_type]).unlink()
except OSError:
pass
filename = '%s_%s.' % (
secure_filename(person.decoded_data['personal_last_name']),
file_type)
media_file_name = files.save(media_file, name=filename) if media_file else ''
person.data[file_type] = media_file_name
person.save()
return flask.redirect(redirect_url)
示例9: envelope_print
def envelope_print(meeting_id, person_id):
app = flask.current_app
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
person = sugar.get_person_or_404(meeting_id, person_id)
secretariat = refdata.secretariat
temp = path(tempfile.mkdtemp())
flask.g.pdf_compatible = True
country_names = []
try:
country_names = refdata.translated_country_names[
person.data['personal_country']]
except KeyError:
pass
context = dict(meeting=meeting,
person=person,
path=app.root_path,
secretariat=secretariat,
country_names=country_names)
return sugar.render_pdf('participant/person_envelope.html',
temp=temp,
height='6.4in',
width='9.0in',
context=context,
filename=secure_filename(person.name),
use_wkhtmltopdf=True)
示例10: badge_misc_pdf
def badge_misc_pdf(meeting_id, badge_type):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
temp = path(tempfile.mkdtemp())
app = flask.current_app
if badge_type == 'visitor':
category = models.Category.select().where(
data__contains={'name_E': 'Visitor'}).get()
elif badge_type == 'security':
category = models.Category.select().where(
data__contains={'name_E': 'Security'}).get()
elif badge_type == 'exhibitor':
category = models.Category.select().where(
data__contains={'name_E': 'Exhibitor'}).get()
elif badge_type == 'host_government':
category = models.Category.select().where(
data__contains={'name_E': 'Host Government'}).get()
elif badge_type == 'local_staff':
category = models.Category.select().where(
data__contains={'name_E': 'Local staff'}).get()
else:
flask.abort(400)
context = {
'meeting': meeting,
'category': category,
'badge_type': badge_type,
'path': app.root_path,
'background_path': app.config['UPLOADED_BACKGROUNDS_DEST'],
}
return sugar.render_pdf('participant/badge_misc_simple.html', temp=temp,
height="2.15in", width="3.4in", context=context,
filename=sugar.random_string(6),
use_wkhtmltopdf=True)
示例11: badge_misc
def badge_misc(meeting_id, badge_type):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
if badge_type == 'visitor':
category = models.Category.select().where(
data__contains={'name_E': 'Visitor'}).get()
elif badge_type == 'security':
category = models.Category.select().where(
data__contains={'name_E': 'Security'}).get()
elif badge_type == 'exhibitor':
category = models.Category.select().where(
data__contains={'name_E': 'Exhibitor'}).get()
elif badge_type == 'host_government':
category = models.Category.select().where(
data__contains={'name_E': 'Host Government'}).get()
elif badge_type == 'local_staff':
category = models.Category.select().where(
data__contains={'name_E': 'Local staff'}).get()
else:
flask.abort(400)
return {
'meeting': meeting,
'category': category,
'badge_type': badge_type,
}
示例12: revert_photo
def revert_photo(meeting_id, person_id):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
person = sugar.get_person_or_404(meeting_id, person_id)
url = flask.url_for('participant.crop_photo_view',
meeting_id=meeting.id,
person_id=person.id)
return _revert_photo(meeting, person, url)
示例13: view_pdf
def view_pdf(meeting_id, person_id):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
person = sugar.get_person_or_404(meeting_id, person_id)
labeled = schema.common.labels_for_values(person.data, meeting_id)
category = sugar.get_person_category_or_404(meeting_id,
category_id=person.category_id(meeting.id))
phrases = {p.data['name']: p for p in meeting.get_phrases}
event_form = EventCitesForm(meeting_model=meeting, person=person)
# render form in participant language
participant_lang = {"E": "en", "S": "es", "F": "fr"}.get(person.lang, "E")
sugar.set_lang(participant_lang)
pdf = sugar.generate_pdf_from_html(
flask.render_template('participant/credentials.html', **{
'person': person,
'category': category,
'meeting': meeting,
'labeled': labeled,
'phrases': phrases,
'credentials_strings': refdata.credentials_strings,
'event_form': event_form,
})
)
return flask.Response(response=pdf, mimetype='application/pdf')
示例14: view
def view(meeting_id, person_id):
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
person = sugar.get_person_or_404(meeting_id, person_id)
page_info = {}
page_info['picture'] = {
'edit_url': flask.url_for('participant.edit_photo',
meeting_id=meeting.id,
person_id=person.id),
'remove_url': flask.url_for('participant.remove_photo',
meeting_id=meeting.id,
person_id=person.id),
'url': person.image_file,
'rotate_url': flask.url_for('participant.rotate_photo',
meeting_id=meeting.id,
person_id=person.id),
'crop_url': flask.url_for('participant.crop_photo_view',
meeting_id=meeting.id,
person_id=person.id),
}
event_form = EventCitesForm(meeting_model=meeting, person=person)
return {
'meeting': meeting,
'person': person,
'page_info': page_info,
'event_form': event_form,
}
示例15: badge_print
def badge_print(meeting_id, person_id, person_type):
app = flask.current_app
meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
if person_type == 'person':
person = sugar.get_person_or_404(meeting_id, person_id)
else:
person = sugar.get_media_person_or_404(meeting_id, person_id)
badge = flask.request.args.get('badge', None)
# create a temporary folder and save participant photo to disk
temp = path(tempfile.mkdtemp())
photo = person.data.get('photo', None)
if photo:
person.photo_url = app.config['UPLOADED_PHOTOS_DEST'] / photo
else:
person.photo_url = None
# save badge as html
context = dict(meeting=meeting, person=person, path=app.root_path,
background_path=app.config['UPLOADED_BACKGROUNDS_DEST'],
badge=badge, person_type=person_type)
return sugar.render_pdf("participant/person_badge_simple.html", temp=temp,
height="2.15in", width="3.4in", context=context,
filename=secure_filename(person.name),
use_wkhtmltopdf=True)