本文整理汇总了Python中app.models.Event.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Event.objects方法的具体用法?Python Event.objects怎么用?Python Event.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Event
的用法示例。
在下文中一共展示了Event.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: event
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def event(slug):
"""View a specific non-recurring event, or the next upcoming instance of
a recurring event.
**Route:** ``/events/<slug>``
**Methods:** ``GET``
:param str slug: The unique slug ID for the post.
"""
if Event.objects(published=True, slug=slug).count() == 0:
abort(404) # Either invalid event ID or duplicate IDs.
event = Event.objects(published=True, slug=slug)[0]
if event.is_recurring:
upcoming_event_instances = (Event.objects(published=True,
start_date__gte=date.today(),
slug=slug)
.order_by('start_date'))
if upcoming_event_instances:
event = upcoming_event_instances[0]
else:
event = event.parent_series.events[-1]
return render_template('events/event.html',
event=event,
now=now,
upcoming_events=_upcoming_events_triple(event))
示例2: events
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def events():
"""View the latest events.
**Route:** ``/events``
**Methods:** ``GET``
"""
today = date.today()
last_sunday = datetime.combine(today - timedelta(days=today.isoweekday()+7),
datetime.min.time())
next_sunday = datetime.combine(today + timedelta(days=7-today.isoweekday()),
datetime.min.time())
recent_and_upcoming = Event.objects(published=True,
start_date__gt=last_sunday).order_by('start_date',
'start_time')
recent_events = recent_and_upcoming.filter(end_date__lt=today)
events_this_week = recent_and_upcoming.filter(end_date__gte=today,
start_date__lt=next_sunday)
upcoming_events = recent_and_upcoming.filter(start_date__gt=next_sunday)[:4]
more_past_events = bool(Event.objects(published=True,
start_date__lte=last_sunday).count())
return render_template('events/events.html',
recent_events=recent_events,
events_this_week=events_this_week,
upcoming_events=upcoming_events,
more_past_events=more_past_events)
示例3: recurring_event
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def recurring_event(slug, index):
"""View a specific instance of a recurring event.
**Route:** ``/events/<slug>/<index>``
**Methods:** ``GET``
:param str slug: The unique slug ID for the post.
:param int index: The instance of the event to fetch.
"""
if Event.objects(published=True, slug=slug).count() == 0:
abort(404) # Either invalid event ID or duplicate IDs.
event = Event.objects(published=True, slug=slug)[0]
if not event.is_recurring or not event.parent_series:
return redirect(url_for('.event', slug=slug))
if len(event.parent_series.events) <= index:
abort(404)
event = event.parent_series.events[index]
return render_template('events/event.html',
event=event,
now=now,
upcoming_events=_upcoming_events_triple(event))
示例4: test_create_event_model
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def test_create_event_model(self):
"""Test creating an event with the proper data"""
self.assertEqual(Event.objects(creator=self.USER).count(), 0)
e = self.make_event()
e.save()
self.assertEqual(Event.objects(creator=self.USER).count(), 1)
self.assertEqual(Event.objects().get(creator=self.USER), e)
示例5: _get_events_for_template
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def _get_events_for_template(past, future):
"""Returns the events to insert in the events template. Returns four
groups of dates:
- ``past_events``: A list of dictionaries, where the dictionaries contain a
list of events for a week, and a label for the week.
- ``this_week``: A list of events happening this week.
- ``next_week``: A list of events happening next week.
- ``future_events``: A list of dictionaries similar to ``post_events``,
but for events happening in the future.
:returns: ``past_events``, ``this_week``, ``next_week``, ``future_events``
"""
today = date.today()
last_sunday = datetime.combine(
today - timedelta(days=(today.isoweekday() % 7)),
datetime.min.time()
)
next_sunday = last_sunday + timedelta(days=7)
following_sunday = last_sunday + timedelta(days=14)
this_week = (Event.objects(start_date__gte=last_sunday,
start_date__lt=next_sunday)
.order_by('start_date'))
next_week = (Event.objects(start_date__gte=next_sunday,
start_date__lt=following_sunday)
.order_by('start_date'))
past_events = []
future_events = []
for week_no in range(past):
ending_sunday = last_sunday - timedelta(days=7 * week_no)
starting_sunday = last_sunday - timedelta(days=7 * (week_no + 1))
week_name = _format_for_display(starting_sunday)
events = Event.objects(start_date__gte=starting_sunday,
start_date__lt=ending_sunday)
past_events.insert(0, {
'week_name': week_name,
'events': events,
})
for week_no in range(future):
starting_sunday = following_sunday + timedelta(days=7 * week_no)
ending_sunday = following_sunday + timedelta(days=7 * (week_no + 1))
week_name = _format_for_display(starting_sunday)
events = Event.objects(start_date__gte=starting_sunday,
start_date__lt=ending_sunday)
future_events.append({
'week_name': week_name,
'events': events,
})
return past_events, this_week, next_week, future_events
示例6: test_delete_event_when_event_exists
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def test_delete_event_when_event_exists(self):
"""Test that when an event with id `_id` exists in the database and the
`/admin/events/delete/_id` route is POSTed to, it is deleted.
"""
e = self.make_event()
e.save()
print str(Event.objects())
self.assertEqual(Event.objects(creator=e.creator).count(), 1)
_id = e.id
resp = self.request_with_role('/admin/events/delete/%s' % _id, method="POST",
follow_redirects=True)
self.assertEqual(resp.status_code, 200)
self.assertEqual(Event.objects(creator=e.creator).count(), 0)
示例7: delete
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def delete(event_id):
""""""
object_id = ObjectId(event_id)
form = DeleteEventForm(request.form)
if Event.objects(id=object_id).count() == 1:
event = Event.objects().with_id(object_id)
try:
EventsHelper.delete_event(event, form)
except GoogleCalendarAPIError as e:
flash(e.message)
else:
flash('Invalid event id')
return redirect(url_for('.index'))
示例8: index
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def index():
"""View the ADI homepage.
**Route:** ``/``
**Methods:** ``GET``
"""
this_moment = datetime.now().time()
# cast date.today() to a datetime
today = datetime.combine(date.today(), datetime.min.time())
# Ending on a future date, or today at a future time. The events should be
# published, and should be chronological.
# We limit to four events, one large event and one set of three events.
events = (Event.objects(Q(end_date__gte=today))
# |
# Q(end_date=today, end_time__gt=this_moment)) #
.filter(published=True)
.order_by('start_date', 'start_time')
.limit(ONE_LARGE_AND_TRIPLE))
# sort published posts chronologically back in time
all_blog_posts = (BlogPost.objects(published=True)
.order_by('-date_published'))
latest_blog_post = all_blog_posts[0] if all_blog_posts else None
return render_template('index.html',
events=events,
blog_post=latest_blog_post)
示例9: unpublish_event
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def unpublish_event(self, stale_event):
"""Unpublish an event, moving it to the private calendar.
The first argument is called ``stale_event`` because it might have
outdated fields. The first thing we do is find a fresh event with it's
id in mongo.
:param stale_event: The event to publish
:type event: :class:`Event`
:raises: :class:`GoogleCalendarAPIBadStatusLine`,
:class:`GoogleCalendarAPIErrorNotFound`,
:class:`GoogleCalendarAPIError`,
:class:`GoogleCalendarAPIMissingID`
:returns: The Google Calendar API response.
:rtype: dict
"""
# Freshen up stale_event
event = Event.objects().get(id=stale_event.id)
if event.published:
raise GoogleCalendarAPIError('Event must have published as `False` before unpublishing')
return self.move_event(event, from_id=self.public_calendar_id,
to_id=self.private_calendar_id)
示例10: event_archive
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def event_archive(index):
"""View old events.
**Route:** ``/events/<index>``
**Methods:** ``GET``
:param int index: The page to fetch
"""
if index <= 0:
return redirect(url_for('.events'))
# Get all events that occur on this page or on subsequent pages, and order
# them chronologically back in time
today = date.today()
events = (Event.objects(published=True, end_date__lt=today)
.order_by('-start_date')
.skip(NUM_PAST_EVENTS_FOR_FRONTPAGE +
(index - 1) * NUM_EVENTS_PER_PAGE))
# If there are no such events, redirect to the pevious page
if not events:
return redirect(url_for('.event_archive', index=index - 1))
# There is always a previous page, but there is only a next page if there
# are more events after this page
previous_index = index - 1
next_index = index + 1 if len(events) > NUM_EVENTS_PER_PAGE else None
# Use .limit() to only show NUM_EVENTS_PER_PAGE events per page
return render_template('events/archive.html',
events=events.limit(NUM_EVENTS_PER_PAGE),
previous_index=previous_index,
next_index=next_index)
示例11: unpublish_event
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def unpublish_event(self, stale_event):
"""Unpublish an event, moving it to the private calendar.
The first argument is called ``stale_event`` because it might have
outdated fields. The first thing we do is find a fresh event with it's
id in mongo.
:param stale_event: The event to publish
:type event: :class:`Event`
:raises: :class:`EventumError.GCalAPI.BadStatusLine`,
:class:`EventumError.GCalAPI.NotFound`,
:class:`EventumError.GCalAPI.Error`,
:class:`EventumError.GCalAPI.MissingID`
:returns: The Google Calendar API response.
:rtype: dict
"""
self.before_request()
# Freshen up stale_event
event = Event.objects().get(id=stale_event.id)
if event.published:
raise EventumError.GCalAPI.PublishFailed.PublishedTrue()
return self.move_event(event, from_id=self.public_calendar_id,
to_id=self.private_calendar_id)
示例12: unique_with_database
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def unique_with_database(form, field):
message = "An event with that slug already exists."
from app.models import Event, EventSeries
if EventSeries.objects(slug=field.data).count() != 0:
raise ValidationError(message)
if Event.objects(slug=field.data).count() != 0:
raise ValidationError(message)
示例13: event_archive
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def event_archive(index):
"""View old events.
**Route:** ``/events/<index>``
**Methods:** ``GET``
:param int index: The page to fetch
"""
index = int(index)
if index <= 0:
return redirect(url_for('.events'))
today = date.today()
last_sunday = datetime.combine(today - timedelta(days=today.weekday()+7),
datetime.min.time())
past_events=Event.objects(published=True,
start_date__lt=last_sunday).order_by('start_date')
if not past_events:
return redirect(url_for('.events'))
previous_index = index - 1
next_index = index + 1 if len(past_events) > 10*index else None
return render_template('events/archive.html',
events=past_events[10*(index-1):10*(index)],
previous_index=previous_index,
next_index=next_index)
示例14: update_event
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def update_event(self, stale_event, as_exception=False):
""""""
event = Event.objects().get(id=stale_event.id)
if not event.gcal_id:
self.create_event(stale_event)
raise GoogleCalendarAPIMissingID('Missing gplus_id. Successfully fell back to create.')
resource = None
resource = GoogleCalendarResourceBuilder.event_resource(event,
for_update=True)
calendar_id = self._calendar_id_for_event(event)
event_id_for_update = event.gcal_id
if as_exception:
instance = self._instance_resource_for_event_in_series(event)
instance.update(resource)
resource = instance
event_id_for_update = instance['id']
print '[GOOGLE_CALENDAR]: Update Event'
request = self.service.events().update(calendarId=calendar_id,
eventId=event_id_for_update,
body=resource)
try:
updated_event = self._execute_request(request)
except GoogleCalendarAPIErrorNotFound as e:
self.create_event(event)
print e.message
raise GoogleCalendarAPIErrorNotFound('Couldn\'t find event to update. '
'Successfully fell back to create.')
self._update_event_from_response(event, updated_event)
return updated_event
示例15: edit
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import objects [as 别名]
def edit(event_id):
""""""
try:
event = Event.objects().get(id=event_id)
except (DoesNotExist, ValidationError):
flash('Cannont find event with id "%s"' % event_id)
return redirect(url_for('.index'))
form = EditEventForm(request.form) if request.method == 'POST' else \
EventsHelper.create_form(event, request)
if form.validate_on_submit():
try:
EventsHelper.update_event(event, form)
except GoogleCalendarAPIError as e:
flash(e.message)
return redirect(url_for('.index'))
if form.errors:
for error in form.errors:
for message in form.errors[error]:
flash(message)
delete_form = DeleteEventForm()
upload_form = UploadImageForm()
images = Image.objects()
return render_template('admin/events/edit.html', form=form, event=event,
delete_form=delete_form, upload_form=upload_form,
images=images)