本文整理汇总了Python中pyramid.traversal.find_root函数的典型用法代码示例。如果您正苦于以下问题:Python find_root函数的具体用法?Python find_root怎么用?Python find_root使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_root函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_deadline
def add_deadline(context, request):
logged_in = authenticated_userid(request)
main = get_renderer('../templates/master.pt').implementation()
schema = DeadlineSchema()
deadlineform = Form(schema, buttons=('submit',),use_ajax=True)
if 'dateDue' in request.params:
try:
controls = request.POST.items()
captured = deadlineform.validate(controls)
except deform.ValidationFailure, e:
deadlineform = e.render()
return {'red':'',
'main':main,
'form':deadlineform,
'content':'',
'logged_in':logged_in,
'name':'Add Deadline'}
dateDue = calendarstuff.datetime_from_str(request.params['dateDue'])
hours = request.params['hours']
sponsored = request.params['sponsored']
appliedClass = request.params['appliedClass']
context.count += 1
deadline = Deadline(dateDue,hours,sponsored,appliedClass,context.count)
deadline.__parent__ = context
context[str(context.count)] = deadline
find_root(context)['activityLogs'].deadline_creation(find_root(request.context)["users"][logged_in],deadline,request.application_url)
return {'red':'deadlines/',
'main':main,
'form':'',
'content':"Added a Deadline",
'logged_in':logged_in,
'name':'Redirecting...'}
示例2: add_sponsored_event
def add_sponsored_event(context,request):
logged_in = authenticated_userid(request)
user = find_root(request.context)['users'][logged_in]
main = get_renderer('../templates/master.pt').implementation()
projectList = find_root(context)["settings"].projects
projectTupleList = []
for project in projectList:
projectTupleList.append((project,project))
projectTupleTuple=tuple(projectTupleList) #sorry about this. It was more fun than a ListList
class SponsoredEventSchema(colander.MappingSchema):
completionDate = colander.SchemaNode(colander.Date(),title="Completion Date (YYYY-MM-DD): ")
hours = colander.SchemaNode(colander.Float(), title="Number of Hours: ")
description = colander.SchemaNode(
colander.String(),
validator=colander.OneOf([x[0] for x in projectTupleTuple]),
widget=deform.widget.RadioChoiceWidget(values=projectTupleTuple),
title='Project',
description='Select a Project')
taskDescription = colander.SchemaNode(
colander.String(), title="Description: ",
widget=deform.widget.TextAreaWidget(rows=5, cols=40),
description='Enter some text')
contact = colander.SchemaNode(colander.String(),title="Contact Name: ")
contactInfo = colander.SchemaNode(colander.String(),title="Contact Info: ")
schema=SponsoredEventSchema()
eventform = Form(schema, buttons=('submit',))
if 'taskDescription' in request.params:
try:
controls = request.POST.items()
captured = eventform.validate(controls)
except deform.ValidationFailure, e:
eventform = e.render()
return {'red':'',
'main':main,
'form':eventform,
'content':'',
'logged_in':logged_in,
'name':'Add Sponsored Event',
'TutText': getTutText(user, view='')}
completionDate = calendarstuff.datetime_from_str(request.params['completionDate'])
hours = request.params['hours']
description = request.params['deformField3']
taskDescription = request.params['taskDescription']
contact = request.params['contact']
contactInfo = request.params['contactInfo']
context.eventcount += 1
user = context.user
event = Event("Sponsored","N/A",completionDate,hours,description,taskDescription,contact,contactInfo,user,context.eventcount)
event.__parent__ = context
context[str(context.eventcount)] = event
activitylog = find_root(context)['activityLogs']
activitylog.event_creation(find_root(request.context)["users"][logged_in],event,request.application_url)
return {'red':'serviceLogs/'+context.user.username,
'main':main,
'form':'',
'content':"Added sponsored event for "+description,
'logged_in':logged_in,
'name':'Redirecting...',
'TutText': getTutText(user, view='')}
示例3: add_user
def add_user(context, request):
logged_in = authenticated_userid(request)
main = get_renderer('../templates/master.pt').implementation()
schema = UserSchema()
userform = Form(schema, buttons=('submit',),use_ajax=True)
if 'username' in request.params:
try:
controls = request.POST.items()
captured = userform.validate(controls)
except deform.ValidationFailure, e:
userform = e.render()
return {'red':'',
'main':main,
'form':userform,
'content':'',
'logged_in':logged_in,
'name':'Add User',
'TutText': getTutText(context, view='')}
username = request.params['username']
if username in context:
return {'red':'',
'logged_in':logged_in,
'main':main,
'form':'',
'content':'Sorry, the username '+username+' already exists in this system. Please try again, or contact an administrator.',
'name':'Users',
'TutText': getTutText(context, view='')}
password = hashlib.sha1(request.params["confirm"].encode('UTF-8')).digest()
studentId = request.params['studentId']
firstName = request.params['firstName']
lastName = request.params['lastName']
email = request.params['email']
phone = request.params['phone']
gradYear = request.params['gradYear']
inductionYear = request.params['inductionYear']
user = User(username,
password,
studentId,
firstName = firstName,
lastName = lastName,
email = email,
phone = phone,
gradYear = gradYear,
inductionYear = inductionYear)
user.__parent__ = context
context[username] = user
serviceLog = ServiceLog(user)
serviceLog.__parent__ = find_root(user)['serviceLogs']
find_root(user)['serviceLogs'][username]=serviceLog
user.serviceLog = ServiceLog
find_root(context)['activityLogs'].user_creation(find_root(request.context)["users"][logged_in],user,request.application_url)
return {'red':'users/',
'main':main,
'form':'',
'content':'The user '+firstName+' '+lastName+' was added to the system, with a username of '+username,
'logged_in':logged_in,
'name':'Redirecting...',
'TutText': getTutText(context, view='')}
示例4: csvimport
def csvimport(context,request):
logged_in = authenticated_userid(request)
main = get_renderer('../templates/master.pt').implementation()
schema = TextFieldSchema()
importform = Form(schema, buttons=('submit',))
if 'submit' in request.params:
inputstring = str(request.params["text"])
inputstring = inputstring.replace("\r","")
inputstring = inputstring.replace(", ",",")
lines = inputstring.split("\n")
inputlist = []
for line in lines:
if not line == "":
ul = line.split(",")
user = User(
ul[2], #username
hashlib.sha1(ul[8].encode('UTF-8')).digest(), #password, encoded
ul[3], #studentID
firstName = ul[1],
lastName = ul[0],
email = ul[4],
phone = ul[5],
gradYear = ul[6],
inductionYear = ul[7]
)
username = ul[2]
if username in context:
return {'red':'',
'logged_in':logged_in,
'main':main,
'form':exportform.render(),
'content':"ERROR: the username "+username+" already exists in this system. Please reassess your input data.",
'name':'Import From CSV',
'TutText': getTutText(context, view='')}
user.__parent__ = context
context[username] = user
serviceLog = ServiceLog(user)
serviceLog.__parent__ = find_root(user)['serviceLogs']
find_root(user)['serviceLogs'][username]=serviceLog
user.serviceLog = ServiceLog
find_root(context)['activityLogs'].user_creation(find_root(request.context)["users"][logged_in],user,request.application_url)
return {'red':'users/',
'main':main,
'logged_in':logged_in,
'form':'',
'content':'Imported Users from CSV',
'name':'Redirecting...',
'TutText': getTutText(context, view='')}
return {'red':'',
'main':main,
'logged_in':logged_in,
'form':importform.render(),
'content':'',
'name':'Import From CSV',
'TutText': getTutText(context, view='')}
示例5: view_servicelog
def view_servicelog(context,request):
logged_in = authenticated_userid(request)
currentuser = find_root(request.context)["users"][logged_in]
main = get_renderer('../templates/master.pt').implementation()
app = find_root(request.context)
if currentuser.isOfficer:
if "action" in request.params:
for ID in request.params.keys():
if not ID in ['action','comment','note']:
event = context[ID]
if request.params["action"] == "delete":
if event.verified == "Verified":
event.user.hours -= float(event.hours)
if event.eventType == "Sponsored":
event.user.sponsored -= float(event.hours)
app['activityLogs'].event_deactivation(currentuser,event,request.application_url)
del event.__parent__[str(event.ID)]
elif request.params["action"] == "verify":
if not event.verified == "Verified":
event.user.hours += float(event.hours)
if event.eventType == "Sponsored":
event.user.sponsored += float(event.hours)
event.verified = "Verified"
app['activityLogs'].event_verification(currentuser,event,request.application_url)
elif request.params["action"] == "flag":
if event.verified == "Verified":
event.user.hours -= float(event.hours)
if event.eventType == "Sponsored":
event.user.sponsored -= float(event.hours)
event.verified = "Flagged"
find_root(context)['activityLogs'].event_flagging(currentuser,event,request.application_url)
elif request.params["action"] == "unverify":
if event.verified == "Verified":
event.user.hours -= float(event.hours)
if event.eventType == "Sponsored":
event.user.sponsored -= float(event.hours)
event.verified = "Unverified"
find_root(context)['activityLogs'].event_unverification(currentuser,event,request.application_url)
if request.params["comment"]:
if event.comment:
event.comment += " "+request.params['comment']
else:
event.comment = request.params['comment']
permission=True
red=''
if not logged_in == context.user.username:
if not find_root(context)['users'][logged_in].isAdvisor and not find_root(context)['users'][logged_in].isOfficer:
permission=False
red = 'serviceLogs'
userclass = calendarstuff.class_from_year(context.user.gradYear)
deadlines = find_root(context)["deadlines"]
now = datetime.now()
return {'red':red,
'main':main,
'content':context,
'logged_in':logged_in,
'name':'Service Logs',
'isallowed':permission,
'deadlines':deadlines}
示例6: add_independent_event
def add_independent_event(context, request):
logged_in = authenticated_userid(request)
main = get_renderer("../templates/master.pt").implementation()
schema = IndependentEventSchema()
eventform = Form(schema, buttons=("submit",))
if "description" in request.params:
try:
controls = request.POST.items()
captured = eventform.validate(controls)
except deform.ValidationFailure, e:
eventform = e.render()
return {
"red": "",
"main": main,
"form": eventform,
"content": "",
"logged_in": logged_in,
"name": "Add Independent Event",
}
completionDate = calendarstuff.datetime_from_str(request.params["completionDate"])
hours = request.params["hours"]
description = request.params["description"]
taskDescription = request.params["taskDescription"]
contact = request.params["contact"]
contactInfo = request.params["contactInfo"]
affects = request.params["affects"]
context.eventcount += 1
user = context.user
event = Event(
"Independent",
completionDate,
hours,
description,
taskDescription,
contact,
contactInfo,
user,
context.eventcount,
affects=affects,
)
event.__parent__ = context
context[str(context.eventcount)] = event
activitylog = find_root(context)["activityLogs"]
activitylog.event_creation(find_root(request.context)["users"][logged_in], event, request.application_url)
return {
"red": "serviceLogs/" + context.user.username,
"main": main,
"form": "",
"content": "Added independent event for " + description,
"logged_in": logged_in,
"name": "Redirecting...",
}
示例7: add_entry
def add_entry(context, request):
if 'submit' in request.params:
session = DBSession()
title = request.params['title']
text = request.params['text']
entry = Entry(title, text)
session.add(entry)
return HTTPFound(location=request.resource_url(find_root(context)))
add_url = request.resource_url(find_root(context), 'add')
return {'mode': 'Add',
'title':'',
'text':'',
'add_url':add_url}
示例8: hoursimport
def hoursimport(context,request):
logged_in = authenticated_userid(request)
main = get_renderer('../templates/master.pt').implementation()
schema = TextFieldSchema()
importform = Form(schema, buttons=('submit',))
if 'submit' in request.params:
inputstring = str(request.params["text"])
inputstring = inputstring.replace("\r","")
inputstring = inputstring.replace(", ",",")
lines = inputstring.split("\n")
inputlist = []
for line in lines:
if not line == "":
rl = line.split(",")
for value in rl[1:]:
try:
value = float(value)
except ValueError:
return {'red':'',
'logged_in':logged_in,
'main':main,
'form':exportform.render(),
'content':"ERROR: Input data was not a number, and could not be processed. Please reassess your input data.",
'name':'Import Hours From CSV',
'TutText': getTutText(context, view='')}
username = rl[0]
if not username in context:
return {'red':'',
'logged_in':logged_in,
'main':main,
'form':exportform.render(),
'content':"ERROR: the username "+username+" does not exist in this system. Please reassess your input data.",
'name':'Import Hours From CSV',
'TutText': getTutText(context, view='')}
context[username].hours = rl[1]
context[username].sponsored = rl[2]
find_root(context)['activityLogs'].user_edit(context[logged_in],context[username],request.application_url)
return {'red':'users/',
'main':main,
'logged_in':logged_in,
'form':'',
'content':'Imported Hours from CSV',
'name':'Redirecting...',
'TutText': getTutText(context, view='')}
return {'red':'',
'main':main,
'logged_in':logged_in,
'form':importform.render(),
'content':'',
'name':'Import Hours From CSV',
'TutText': getTutText(context, view='')}
示例9: requirementsimport
def requirementsimport(context,request):
logged_in = authenticated_userid(request)
main = get_renderer('../templates/master.pt').implementation()
schema = TextFieldSchema()
importform = Form(schema, buttons=('submit',))
if 'submit' in request.params:
inputstring = str(request.params["text"])
inputstring = inputstring.replace("\r","")
inputstring = inputstring.replace(", ",",")
lines = inputstring.split("\n")
inputlist = []
for line in lines:
if not line == "":
rl = line.split(",")
for value in rl[1:]:
if value in ['Yes', 'YES', 'yes', 'Y', 'y']:
value = True
elif value in ['No', 'NO', 'no', 'N', 'n']:
value = False
if type(value) != type(True):
return {'red':'',
'logged_in':logged_in,
'main':main,
'form':exportform.render(),
'content':"ERROR: Input data was not either 'yes' or 'no', and could not be processed. Please reassess your input data.",
'name':'Import Requirements From CSV',
'TutText': getTutText(context, view='')}
username = rl[0]
if not username in context:
return {'red':'','logged_in':logged_in,'main':main,'form':exportform.render(), 'content':"ERROR: the username "+username+" does not exist in this system. Please reassess your input data.",'name':'Import Requirements From CSV'}
context[username].dues = rl[1]
context[username].gpa = rl[2]
context[username].firstMeeting = rl[3]
context[username].secondMeeting = rl[4]
context[username].thirdMeeting = rl[5]
find_root(context)['activityLogs'].user_edit(context[logged_in],context[username],request.application_url)
return {'red':'users/',
'main':main,
'logged_in':logged_in,
'form':'',
'content':'Imported Information from CSV',
'name':'Redirecting...',
'TutText': getTutText(context, view='')}
return {'red':'',
'main':main,
'logged_in':logged_in,
'form':importform.render(),
'content':'',
'name':'Import Requirements From CSV',
'TutText': getTutText(context, view='')}
示例10: add_independent_event
def add_independent_event(context,request):
logged_in = authenticated_userid(request)
user = find_root(request.context)['users'][logged_in]
main = get_renderer('../templates/master.pt').implementation()
schema = IndependentEventSchema()
eventform = Form(schema, buttons=('submit',))
if 'description' in request.params:
try:
controls = request.POST.items()
captured = eventform.validate(controls)
except deform.ValidationFailure, e:
eventform = e.render()
return {'red':'',
'main':main,
'form':eventform,
'content':'',
'logged_in':logged_in,
'name':'Add Independent Event',
'TutText': getTutText(user, view='')}
completionDate = calendarstuff.datetime_from_str(request.params['completionDate'])
hours = request.params['hours']
description = request.params['description']
taskDescription = request.params['taskDescription']
contact = request.params['contact']
contactInfo = request.params['contactInfo']
affects = request.params['affects']
type = request.params['type']
context.eventcount += 1
user = context.user
event = Event("Independent",
type,
completionDate,
hours,
description,
taskDescription,
contact,contactInfo,
user,
context.eventcount,
affects=affects)
event.__parent__ = context
context[str(context.eventcount)]=event
activitylog=find_root(context)['activityLogs']
activitylog.event_creation(find_root(request.context)["users"][logged_in],event,request.application_url)
return {'red':'serviceLogs/'+context.user.username,
'main':main,
'form':'',
'content':"Added independent event for "+description,
'logged_in':logged_in,
'name':'Redirecting...',
'TutText': getTutText(user, view='')}
示例11: __call__
def __call__(self, node, value):
root = find_root(self.context)
try:
find_resource(root, value)
except KeyError:
raise colander.Invalid(
node, _("Not an existing valid path."))
示例12: dereference
def dereference(self, context):
""" Return the :class:`Object` this Reference refers to.
``context`` can be any resource and is simply used to find the root
(which in turn is used to resolve the reference).
"""
root = find_root(context)
return root.get_object_for_reference(self)
示例13: deferred_user_choices_widget
def deferred_user_choices_widget(node, kw):
context = kw['context']
root = find_root(context)
user_choices = tuple(root['users'].keys())
return deform.widget.AutocompleteInputWidget(size=20,
values = user_choices,
min_length=1)
示例14: at_userid_link
def at_userid_link(text, obj, request=None):
""" Transform @userid to a link.
"""
users = find_root(obj).users
meeting = find_interface(obj, IMeeting)
assert meeting
if not request:
request = get_current_request()
def handle_match(matchobj):
# The pattern contains a space so we only find usernames that
# has a whitespace in front, we save the spaced so we can but
# it back after the transformation
space, userid = matchobj.group(1, 2)
#Force lowercase userid
userid = userid.lower()
if userid in users:
user = users[userid]
tag = {}
tag['href'] = request.resource_url(meeting, '_userinfo', query={'userid': userid}).replace(request.application_url, '')
tag['title'] = user.title
tag['class'] = "inlineinfo"
return space + HTML.a('@%s' % userid, **tag)
else:
return space + '@' + userid
return re.sub(AT_PATTERN, handle_match, text)
示例15: groupfinder
def groupfinder(username, request):
root = find_root(request.context)
if username in root:
return username
else:
# raise KeyError('Unknown user: %s' % username)
return None