本文整理汇总了Python中rorn.Box.ErrorBox.die方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorBox.die方法的具体用法?Python ErrorBox.die怎么用?Python ErrorBox.die使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rorn.Box.ErrorBox
的用法示例。
在下文中一共展示了ErrorBox.die方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: newNoteModify
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def newNoteModify(handler, taskid, id, p_action):
handler.title("New Note")
requirePriv(handler, "User")
if p_action != "delete":
ErrorBox.die("Invalid Action", "Unrecognized action <b>%s</b>" % p_action)
taskid = int(taskid)
task = Task.load(taskid)
if not task or task.sprint.isHidden(handler.session["user"]):
ErrorBox.die("Invalid Task", "No task with ID <b>%d</b>" % taskid)
id = int(id)
note = Note.load(id)
if not note:
ErrorBox.die("Invalid Note", "No note with ID <b>%d</b>" % noteid)
elif note.task != task: # Doesn't really matter, but shouldn't happen
ErrorBox.die("Task mismatch", "Note/task mismatch")
elif note.user != handler.session["user"]:
ErrorBox.die("Permission denied", "Notes can only be deleted by their creators")
note.delete()
delay(handler, SuccessBox("Deleted note", close=3))
Event.deleteNote(handler, note)
redirect("/tasks/%d" % task.id)
示例2: exportSprints
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def exportSprints(handler, project):
id = int(project)
handler.title('Export Sprint')
requirePriv(handler, 'User')
project = Project.load(id)
if not project:
ErrorBox.die('Invalid project', "No project with ID <b>%d</b>" % id)
print "<link href=\"/static/jquery.multiselect.css\" rel=\"stylesheet\" type=\"text/css\" />"
print "<script src=\"/static/jquery.multiselect.js\" type=\"text/javascript\"></script>"
print "<script src=\"/static/sprints-export.js\" type=\"text/javascript\"></script>"
print "<style type=\"text/css\">"
print "select {width: 50%;}"
print "img.format {"
print " width: 64px;"
print " cursor: pointer;"
print " padding: 5px;"
print " border: 3px solid #fff;"
print "}"
print "img.format.selected, .ui-effects-transfer {border: 3px solid #f00;}"
print "</style>"
print "<h2>Sprints</h2>"
print "<select name=\"sprints\" multiple>"
for sprint in project.getSprints():
if sprint.canView(handler.session['user']):
print "<option value=\"%d\"%s>%s</option>" % (sprint.id, ' selected' if sprint.isActive() else '', sprint.safe.name)
print "</select>"
print "<h2>Format</h2>"
for export in exports.values():
print "<img class=\"format\" src=\"/static/images/%s.png\" title=\"%s\" export-name=\"%s\">" % (export.getIcon(), export.getFriendlyName(), export.getName())
print "<br><br>"
print Button('Export', id = 'export-button').positive()
示例3: twoFactorAuthentication
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def twoFactorAuthentication(handler, p_action):
handler.title("Two-Factor Authentication")
requirePriv(handler, "User")
if p_action == "enable":
handler.session["user"].hotpKey = b32encode("".join(chr(randrange(256)) for _ in range(10)))
handler.session["user"].save()
Event.tfa(handler, handler.session["user"])
print SuccessBox("Two-factor authentication is <b>enabled</b>")
print "Your HOTP key is <b>%s</b>:<br><br>" % handler.session["user"].hotpKey
print '<div style="text-align: center"><img src="https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/Sprint%%3Fsecret%%3D%s"></div><br>' % handler.session[
"user"
].hotpKey
print "This key will not be displayed again — be sure to write it down, or add it to your Google Authenticator list now"
elif p_action == "disable":
handler.session["user"].hotpKey = ""
handler.session["user"].save()
Event.tfa(handler, handler.session["user"])
delay(handler, SuccessBox("Two-factor authentication is <b>disabled</b>"))
redirect("/users/%s" % handler.session["user"].username)
else:
ErrorBox.die("Unexpected action: <b>%s</b>" % stripTags(p_action))
示例4: adminPrivilegesPost
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def adminPrivilegesPost(handler, p_grant):
handler.title("Privileges")
requirePriv(handler, 'Admin')
p_grant = {name: privs.keys() for name, privs in p_grant.iteritems()}
privNames = set()
for privs in p_grant.values():
privNames |= set(privs)
if not privNames <= set(privList.keys()):
ErrorBox.die("Update privileges", "Unrecognized privilege name")
for user in User.loadAll():
for priv in privList:
privs = p_grant.get(user.username, [])
has = user.hasPrivilege(priv)
if has and priv not in privs:
print "Revoking %s from %s<br>" % (priv, user.username)
user.privileges.remove(priv)
Event.revokePrivilege(handler, user, priv)
elif not has and priv in privs:
print "Granting %s to %s<br>" % (priv, user.username)
user.privileges.add(priv)
Event.grantPrivilege(handler, user, priv, False)
user.save()
print "Done"
示例5: findActiveSprint
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def findActiveSprint(handler, project = None, search = None):
handler.title('Active Sprint')
requirePriv(handler, 'User')
if project:
projectid = int(project)
project = Project.load(projectid)
if not project:
ErrorBox.die('Load project', "No project with ID <b>%d</b>" % projectid)
url = "/sprints/%d"
if search:
url += "?search=%s" % search
sprints = Sprint.loadAllActive(handler.session['user'], project)
sprints = filter(lambda sprint: sprint.canView(handler.session['user']), sprints)
for case in switch(len(sprints)):
if case(0):
ErrorBox.die('Active sprint', 'No active sprints found')
break
if case(1):
redirect(url % sprints[0].id)
break
if case():
print "You are active in multiple sprints%s:<br><br>" % (" in the %s project" % project.safe.name if project else '')
for sprint in sprints:
print "<a href=\"%s\">%s</a><br>" % (url % sprint.id, sprint.safe.name)
break
示例6: userAvatarSet
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def userAvatarSet(handler, username):
handler.title('Set avatar')
requirePriv(handler, 'User')
user = User.load(username = username)
if not user:
ErrorBox.die("Set avatar", "No user named <b>%s</b>" % stripTags(username))
if user != handler.session['user']: #TODO Allow devs
redirect("/users/%s/avatar/set" % handler.session['user'].username)
if not Image:
ErrorBox.die("Set avatar", "This sprint install does not have the Python Imaging Library (PIL), so local avatars are not supported")
print "Restrictions on a locally hosted avatar:"
print "<ul>"
print "<li>Type: %s</li>" % ", ".join(AVATAR_TYPES).upper()
print "<li>Size: %s bytes</li>" % AVATAR_MAX_SIZE
print "</ul>"
print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"/users/%s/avatar/set\">" % user.username
print "<input type=\"file\" name=\"data\"><br>"
# Using a plain button here because the file field isn't styled
print "<button>Upload</button>"
print "</form>"
if user.hasLocalAvatar():
print "<br>"
print "You can also remove your existing local avatar. Your account will switch back to using your gravatar image<br>"
print "<form method=\"post\" action=\"/users/%s/avatar/remove\">" % user.username
print "<button>Remove avatar</button>"
print "</form>"
示例7: adminSessionsPost
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def adminSessionsPost(handler, p_key, p_action, p_value = None):
handler.title('Sessions')
requirePriv(handler, 'Admin')
print "<script src=\"/static/admin-sessions.js\" type=\"text/javascript\"></script>"
if not p_key in Session.getIDs():
ErrorBox.die("Retrieve session", "No session exists with key <b>%s</b>" % stripTags(p_key))
session = Session.load(p_key)
for case in switch(p_action):
if case('reassign'):
handler.title('Reassign Session')
if p_value:
user = User.load(int(p_value))
if not user:
ErrorBox.die("Load user", "No user exists with ID <b>%s</b>" % stripTags(p_value))
session['user'] = user
redirect('/admin/sessions')
else:
print "<form method=\"post\" action=\"/admin/sessions\">"
print "<input type=\"hidden\" name=\"action\" value=\"reassign\">"
print "<input type=\"hidden\" name=\"key\" value=\"%s\">" % p_key
print "<select id=\"selectUser\" name=\"value\">"
for user in sorted(User.loadAll()):
print "<option value=\"%d\">%s</option>" % (user.id, user.safe.username)
print "</select><br>"
print Button('Reassign', type = 'submit').positive()
print Button('Cancel', id = 'cancel-button', type = 'button', url = '/admin/sessions').negative()
print "</form>"
break
if case('destroy'):
Session.destroy(p_key)
redirect('/admin/sessions')
break
break
示例8: adminProjectsMoveSprintsPost
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def adminProjectsMoveSprintsPost(handler, id, p_newproject, p_sprintid = None):
handler.title('Move Sprints')
requirePriv(handler, 'Admin')
project = Project.load(int(id))
if not project:
ErrorBox.die('Invalid Project', "No project with ID <b>%d</b>" % int(id))
p_newproject = to_int(p_newproject, 'newproject', ErrorBox.die)
target = Project.load(p_newproject)
if not p_sprintid:
delay(handler, WarningBox("No sprints to move", close = True))
redirect("/admin/projects/%d" % project.id)
sprintids = [to_int(id, 'sprintid', ErrorBox.die) for id in p_sprintid]
sprints = [Sprint.load(id) for id in sprintids]
if not all(sprints):
ErrorBox.die("Invalid sprint ID(s)")
for sprint in sprints:
sprint.project = target
sprint.save()
delay(handler, SuccessBox("%s moved" % pluralize(len(sprints), 'sprint', 'sprints'), close = True))
redirect("/admin/projects/%d" % project.id)
示例9: adminProjectsManage
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def adminProjectsManage(handler, id):
handler.title('Manage Project')
requirePriv(handler, 'Admin')
project = Project.load(int(id))
if not project:
ErrorBox.die('Invalid Project', "No project with ID <b>%d</b>" % int(id))
undelay(handler)
sprints = project.getSprints()
otherProjects = sorted((p for p in Project.loadAll() if p != project), key = lambda p: p.name)
for sprint in sprints:
if 'deleted' in sprint.flags:
print "<form method=\"post\" action=\"/admin/projects/%d/cancel-deletion/%d\">" % (project.id, sprint.id)
print WarningBox("%s is flagged for deletion during nightly cleanup. %s" % (sprint.link(handler.session['user']), Button('Cancel').mini().post()))
print "</form>"
print "<a name=\"sprints\"></a>"
print "<h3>Sprints</h3>"
if len(sprints) > 0:
print "<form method=\"post\" action=\"/admin/projects/%d/sprints\">" % project.id
for sprint in sprints:
print "<input type=\"checkbox\" name=\"sprintid[]\" value=\"%d\"> %s<br>" % (sprint.id, sprint.link(handler.session['user']))
print "<br>"
print "Move to project: <select name=\"newproject\">"
for p in otherProjects:
print "<option value=\"%d\">%s</option>" % (p.id, p.safe.name)
print "</select>"
print Button('Move').post('move').positive()
print "<br><br>"
print "Delete sprints (irreversible once finalized):"
print Button('Delete').post('delete').negative()
print "</form>"
else:
print "No sprints"
print "<a name=\"rename\"></a>"
print "<h3>Rename</h3>"
print "<form method=\"post\" action=\"/admin/projects/%d/edit\">" % project.id
print "Name: <input type=\"text\" name=\"name\" value=\"%s\">" % project.safe.name
print Button('Rename', type = 'submit').positive()
print "</form>"
print "<a name=\"delete\"></a>"
print "<h3>Delete</h3>"
print "<form method=\"post\" action=\"/admin/projects/%d/delete\">" % project.id
if len(project.getSprints()) > 0:
if len(otherProjects) > 0:
print "Delete <b>%s</b> and move all sprints to <select name=\"newproject\">" % project.safe.name
for p in otherProjects:
print "<option value=\"%d\">%s</option>" % (p.id, p.safe.name)
print "</select>"
print Button('Delete', type = 'submit').negative()
else:
print "Unable to remove the only project if it has sprints"
else:
print Button("Delete %s" % project.safe.name, type = 'submit').negative()
print "</form><br>"
示例10: adminProjectsEditPost
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def adminProjectsEditPost(handler, id, p_name):
handler.title('Edit Project')
requirePriv(handler, 'Admin')
project = Project.load(int(id))
if not project:
ErrorBox.die('Invalid Project', "No project with ID <b>%d</b>" % int(id))
project.name = p_name
project.save()
delay(handler, SuccessBox("Saved project changes", close = True))
redirect("/admin/projects/%d" % project.id)
示例11: userTasks
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def userTasks(handler, username):
handler.title('User tasks')
user = User.load(username = username)
if not user:
ErrorBox.die("User tasks", "No user named <b>%s</b>" % stripTags(username))
tasks = [task.id for task in Task.loadAll() if user in task.assigned and task.stillOpen() and task.sprint.isActive()]
if len(tasks) == 0:
ErrorBox.die("User tasks", "%s has no open tasks in active sprints" % user)
redirect("/tasks/%s" % ','.join(map(str, tasks)))
示例12: searchRunSprint
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def searchRunSprint(handler, id, sprintid):
handler.title('Run Search')
requirePriv(handler, 'User')
id = int(id)
search = SavedSearch.load(id)
if not search:
ErrorBox.die('Invalid Search', "Search <b>%d</b> does not exist" % int(id))
elif search.user != handler.session['user'] and not search.public:
ErrorBox.die('Invalid Search', "You cannot run search <b>%d</b>" % int(id))
redirect("/sprints/%s?search=%s" % (sprintid, search.query))
示例13: adminProjectsPost
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def adminProjectsPost(handler, p_name):
handler.title('Project Management')
requirePriv(handler, 'Admin')
if Project.load(name = p_name):
ErrorBox.die('Add Project', "There is already a project named <b>%s</b>" % stripTags(p_name))
project = Project(p_name)
project.save()
delay(handler, SuccessBox("Added project <b>%s</b>" % stripTags(p_name), close = True))
Event.newProject(handler, project)
redirect('/')
示例14: userAvatarRemove
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def userAvatarRemove(handler, username):
handler.title('Remove avatar')
requirePriv(handler, 'User')
user = User.load(username = username)
if not user:
ErrorBox.die("Remove avatar", "No user named <b>%s</b>" % stripTags(username))
if user != handler.session['user']: #TODO Allow devs
redirect("/users/%s/avatar/set" % handler.session['user'].username)
user.avatar = None
user.save()
delay(handler, SuccessBox("Avatar removed"))
redirect("/users/%s" % user.username)
示例15: newTaskManyUpload
# 需要导入模块: from rorn.Box import ErrorBox [as 别名]
# 或者: from rorn.Box.ErrorBox import die [as 别名]
def newTaskManyUpload(handler, group, p_data):
requirePriv(handler, "User")
# Vague sanity check that this is actually text, from http://stackoverflow.com/a/7392391/309308
textchars = "".join(map(chr, [7, 8, 9, 10, 12, 13, 27] + range(0x20, 0x100)))
is_binary_string = lambda bytes: bool(bytes.translate(None, textchars))
if is_binary_string(p_data):
ErrorBox.die(
"The uploaded file appears to be binary -- it should be a text file matching the normal add tasks format"
)
handler.session["many-upload"] = p_data
redirect("/tasks/new/many?group=%s" % group)