本文整理汇总了Python中models.Event.organisations方法的典型用法代码示例。如果您正苦于以下问题:Python Event.organisations方法的具体用法?Python Event.organisations怎么用?Python Event.organisations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Event
的用法示例。
在下文中一共展示了Event.organisations方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: events
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import organisations [as 别名]
def events(id=None):
if id:
event = Event.objects.get(pk=id)
event.update_timezone()
add_form = EventForm(request.form, obj=event)
title_aside = u'Éditer l\'événement'
else:
event = Event()
add_form = EventForm()
title_aside = u'Créer un événement'
if add_form.organisations.data:
add_form.organisations.choices = make_choices(add_form.orgas_choices, selected=add_form.organisations.data, name='Organisations')
if add_form.places.data:
add_form.places.choices = make_choices(add_form.places_choices, selected=add_form.places.data, name='Lieux')
if add_form.validate_on_submit():
event.title = add_form.title.data
event.description = add_form.description.data
event.organisations = add_form.organisations.data
event.places = add_form.places.data
if not event.author:
event.author = current_user.to_dbref()
event.datetime_first = arrow.get(add_form.datetime_first.data).datetime
event.datetime_last = arrow.get(add_form.datetime_last.data).datetime
event.update_timezone()
if current_user.has_role('Administrateur') or current_user.has_role('Éditeur'):
event.status = 'published' if 'publish' in request.form else 'draft'
else:
event.status = 'validation' if 'publish' in request.form else 'draft'
event.save()
if id:
return redirect('/events')
# Filter the events for non-admin users
if not current_user.has_role('Administrateur'):
filter_role = {'organisations__in': current_user.associations}
else:
filter_role = {}
today = arrow.now().date()
events_draft = Event.objects(status='draft', **filter_role).order_by('datetime_first')
events_validation = Event.objects(status='validation', datetime_first__gte=today, **filter_role).order_by('datetime_first')
events_published = Event.objects(status='published', datetime_first__gte=today).order_by('datetime_first')
return render_template('events.html', events_draft=events_draft, events_validation=events_validation, events_published=events_published, add_form=add_form, title_aside=title_aside, icons=icons)