本文整理汇总了Python中models.Event.put方法的典型用法代码示例。如果您正苦于以下问题:Python Event.put方法的具体用法?Python Event.put怎么用?Python Event.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Event
的用法示例。
在下文中一共展示了Event.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def post(self):
entity_key_urlsafe = self.request.get("entity_key")
if (self.request.get('type') == 'Event'):
if entity_key_urlsafe:
event_key = ndb.Key(urlsafe=entity_key_urlsafe)
event = event_key.get()
timestamp = datetime.datetime.strptime(self.request.get("date"), "%Y-%m-%dT%H:%M")
event.date = timestamp.date()
event.time = timestamp.time()
event.title = self.request.get("title")
event.description = self.request.get("description")
event.put()
else:
timestamp = datetime.datetime.strptime(self.request.get("date"), "%Y-%m-%dT%H:%M")
new_event = Event(parent=PARENT_KEY,
date=timestamp.date(),
time=timestamp.time(),
title=self.request.get('title'),
description=self.request.get('description'))
new_event.put()
elif (self.request.get('type') == 'Announcement'):
if entity_key_urlsafe:
announcement_key = ndb.Key(urlsafe=entity_key_urlsafe)
announcement = announcement_key.get()
announcement.title = self.request.get("title")
announcement.description = self.request.get("description")
announcement.put()
else:
new_announcement = Announcement(parent=PARENT_KEY,
title=self.request.get('title'),
description=self.request.get('description'))
new_announcement.put()
self.redirect(self.request.referer)
示例2: event_examples
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def event_examples():
"""List all events"""
event = Event.query()
form = EventForm()
if form.validate_on_submit():
event = Event(
#event_id=
title=form.title.data,
day=form.day.data,
location=form.location.data,
description=form.descrtiption.data,
anchor_amount=form.anchor_amount.data,
amount_min=form.amount_min.data,
max_attendees=form.max_attendees.data,
registration_start=form.registration_start.data,
registration_end=form.registration_end.data,
added_by=users.get_current_user()
)
try:
event.put()
event_id = event.key.id()
flash(u'Event %s successfully saved.' % event_id, 'success')
return redirect(url_for('event_examples'))
except CapabilityDisabledError:
flash(u'App Engine Datastore is currently in read-only mode.', 'info')
return redirect(url_for('event_examples'))
return render_template('event_gae.html', event=event, form=form)
示例3: call_api
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def call_api(service, data):
'''Submit service status to API'''
service = Service.get_by_slug(service)
status = Status.get_by_slug(data['status'])
e = Event(service=service, status=status, message=data['message'])
print json.dumps(data, sort_keys=True, skipkeys=True)
e.put()
示例4: save
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def save(self):
site=get_site()
timezone=pytz.timezone(site.timezone)
cleaned_data=self.cleaned_data
profile=get_current_profile()
if profile.userlevel > 9:
credit_name, credit_link= "Staff", None
status='approved'
approved_on=datetime.now()
else:
credit_name, credit_link = profile.nickname, profile.link
status='submitted'
approved_on=None
event=Event(title=cleaned_data.get("title"),
link=cleaned_data.get("link") or None,
description=cleaned_data.get("description")[:250] or None,
start=timezone.localize(datetime.combine(cleaned_data.get("start_date"),cleaned_data.get("start_time"))),
end=timezone.localize(datetime.combine(cleaned_data.get("end_date") or cleaned_data.get("start_date"),cleaned_data.get("end_time"))),
location=cleaned_data.get("location") or None,
submitted_by=get_current_profile(),
status=status,
site=get_site(),
cost=cleaned_data.get("cost"),
credit_name=credit_name,
credit_link=credit_link,
approved_on=approved_on,
approved_by=profile,
)
event.put()
return event
示例5: event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def event(id, name):
time_now = (int)(time.time())
hourly = time_now - (time_now % 3600)
key = ndb.Key("Agent",id, "EventType", name, "Script", "random.py", "Hourly", hourly, "Event", time_now)
event = Event(key=key, name=name, script="random.py", timestamp=datetime.utcfromtimestamp(time_now), body="Test")
event.put()
return "OK"
示例6: serverisup
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def serverisup (service):
# Create a new event with the given status and given service
service = Service.get_by_slug(service)
status = Status.get_by_slug("up")
e = Event(service=service, status=status, message="The server is responding.")
e.put()
示例7: serverisdown
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def serverisdown (service):
# Create a new event with the given status and given service
service = Service.get_by_slug(service)
status = Status.get_by_slug("down")
e = Event(service=service, status=status, message="The server could not be reached")
e.put()
示例8: create_event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def create_event(user, **kwargs):
"""
server endpoint for creation of events
events are created by the user of the neuaer plugin. for example
when the user wants to invoke the plugin event upon bluetooth disconnection
"""
req = CreateEventRequest(request, settings.EVENT)
if not req.is_valid():
return jsonify(**req.error_message)
event_props = {
'slug' : req.event.get('event_id', None),
'redirect': req.event.get('after_config_redirect', None),
'user': user
}
event = Event.get_with_slug_user(**event_props)
# create the event if it doesn't already exist
if not event:
event = Event(**event_props)
event.put()
else:
return jsonify(**error_responses('create_event', 'event_exists'))
return jsonify(success="created")
示例9: post
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def post(self):
user = users.get_current_user()
try:
start_time = datetime.strptime('%s %s:%s %s' % (
self.request.get('date'),
self.request.get('start_time_hour'),
self.request.get('start_time_minute'),
self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p')
end_time = datetime.strptime('%s %s:%s %s' % (
self.request.get('date'),
self.request.get('end_time_hour'),
self.request.get('end_time_minute'),
self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p')
conflicts = Event.check_conflict(start_time,end_time,self.request.get_all('rooms'))
if conflicts:
raise ValueError('Room conflict detected')
if not self.request.get('estimated_size').isdigit():
raise ValueError('Estimated number of people must be a number')
if not int(self.request.get('estimated_size')) > 0:
raise ValueError('Estimated number of people must be greater then zero')
if (end_time-start_time).days < 0:
raise ValueError('End time must be after start time')
if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ):
raise ValueError( 'Phone number does not appear to be valid' )
else:
event = Event(
name = cgi.escape(self.request.get('name')),
start_time = start_time,
end_time = end_time,
type = cgi.escape(self.request.get('type')),
estimated_size = cgi.escape(self.request.get('estimated_size')),
contact_name = cgi.escape(self.request.get('contact_name')),
contact_phone = cgi.escape(self.request.get('contact_phone')),
details = cgi.escape(self.request.get('details')),
url = cgi.escape(self.request.get('url')),
fee = cgi.escape(self.request.get('fee')),
notes = cgi.escape(self.request.get('notes')),
rooms = self.request.get_all('rooms'),
expired = local_today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date
)
event.put()
log = HDLog(event=event,description="Created new event")
log.put()
notify_owner_confirmation(event)
notify_new_event(event)
set_cookie(self.response.headers, 'formvalues', None)
self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name)))
except Exception, e:
message = str(e)
if 'match format' in message:
message = 'Date is required.'
if message.startswith('Property'):
message = message[9:].replace('_', ' ').capitalize()
# This is NOT a reliable way to handle erorrs
#set_cookie(self.response.headers, 'formerror', message)
#set_cookie(self.response.headers, 'formvalues', dict(self.request.POST))
#self.redirect('/new')
error = message
self.response.out.write(template.render('templates/error.html', locals()))
示例10: event_insert
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def event_insert(self, request):
"""insert or update an event"""
if request.from_datastore:
my_event = request
else:
my_event = Event(parent=main.PARENT_KEY, date=request.date, time=request.time, title=request.title, description=request.description)
my_event.put()
return my_event
示例11: process_event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def process_event(event_file, user):
event_data = json.loads(event_file)
event_name = event_data['name']
event_place = event_data['place']
event_date_from = datetime.strptime(event_data['date_from'], '%Y-%m-%d').date()
event_date_to = datetime.strptime(event_data['date_to'], '%Y-%m-%d').date()
event_timezone = event_data['timezone']
if 'description' in event_data:
event_description = event_data['description']
else:
event_description = ''
ev = Event(owner=user,
name=event_name,
place=event_place,
date_from=event_date_from,
date_to=event_date_to,
timezone=event_timezone,
description=event_description,
data=event_data
)
ev.put()
for session in event_data['sessions']:
session_name = session['name']
session_room = session['room']
tr = Session(owner=user,
name=session_name,
room=session_room,
event=ev.key)
tr.put()
for talk in session['talks']:
talk_title = talk['title']
talk_authors = talk['authors']
talk_start = datetime.strptime(talk['start'], '%Y-%m-%d %H:%M')
talk_end = datetime.strptime(talk['end'], '%Y-%m-%d %H:%M')
if 'tags' in talk:
talk_tags = talk['tags']
else:
talk_tags = []
if 'abstract' in talk:
talk_abstract = talk['abstract']
else:
talk_abstract = ''
tk = Talk(owner=user,
session=tr.key,
title=talk_title,
authors=talk_authors,
start=talk_start,
end=talk_end,
tags=talk_tags,
abstract=talk_abstract
)
tk.put()
示例12: test_history_no_errors_boundary
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def test_history_no_errors_boundary(self):
down = Status.get_by_slug("down")
up = Status.get_by_slug("up")
now = datetime(2011, 4, 5)
event = Event(status=down, service=self.service, start=now, message="HEY")
event.put()
history = self.service.history(5, up, start=date(2011, 4, 5))
self.assertEquals(history[0]["information"], False)
示例13: post
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def post(self):
# TODO: sanity test
group = self.request.get('group')
vendor = self.request.get('vendor')
event = Event(group = Group.get_by_id(long(group)),
vendor = Vendor.get_by_id(long(vendor)),
advocate = users.get_current_user())
event.put()
self.redirect('/u/mine/profile')
示例14: test_history_current_status
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def test_history_current_status(self):
down = Status.get_by_slug("down")
up = Status.get_by_slug("up")
now = datetime(2011, 4, 4, 12, 51)
event = Event(status=down, service=self.service, start=now, message="HEY")
event.put()
history, = self.service.history(1, up, start=date(2011, 4, 5))
self.assertEquals(history["information"], True)
示例15: add
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import put [as 别名]
def add(request):
user = users.get_current_user()
if request.POST and user:
post_date = request.POST.get('date', False)
date = datetime.date(*time.strptime(post_date, '%Y-%m-%d')[:3])
event = Event(date=date, owner=user)
event.put()
return HttpResponse("Successed at marking the date %s." % date)
return HttpResponse("Failure.")