Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def raiseit(*arg):
exc = deform.exception.ValidationFailure(None, None, None)
exc.render = lambda *arg: 'failure'
raise exc
inst.submit_success = raiseit
def raiseit(*arg):
exc = deform.exception.ValidationFailure(None, None, None)
exc.render = lambda *arg: 'failure'
raise exc
inst.submit_success = raiseit
def raiseit(*arg):
raise deform.exception.ValidationFailure(None, None, None)
inst.submit_success = raiseit
@view_config(context=ISiteRoot, name="edit_groups", renderer=DEFAULT_TEMPLATE, permission=MANAGE_GROUPS)
def root_group_form(self):
schema = get_groups_schema(self.context)
add_csrf_token(self.context, self.request, schema)
form = Form(schema, buttons=(button_save, button_cancel))
self.api.register_form_resources(form)
post = self.request.POST
if 'save' in post:
controls = post.items()
try:
#appstruct is deforms convention. It will be the submitted data in a dict.
appstruct = form.validate(controls)
except ValidationFailure, e:
self.response['form'] = e.render()
return self.response
#Set permissions
self.context.update_userids_permissions_from_form(appstruct['userids_and_groups'])
url = resource_url(self.context, self.request)
return HTTPFound(location=url)
if 'cancel' in post:
url = resource_url(self.context, self.request)
return HTTPFound(location=url)
#No action - Render edit form
appstruct = self.context.get_security_appstruct()
def _results_ts(count):
""" Note about the odd syntax: pluralize returns unicode, so it won't be translated.
Hence it needs to be converted back to a translation string.
"""
return _(self.api.pluralize(_(u"item"),
_(u"items"),
count))
post = self.request.POST
if 'search' in post:
controls = post.items()
try:
#appstruct is deforms convention. It will be the submitted data in a dict.
appstruct = form.validate(controls)
except ValidationFailure, e: #pragma : no cover
self.response['search_form'] = e.render()
return self.response
#Preform the actual search
query = {}
if appstruct['query']:
query['searchable_text'] = appstruct['query']
query['path'] = resource_path(self.api.meeting)
if self.api.userid:
query['allowed_to_view'] = effective_principals(self.request)
else:
query['allowed_to_view'] = [Everyone]
cat_query = self.api.root.catalog.query
get_metadata = self.api.root.catalog.document_map.get_metadata
try:
# fill in errors raised by widgets
self.widget.handle_error(self, e)
cstruct = e.value
exc = e
self.cstruct = cstruct
try:
appstruct = self.schema.deserialize(cstruct)
except colander.Invalid as e:
# fill in errors raised by schema nodes
self.widget.handle_error(self, e)
exc = e
if exc:
raise exception.ValidationFailure(self, cstruct, exc)
return appstruct
response = {}
response['api'] = APIView(context, request)
content_util = request.registry.getUtility(IContentUtility)
schema = content_util['User'].schema(context=context, request=request, type='request_password')
form = Form(schema, buttons=('request', 'cancel'))
response['form_resources'] = form.get_widget_resources()
#Handle submitted information
if 'request' in request.POST:
controls = request.POST.items()
try:
#appstruct is deforms convention. It will be the submitted data in a dict.
appstruct = form.validate(controls)
except ValidationFailure, e:
response['form'] = e.render()
return response
userid_or_email = appstruct['userid_or_email']
#userid here can be either an email address or a login name
if '@' in userid_or_email:
#assume email
user = context['users'].get_user_by_email(userid_or_email)
else:
user = context['users'].get(userid_or_email)
if IUser.providedBy(user):
user.new_request_password_token(request)
response['api'].flash_messages.add(_('Email sent.'))
url = resource_url(response['api'].root, request)
# if admin is changing password for another user no verification of current password is needed
if self.context != self.api.user_profile and self.api.context_has_permission(MANAGE_SERVER, self.api.root):
schema = createSchema('ChangePasswordAdminSchema')
else:
schema = createSchema('ChangePasswordSchema')
add_csrf_token(self.context, self.request, schema)
schema = schema.bind(context = self.context, request = self.request, api = self.api)
form = Form(schema, buttons = (button_update, button_cancel))
self.api.register_form_resources(form)
post = self.request.POST
if 'update' in post:
controls = post.items()
try:
#appstruct is deforms convention. It will be the submitted data in a dict.
appstruct = form.validate(controls)
except ValidationFailure, e:
self.response['form'] = e.render()
return self.response
self.context.set_password(appstruct['password'])
msg = _(u"Password changed")
self.api.flash_messages.add(msg)
url = self.request.resource_url(self.context)
return HTTPFound(location = url)
if 'cancel' in post:
url = self.request.resource_url(self.context)
return HTTPFound(location = url)
#No action - Render edit form
self.response['form'] = form.render()
return self.response