def submit(self): FormControllerMixin.submit(self) publishable = self.context["publishable"] # Adding roles instance = self.form_instance instance.roles.extend(publishable.roles) # If require email confirmation, disabled authenticated access # and send email confirmation message confirmation_email_template = publishable.confirmation_email_template if confirmation_email_template: instance.enabled = False instance.confirmed_email = False confirmation_email_template.send(self.email_parameters) # Storing instance instance.insert() datastore.commit() else: # Storing instance instance.insert() datastore.commit() # Getting confirmation target uri confirmation_target = self.context[ "publishable"].confirmation_target uri = self.context["cms"].uri(confirmation_target) # Enabling user and autologin instance.enabled = True self.context["cms"].authentication.set_user_session(instance) # Redirecting to confirmation target raise cherrypy.HTTPRedirect(uri)
def form_schema(self): form_schema = FormControllerMixin.form_schema(self) # Set schema name in order to keep always the same value # although change value of form_model member form_schema.name = u"SignUpForm" # Adding extra field for password confirmation if form_schema.get_member("password"): password_confirmation_member = schema.String( name="password_confirmation", edit_control="cocktail.html.PasswordBox", required=form_schema.get_member("password")) form_schema.add_member(password_confirmation_member) # Set password_confirmation position just after # password member position order_list = form_schema.members_order pos = order_list.index("password") order_list.insert(pos + 1, "password_confirmation") # Add validation to compare password_confirmation and # password fields @password_confirmation_member.add_validation def validate_password_confirmation(member, value, ctx): password = ctx.get_value("password") password_confirmation = value if password and password_confirmation \ and password != password_confirmation: yield PasswordConfirmationError(member, value, ctx) return form_schema
def form_adapter(self): adapter = FormControllerMixin.form_adapter(self) adapter.exclude([ "prefered_language", "roles", "password_confirmation", "enabled", "confirmed_email" ] + [key for key in Item.members()]) return adapter
def form_errors(self): form_errors = FormControllerMixin.form_errors(self) if not form_errors and self.submitted and get_current_user().anonymous: user_param = get_parameter(schema.Member("user")) form_errors._items.append(AuthenticationFailedError(user_param)) return form_errors
def submit(self): FormControllerMixin.submit(self) export_events = [] tracker = StatusTracker() @when(tracker.file_processed) def handle_file_processed(event): if event.status == "failed": event.error_handled = True export_events.append(event) form = self.form_data user = get_current_user() user.require_permission( ExportationPermission, destination = form["destination"] ) destination = form["destination"] snapshoter = form["snapshoter"] context = self.form_data.copy() exporter_context = destination.export( snapshoter, self.selection, update_only = form["update_only"], status_tracker = tracker, context = context ) # View class self.view_class = destination.view_class(exporter_context) self.output["export_events"] = export_events self.output.update( **destination.output(exporter_context) ) datastore.commit()
def __init__(self, *args, **kwargs): DocumentController.__init__(self, *args, **kwargs) FormControllerMixin.__init__(self)
def __init__(self, *args, **kwargs): BaseBackOfficeController.__init__(self, *args, **kwargs) FormControllerMixin.__init__(self, *args, **kwargs) self.selection = self.params.read( schema.Collection("selection", items = schema.Reference(type = Publishable)) )