def extends(*args, **kwargs): frame = sys._getframe(1) f_locals = frame.f_locals if not kwargs.get('ignoreFields', False): f_locals['fields'] = field.Fields() for arg in args: f_locals['fields'] += getattr(arg, 'fields', field.Fields()) if not kwargs.get('ignoreHandlers', False): f_locals['buttons'] = button.Buttons() for arg in args: f_locals['buttons'] += getattr(arg, 'buttons', button.Buttons()) if not kwargs.get('ignoreHandlers', False): f_locals['handlers'] = button.Handlers() for arg in args: f_locals['handlers'] += getattr(arg, 'handlers', button.Handlers())
def update(self): def handleApply(self, action): data, errors = self.extractData() if not data.get(self.channel_selector): self.unsubscribe() return if errors: self.status = self.formErrorsMessage return content = self.getContent() del data[self.channel_selector] changes = form.applyChanges(self, content, data) if changes: zope.event.notify( zope.lifecycleevent.ObjectModifiedEvent(content)) self.status = self.successMessage else: self.status = self.noChangesMessage self.handlers = button.Handlers() self.handlers.addHandler(self.parentForm.buttons['apply'], handleApply) super(SubscriptionEditSubForm, self).update()
def setup_form(self): self.buttons = button.Buttons() self.handlers = button.Handlers() if self.form_type() == 'addform': preview = button.Button(title=_(u'Continue'), name='save') self.buttons += button.Buttons(preview) preview_handler = button.Handler(preview, self.__class__.handle_preview) self.handlers.addHandler(preview, preview_handler) self.ignoreContext = True self.ignoreReadonly = True else: update = button.Button(title=_(u'Continue'), name='save') self.buttons += button.Buttons(update) update_handler = button.Handler(update, self.__class__.handle_update) self.handlers.addHandler(update, update_handler) self.context = self.event cancel = button.Button(title=_(u'Cancel'), name='cancel') self.buttons += button.Buttons(cancel) cancel_handler = button.Handler(cancel, self.__class__.handle_cancel) self.handlers.addHandler(cancel, cancel_handler)
def update(self): def handleApply(self, action): data, errors = self.extractData() if not data.get(self.channel_selector): return if errors: self.status = form.AddForm.formErrorsMessage return extract = lambda d, prefix: dict([(key.split('.', 1)[-1], value) for (key, value) in d.items() if key.startswith(prefix)]) comp_data = extract(data, 'composer.') coll_data = extract(data, 'collector.') pdata, perrors = self.parentForm.extractData() comp_data.update(pdata) composer = self.context.composers[self.format] secret = collective.singing.subscribe.secret( self.context, composer, comp_data, self.request) secret_provided = self.secret if secret_provided and secret != secret_provided: self.status = self.status_error return # Check if subscribed to other channels if not secret_provided and not self.parentForm.confirmation_sent: existing = sum( [len(channel.subscriptions.query(secret=secret)) \ for channel in channel_lookup(only_subscribeable=True)]) if existing: self.status = self.status_already_subscribed return metadata = dict(format=self.format, date=datetime.datetime.now(), pending=not secret_provided) # We assume here that the language of the request is the # desired language of the subscription: pl = component.queryAdapter( self.request, zope.i18n.interfaces.IUserPreferredLanguages) if pl is not None: metadata['languages'] = pl.getPreferredLanguages() # By using another method here we allow subclasses to override # what really happens here: self.add_subscription(self.context, secret, comp_data, coll_data, metadata, secret_provided) self.handlers = button.Handlers() self.handlers.addHandler(self.parentForm.buttons['apply'], handleApply) super(SubscriptionAddSubForm, self).update()
def __init__(self, context, request): super(SubmissionEditForm, self).__init__(context, request) language = negotiate(context=request) or u'' context_language = get_navigation_root_language(self.context) if context_language.startswith(language or context_language): self._locale_postfix = '' else: self._locale_postfix = '_' + language self.buttons = button.Buttons() self.handlers = button.Handlers()
def __init__(self, context, request): super(FlowSubmitForm, self).__init__(context, request) language = negotiate(context=self.request) or u'' context_language = get_navigation_root_language(self.context) if context_language.startswith(language or context_language): self.localized_context = context else: proxy = LanguageFieldsProxy(self.context) proxy._language = language self.localized_context = proxy self.buttons = button.Buttons() self.handlers = button.Handlers() if 'disable_border' in self.request.form: del self.request.form['disable_border']
def setup_form(self): self.buttons = button.Buttons() self.handlers = button.Handlers() save = button.Button(title=_(u'Save Event'), name='save') self.buttons += button.Buttons(save) save_handler = button.Handler(save, self.__class__.handle_save) self.handlers.addHandler(save, save_handler) self.event = self.context cancel = button.Button(title=_(u'Cancel Event Submission'), name='cancel') self.buttons += button.Buttons(cancel) cancel_handler = button.Handler(cancel, self.__class__.handle_cancel) self.handlers.addHandler(cancel, cancel_handler)