本文整理汇总了Python中models.Conference类的典型用法代码示例。如果您正苦于以下问题:Python Conference类的具体用法?Python Conference怎么用?Python Conference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_createSession
def test_createSession(self):
test_url = '/conference/{wcksafe}/session'
# Ensure default profile is created
url = '/profile'
res = urlfetch.fetch(self.urlbase + url, method='GET')
self.assertEqual(res.status_code, 200)
# Create conference and get websafe key
conf = Conference(
name='Test Conference',
organizerUserId=json.loads(res.content)['mainEmail']
)
wck = conf.put()
sleep(0.1)
wcksafe = wck.urlsafe()
test_url = test_url.format(wcksafe=wcksafe)
# Ensure no sessions exist yet
self.assertEqual(0, len(Session.query().fetch(5)))
# Test endpoint
params = {
'name': 'TEST Session',
'date': '2015-8-10',
'startTime': '9:10',
'conferenceKey': wcksafe
}
response = urlfetch.fetch(self.urlbase + test_url,
payload=json.dumps(params),
method=urlfetch.POST,
headers={'Content-Type': 'application/json'})
self.assertEqual(response.status_code, 200)
示例2: test_getSessionsBySpeaker
def test_getSessionsBySpeaker(self):
# Create two conferences
conf = Conference(name='Test Conference A')
wckA = conf.put()
wckAsafe = wckA.urlsafe()
conf = Conference(name='Test Conference B')
wckB = conf.put()
wckBsafe = wckB.urlsafe()
# Add 4 sessions among conferences with three having particular speaker
propsA = {'name': 'Monkey Business', 'date': date(2015,8,8),
'parent': wckA, 'conferenceKey': wckAsafe,
'typeOfSession': 'lecture', 'startTime': time(18,15)}
propsB = {'name': 'Monkey Business', 'date': date(2015,9,12),
'parent': wckB, 'conferenceKey': wckBsafe,
'typeOfSession': 'workshop', 'startTime': time(12,15)}
# Add two to first created conference
Session(speaker=['Sarah', 'Frodo'], **propsA).put()
Session(speaker=['Frodo'], **propsA).put()
# Add two to second created conference
Session(speaker=['Saruman'], **propsB).put()
Session(speaker=['Gollum', 'Frodo'], **propsB).put()
# Test the endpoint
url = '/speaker/{0}'.format('Frodo')
res = urlfetch.fetch(self.urlbase + url)
self.assertEqual(res.status_code, 200)
self.assertEqual(len(json.loads(res.content)['items']), 3)
示例3: getMarketableConferences
def getMarketableConferences(self, request):
"""Find the conferences that is in progress and not yet fully booked"""
mtoday = datetime.now().date()
# Get conferences with seats available
conf_inprogress_seatsavail = set(
Conference.query().filter(
Conference.seatsAvailable > 0).fetch(keys_only=True))
# Get conferences where open end date is more or equal than today
conf_inprogress_enddate = set(
Conference.query().filter(Conference.endDate >= mtoday).fetch(
keys_only=True))
# Get conferences where open start date is less than or equal to today
conf_inprogress_startdate = set(
Conference.query().filter(Conference.startDate <= mtoday).fetch(
keys_only=True))
# return a set with conferences common in all queries
conf_inprogress_keys = conf_inprogress_seatsavail\
& conf_inprogress_startdate\
& conf_inprogress_enddate
conf_inprogress = ndb.get_multi(conf_inprogress_keys)
return MarketableConferenceForms(items=[
MarketableConferenceForm(name=getattr(data, "name"),
topics=getattr(data, "topics"),
city=getattr(data, "city"),
seatsAvailable=getattr(data,
"seatsAvailable"),
endDate=str(getattr(data, "endDate")))
for data in conf_inprogress])
示例4: match_or_send_to_waiting_room
def match_or_send_to_waiting_room(call, schedule):
# Refreshing database object
flush_transaction()
call.reload()
if call.matched:
other = call.conference.call_set.exclude(pk=call.pk)[0]
data = send_to_conference_room(call, schedule, other, initial=False)
if data: return data
matchcall = find_match(schedule, call)
if matchcall:
conf = Conference()
conf.maxcapacity = 2
conf.datecreated = as_date(schedule)
conf.save()
call.conference = conf
call.matched = True
call.save()
matchcall.conference = conf
matchcall.matched = True
matchcall.save()
data = send_to_conference_room(call, schedule, matchcall, initial=True)
if data: return data
if call.user.profile.any_match:
call.user.profile.any_match = False
call.user.profile.save()
return render_to_response("twilioresponse.xml", { 'say' :"We are very sorry - We could not find you a match today, but tomorrow we'll do our best to compensate it! We wish you an awesome day!",
'hangup' : True })
#Check if we have exceeded the waiting redirect limits
elif call.retries >= REDIRECT_LIMIT:
# The user has reached the limit of redials, so hang up
logger.debug("LIMIT RETRIES - Ask to try to match with any person")
any_match = "We could not find any matches. If you'd like us to try to match you with Anyone please press any number now."
goodbye = "We wish you an Amazing day! Good bye!"
return render_to_response("twilioresponse.xml", { 'any_match' :any_match, 'schedule': schedule, 'hangup': True, 'goodbye' : goodbye })
call.retries = call.retries + 1
call.save()
# Send user to private conference (Conferencename=Username) or send them to the waiting room they were at
return send_to_waiting_room( HOLD_LIMIT
, schedule
, call.user.username
, False
, "Please bare with us - we'll find the best match for you!")
示例5: _createConferenceObject
def _createConferenceObject(self, conferenceForm):
"""Create conference object, returns ConferenceForm."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
data = formToDict(conferenceForm, exclude=('websafeKey', 'organizerDisplayName'))
# add default values for those missing
for df in DEFAULTS:
if data[df] in (None, []):
data[df] = DEFAULTS[df]
# add organizerUserId before checking the required fields
data['organizerUserId'] = user_id = getUserId(user)
# check required fields
for key in Conference.required_fields_schema:
if not data[key]:
raise endpoints.BadRequestException("Conference '%s' field required" % key)
# convert dates from strings to Date objects; set month based on start_date
try:
data['startDate'] = datetime.strptime(data['startDate'][:10], "%Y-%m-%d").date()
data['endDate'] = datetime.strptime(data['endDate'][:10], "%Y-%m-%d").date()
except (TypeError, ValueError):
raise endpoints.BadRequestException("Invalid date format. Please use 'YYYY-MM-DD'")
if data['startDate'] > data['endDate']:
raise endpoints.BadRequestException("start date must be before end date")
data['month'] = data['startDate'].month
# set seatsAvailable to be same as maxAttendees on creation
if data["maxAttendees"] > 0:
data["seatsAvailable"] = data["maxAttendees"]
# generate Profile Key based on user ID and Conference
# ID based on Profile key get Conference key from ID
p_key = ndb.Key(Profile, user_id)
c_id = Conference.allocate_ids(size=1, parent=p_key)[0]
c_key = ndb.Key(Conference, c_id, parent=p_key)
data['key'] = c_key
# create Conference, send email to organizer confirming
# creation of Conference & return (modified) ConferenceForm
conf = Conference(**data)
conf.put()
taskqueue.add(
params={'email': user.email(), 'conferenceInfo': repr(conferenceForm)},
url='/tasks/send_confirmation_email'
)
return conf.toForm()
示例6: get
def get(self, conf_handle = None):
request = self.wsgi_request
response = self.wsgi_response
c = self.context
if conf_handle:
conf_id = Conference.get_id_from_url_title(conf_handle)
c.conf = Conference.get(conf_id)
if c.conf:
return self.render_stuff('/index.html')
self.set_body("Please enter a valid conference handle..")
return self.render()
示例7: _createConferenceObject
def _createConferenceObject(self, request):
"""Create or update Conference object, returning ConferenceForm/request."""
# preload necessary data items
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
if not request.name:
raise endpoints.BadRequestException("Conference 'name' field required")
# copy ConferenceForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data['websafeKey']
del data['organizerDisplayName']
# add default values for those missing (both data model & outbound Message)
for df in DEFAULTS:
if data[df] in (None, []):
data[df] = DEFAULTS[df]
setattr(request, df, DEFAULTS[df])
# convert dates from strings to Date objects; set month based on start_date
if data['startDate']:
data['startDate'] = datetime.strptime(data['startDate'][:10], "%Y-%m-%d").date()
data['month'] = data['startDate'].month
else:
data['month'] = 0
if data['endDate']:
data['endDate'] = datetime.strptime(data['endDate'][:10], "%Y-%m-%d").date()
# set seatsAvailable to be same as maxAttendees on creation
# both for data model & outbound Message
if data["maxAttendees"] > 0:
data["seatsAvailable"] = data["maxAttendees"]
setattr(request, "seatsAvailable", data["maxAttendees"])
# make Profile Key from user ID
p_key = ndb.Key(Profile, user_id)
# allocate new Conference ID with Profile key as parent
c_id = Conference.allocate_ids(size=1, parent=p_key)[0]
# make Conference key from ID
c_key = ndb.Key(Conference, c_id, parent=p_key)
data['key'] = c_key
data['organizerUserId'] = request.organizerUserId = user_id
# create Conference & return (modified) ConferenceForm
conference = Conference(**data)
conference.put()
return request
示例8: getConferencesNotSoldOutInAmsterdam
def getConferencesNotSoldOutInAmsterdam(self, request):
""" Only show conferences in Amsterdam that are not sold out
"""
in_amsterdam = Conference.query(
Conference.city == 'Amsterdam')
not_sold_out = Conference.query(
Conference.seatsAvailable > 0)
confs = self._intersectQueries(in_amsterdam, not_sold_out)
names = self._getConferenceOrganisers(confs)
return ConferenceForms(
items=[self._copyConferenceToForm(
conf, names[conf.organizerUserId]) for conf in confs])
示例9: _createSessionObject
def _createSessionObject(self, request):
"""Create or update Session object, returning SessionForm/request."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
if not request.name:
raise endpoints.BadRequestException("Session 'name' field required")
# copy SessionForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data['websafeKey']
# del data['organizerDisplayName']
# add default values for those missing (both data model & outbound Message)
for df in DEFAULTS_SESSION:
if data[df] in (None, []):
data[df] = DEFAULTS_SESSION[df]
setattr(request, df, DEFAULTS_SESSION[df])
# Getting a TEMP conference key for the moment
q = Conference.query()
cons = q.get()
c_key = cons.key
s_id = Session.allocate_ids(size=1, parent=c_key)[0]
s_key = ndb.Key(Session, s_id, parent=c_key)
data['key'] = s_key
Session(**data).put()
return request
示例10: getConferencesByPopularity
def getConferencesByPopularity(self, request):
"""Return conferences by popularity"""
# fetch conference from key
conf = Conference.query().fetch()
# Check that conference exists
if not conf:
raise endpoints.NotFoundException("No conference found with this key: %s" % request.websafeConferenceKey)
conf_list = []
for c in conf:
count = Profile.query().filter(Profile.conferenceKeysToAttend == c.key.urlsafe()).count()
conf_list.append({"conf": c, "count": count})
conf_list = sorted(conf_list, key=lambda conf: conf["count"], reverse=True)
# need to fetch organiser displayName from profiles
# get all keys and use get_multi for speed
organisers = [(ndb.Key(Profile, c.organizerUserId)) for c in conf]
profiles = ndb.get_multi(organisers)
# put display names in a dict for easier fetching
names = {}
for profile in profiles:
names[profile.key.id()] = profile.displayName
# return individual ConferenceForm object per Conference
return ConferenceForms(
items=[self._copyConferenceToForm(c["conf"], names[c["conf"].organizerUserId]) for c in conf_list]
)
示例11: get
def get(self, confid, secret):
"""Download all speakers and proposals for a conference"""
# Super-Reviewers
committee = []
if confid == 'droidcon-2016':
committee = ['[email protected]',
'[email protected]']
# get conference
conference = Conference.get_by_id(confid)
# check if the provided secret is correct
if conference.secret != secret:
self.response.http_status_message(403)
return
speakers = Speaker.query()
proposals = Proposal.query(ancestor=conference.key)
reviews = Review.query()
speakers_dict = [dict(s.to_dict(), **dict(id=s.key.id()))
for s in speakers]
proposals_dict = []
# create a fast lookup table - reviews by parent
reviews_by_parent = {}
for r in reviews:
parent = r.key.parent()
rlist = reviews_by_parent[parent]
if rlist is None:
rlist = []
rlist.append(r)
reviews_by_parent[parent] = rlist
# crete a fast lookup table - speaker by key
speakers_by_id = {}
for s in speakers:
speakers_by_key[s.key] = s
for p in proposals:
p_dict = p.to_dict()
p_dict['id'] = p.key.id()
p_r = {}
p_sum = 0
for r in reviews_by_parent[p.key]:
p_r[r.key.id()] = r.to_dict()
if r.rating:
if r.key.id() in committee:
# double the rating!
p_sum = p_sum + r.rating
p_sum = p_sum + r.rating
s = speakers_by_key[p.speaker]
if s is not None:
p_dict['speaker-email'] = s.email
p_dict['speaker-name'] = s.name
p_dict['speaker-surname'] = s.surname
if s.rating:
p_sum = p_sum + s.rating
p_dict['reviews'] = p_r
p_dict['rating'] = p_sum
proposals_dict.append(p_dict)
self.response.headers['Content-Type'] = 'application/json'
obj = {
'speakers': speakers_dict,
'proposals': proposals_dict,
}
self.response.out.write(json.dumps(obj, cls=DatastoreEncoder))
示例12: getSessionsBySpeaker
def getSessionsBySpeaker(self, request):
"""Given a speaker, return all sessions given by this particular speaker, across all conferences"""
# make sure user is logged in
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
user_id = getUserId(user)
# get speaker value from form request
sessionSpeakerOfInterest = request.speaker
# store all session objects across all conferences where this speaker is presenting
all_sessions = []
# query for conferences
conferences = Conference.query()
for conf in conferences:
ck = getattr(conf, "key")
wsck = ck.urlsafe()
# For each conference, get Sessions for the Conference filtered by Speaker
sessions = Session.query(Session.websafeConferenceKey == wsck)
sessions = sessions.filter(Session.speaker == sessionSpeakerOfInterest)
for session in sessions:
all_sessions.append(session)
# return sessions in all conferences
return SessionForms(items=[self._copySessionToForm(session) for session in all_sessions])
示例13: _createConferenceObject
def _createConferenceObject(self, request):
"""Create or update Conference object, returning ConferenceForm/request."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
if not request.name:
raise endpoints.BadRequestException("Conference 'name' field required")
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data['websafeKey']
del data['organizerDisplayName']
for df in DEFAULTS:
if data[df] in (None, []):
data[df] = DEFAULTS[df]
setattr(request, df, DEFAULTS[df])
if data['startDate']:
data['startDate'] = datetime.strptime(data['startDate'][:10], "%Y-%m-%d").date()
data['month'] = data['startDate'].month
else:
data['month'] = 0
if data['endDate']:
data['endDate'] = datetime.strptime(data['endDate'][:10], "%Y-%m-%d").date()
if data["maxAttendees"] > 0:
data["seatsAvailable"] = data["maxAttendees"]
p_key = ndb.Key(Profile, user_id)
c_id = Conference.allocate_ids(size=1, parent=p_key)[0]
c_key = ndb.Key(Conference, c_id, parent=p_key)
data['key'] = c_key
data['organizerUserId'] = request.organizerUserId = user_id
Conference(**data).put()
taskqueue.add(params={'email': user.email(),
'conferenceInfo': repr(request)},
url='/tasks/send_confirmation_email'
)
return request
示例14: getSessionsByDateAndCity
def getSessionsByDateAndCity(self, request):
"""Return all sessions in given city on given date."""
# Expect date in format YYYY-MM-DD
try:
date = datetime.strptime(request.date, '%Y-%m-%d').date()
except ValueError:
raise endpoints.BadRequestException('Invalid date - '
'must be in YYYY-MM-DD format')
# get just the keys for conferences in city
conf_keys = Conference.query(Conference.city==request.city)\
.fetch(keys_only=True)
# get all sessions for conferences in city, filter on date
# (Guido's advice in http://stackoverflow.com/questions/12440333/
# ndb-query-on-multiple-parents-given-a-cursor)
# need to do multiple ancestor queries, do asynchronously
futures = []
for c_key in conf_keys:
futures.append(Session.query(ancestor=c_key)\
.filter(Session.date==date)\
.fetch_async())
sess = []
for f in futures:
sess.extend(f.get_result())
return SessionForms(
items=[self._copySessionToForm(s) for s in sess]
)
示例15: filterPlayground
def filterPlayground(self, request):
q = Conference.query()
# advanced filter building and usage
field = "city"
operator = "="
value = "London"
f = ndb.query.FilterNode(field, operator, value)
q = q.filter(f)
# TODO
# add 2 filters:
# 1: city equals to London
# 2: topic equals "Medical Innovations"
field = "topics"
operation = "="
value = "Medical Innovations"
f = ndb.query.FilterNode(field, operator, value)
q = q.filter(f)
q = q.order(Conference.maxAttendees)
return ConferenceForms(
items=[self._copyConferenceToForm(conf, "") for conf in q]
)