def setUpWidgets(self, ignore_request=False):
     """Manually set the widget values"""
     annotated_obj = IAnnotations(self.context)         
     keys = IGallerificSetting.names()
     data = {}      
     try:                          
         for key in keys:
             data[key] = annotated_obj[key]
         self.widgets = form.setUpWidgets( self.form_fields, self.prefix, self.context, self.request, data=data, ignore_request=ignore_request)
 	except:
     	self.widgets = form.setUpWidgets( self.form_fields, self.prefix, self.context, self.request, ignore_request=ignore_request)
Example #2
0
 def setUpWidgets(self):
     fields = self._getFieldsForWidgets()
     # We need to initialize the widget in two phases because
     # the language vocabulary factory will try to access the product
     # widget to find the final context.
     self.widgets = form.setUpWidgets(
         fields.select('product'),
         self.prefix, self.context, self.request,
         data=self.initial_values, ignore_request=False)
     self.widgets += form.setUpWidgets(
         fields.omit('product'),
         self.prefix, self.context, self.request,
         data=self.initial_values, ignore_request=False)
    def setUpWidgets(self):
        """See `LaunchpadFormView`."""
        # The filter_target widget needs to know the selection made in the
        # filter_status widget.  Set up the widgets in two phases to make this
        # possible.
        self.widgets = form.setUpWidgets(
            self.form_fields.select('filter_status'), self.prefix,
            self.context, self.request, data=self.initial_values,
            ignore_request=False)
        self.widgets += form.setUpWidgets(
            self.form_fields.omit('filter_status'), self.prefix, self.context,
            self.request, data=self.initial_values, ignore_request=False)

        if not self.filter_action.submitted():
            self.setUpEntriesWidgets()
 def setUpWidgets(self, ignore_request=False):
     mod = self.get_mod()
     data = {'moderation': mod}
     self.widgets = form.setUpWidgets(
         self.form_fields, self.prefix, self.context,
         self.request, form=self, data=data,
         ignore_request=ignore_request)
    def __call__(self):
        storage = getUtility(IRedirectionStorage)
        portal = getUtility(ISiteRoot)
        request = self.request
        form = request.form
        status = IStatusMessage(self.request)

        if 'form.button.Remove' in form:
            redirects = form.get('redirects', ())
            for redirect in redirects:
                storage.remove(redirect)
            if len(redirects) == 0:
                status.addStatusMessage(_(u"No aliases selected for removal."), type='info')
            elif len(redirects) > 1:
                status.addStatusMessage(_(u"Aliases removed."), type='info')
            else:
                status.addStatusMessage(_(u"Alias removed."), type='info')
        elif 'form.button.Save' in form:
            dst = IAliasesSchema(self.context)
            dst.managed_types = self.request.form['form.managed_types']
        elif 'form.button.Upload' in form:
            self.upload(form['file'], portal, storage, status)

        self.widgets = setUpWidgets(
            self.form_fields, 'form', self.context, self.request,
            form=self, ignore_request=True)

        return self.template()
Example #6
0
 def setUpWidgets(self, ignore_request=False):
     tz = getattr(self.divisionConfiguration, 'tz', 'UTC')
     data = {'tz': tz}
     self.widgets = form.setUpWidgets(
         self.form_fields, self.prefix, self.context,
         self.request, form=self, data=data,
         ignore_request=ignore_request)
    def setUpWidgets(self, ignore_request=False):
        '''
        From zope.formlib.form.Formbase.
        '''
        self.adapters = {}
        ff = self.form_fields
        fieldnames = [x.__name__ for x in ff]
        data = {}
        for key in fieldnames:
            form_value = self.request.form.get(key)
            if form_value is not None and not form_value == u'':
                data[key] = form_value
                self.request[key] = form_value

        today = date.today()
        if not ff['start'].field.default:
            ff['start'].field.default = (today - timedelta(365))
        if not ff['end'].field.default:
            ff['end'].field.default = (today)

        self.widgets = setUpWidgets(
            ff,
            self.prefix,
            self.context,
            self.request,
            form=self,
            adapters=self.adapters,
            ignore_request=ignore_request,
            data=data
        )
Example #8
0
    def __call__(self, fname=None, fset=None):
        # Note that fset (field set) is not used.  This is added so
        # the function signature is the same as in plone.app.z3cform.
        # This may avoid errors.
        res = {'errmsg': ''}

        if fname is None:
            return json.dumps(res)

        form = aq_inner(self.context)
        context = aq_inner(form.context)
        request = self.request
        processInputs(request)
        setPageEncoding(request)

        raw_fname = fname[len(form.prefix) + 1:]
        formlib_field = form.form_fields[raw_fname]
 
        widgets = formlib.setUpWidgets(
            (formlib_field,), form.prefix, context,
            request, form=form, adapters={}, ignore_request=False)
        widget = widgets[raw_fname]
        error = None
        try:
            widget.getInputValue()
        except:
            pass
        error = widget.error()

        res['errmsg'] = error or ''
        self.request.response.setHeader('Content-Type', 'application/json')
        return json.dumps(res)
Example #9
0
    def setUpWidgets(self, ignore_request=False):
        self.adapters = {}
        self.adapters[IMobileConfiglet] = MobileControl(self.context)

        self.widgets = form.setUpWidgets(self.form_fields, self.prefix,
             self.context, self.request, form=self, adapters=self.adapters,
             ignore_request=ignore_request)
Example #10
0
    def validate_input(self, formname, fieldname, value=None):
        """Given a form (view) name, a field name and the submitted
        value, validate the given field.
        """
        
        # Abort if there was no value changed. Note that the actual value
        # comes along the submitted form, since a widget may require more than
        # a single form field to validate properly.
        if value is None:
            return
        
        context = aq_inner(self.context)
        request = aq_inner(self.request)
        processInputs(self.request)
        
        # Find the form, the field and the widget

        form = getMultiAdapter((context, request), name=formname)
        form = form.__of__(context)
        
        raw_fieldname = fieldname[len(form.prefix)+1:]
        formlib_field = form.form_fields[raw_fieldname]
 
        widgets = formlib.setUpWidgets((formlib_field,), form.prefix, context, 
            request, form=form, adapters={}, ignore_request=False)
            
        widget = widgets[raw_fieldname]
        
        # Attempt to convert the value - this will trigge validation
        ksscore = self.getCommandSet('core')
        kssplone = self.getCommandSet('plone')
        validate_and_issue_message(ksscore, widget, fieldname, kssplone)
 def setUpWidgets(self, ignore_request=False):
     vis = IGSGroupVisibility(self.groupInfo).visibility
     data = {'privacy': vis}
     self.widgets = form.setUpWidgets(
         self.form_fields, self.prefix, self.context,
         self.request, form=self, data=data,
         ignore_request=ignore_request)
Example #12
0
    def setUpWidgets(self, ignore_request=False):
        request = self.request
        if 'form.actions.save' in request:
            # Add annotated values to the request so that we see the saved
            # values on a freshly opened form.
            context = Acquisition.aq_inner(self.context).getCanonical()
            annotations = IAnnotations(context)
            for key in [PRESS_CONTACTS_KEY, FEED_KEY, KEYWORDS_KEY]:
                if annotations.get(key):
                    if key == KEYWORDS_KEY:
                        request.form['form.%s' % key] = ' '.join(
                            annotations[key])
                    elif key == PRESS_CONTACTS_KEY:
                        good_paths = list()
                        # safeguard against missing press contacts
                        for path in annotations[key]:
                            if path.startswith('/'):
                                path = path[1:]
                                try:
                                    context.restrictedTraverse(str(path))
                                    good_paths.append(path)
                                    request.form['form.%s' % key] = \
                                        annotations[key]
                                except AttributeError:
                                    pass
                        if len(good_paths) < len(annotations[key]):
                            annotations[key] = good_paths
                    else:
                        request.form['form.%s' % key] = annotations[key]

        self.adapters = {}
        self.widgets = form.setUpWidgets(
            self.form_fields, self.prefix, self.context, self.request,
            form=self, adapters=self.adapters, ignore_request=ignore_request)
 def __init__(self, context, request):
     SimpleInputWidget.__init__(self, context, request)
     fields = form.Fields(
         Choice(__name__='action', source=self._getActionsVocabulary(),
                title=_('Action')),
         Datetime(__name__='announcement_date', title=_('Date'),
                  required=False, default=None))
     fields['action'].custom_widget = CustomWidgetFactory(
         LaunchpadRadioWidget)
     fields['announcement_date'].custom_widget = CustomWidgetFactory(
         DateTimeWidget)
     if IAnnouncement.providedBy(self.context.context):
         # we are editing an existing announcement
         data = {}
         date_announced = self.context.context.date_announced
         data['announcement_date'] = date_announced
         if date_announced is None:
             data['action'] = 'sometime'
         else:
             data['action'] = 'specific'
     else:
         data = {'action': 'immediately'}
     widgets = form.setUpWidgets(
         fields, self.name, context, request, ignore_request=False,
         data=data)
     self.action_widget = widgets['action']
     self.announcement_date_widget = widgets['announcement_date']
Example #14
0
 def setUpWidgets(self, ignore_request=False):
     
     self.widgets = form.setUpWidgets(
         self.form_fields, self.prefix, self.context, self.request,
         data=self.parameters if self.parameters else self.request.form,
         ignore_request=ignore_request
     )
Example #15
0
    def __call__(self):
        widgets = form.setUpWidgets(
                self.form_fields, 'form', self.context, self.request)
        results = []
        data ={}
        if 'submit' in self.request:
            # get input data
            errors = form.getWidgetsData(widgets, 'form', data)
            invariant_errors = form.checkInvariants(self.form_fields, data)
            if errors:
                results.append('<h4>there were errors</h4>')

            if invariant_errors:
                results.append('<h4>there were invariant errors</h4>')
                for error in invariant_errors:
                    results.append( "<p style='color:red'>%s</p>" % error )

        for w in widgets:
            results.append("<p>%s</p>" % w())
            error = w.error()
            if error:
                results.append("<p style='color:red'>%s</p>" % error)

        results = '\n'.join(results)
        return """<html><body>
        <form>%s <input type="submit" name="submit" value="submit"></form>
        <p>updated: %s</p>
        </body></html>
        """ % (results, str(data))
 def setUpWidgets(self, ignore_request=False):
     self.widgets = form.setUpWidgets(self.form_fields, self.prefix,
                                      self.context, self.request,
                                      form=self,
                                      ignore_request=ignore_request)
     self.widgets['changeSubscription']._displayItemForMissingValue =\
         False
    def setUpWidgets(self, ignore_request=True):
        if self.loggedInUser.anonymous or self.userInfo.anonymous:
            # --=mpj17=-- A tiny hack. These should never be shown.
            specificEmailAddresses = ''
            deliverySetting = GroupEmailSetting.webonly
        else:
            specificEmailAddresses = \
                self.groupEmailUser.get_specific_email_addresses()
            deliverySetting = self.groupEmailUser.get_delivery_setting()
        delivery = 'email'
        default_or_specific = 'default'
        if deliverySetting == GroupEmailSetting.webonly:
            delivery = 'web'
        elif deliverySetting == GroupEmailSetting.digest:
            delivery = 'digest'
        elif deliverySetting == GroupEmailSetting.specific:
            default_or_specific = 'specific'

        default_data = {'default_or_specific': default_or_specific,
                        'destination': specificEmailAddresses,
                        'delivery': delivery,
                        'userId': self.userInfo.id}

        #alsoProvides(self.userInfo, IGSGroupEmailSettings)
        self.widgets = form.setUpWidgets(
            self.form_fields, self.prefix, self.userInfo, self.request,
            data=default_data,
            ignore_request=False)
Example #18
0
    def setUpWidgets(self, ignore_request=False, cookie=None):
        if ignore_request is False:
            start_date, end_date = cookies.get_date_range(self.request)
        else:
            start_date = end_date = None

        context = type("context", (), {
            "range_start_date": start_date,
            "range_end_date": end_date,
            "parliament": None})

        self.adapters = {
            self.IDateRangeSchema: context,
            }
        if self.is_in_parliament(self.context):
            self.form_fields = self.form_fields.omit("parliament")
            
        self.widgets = form.setUpWidgets(
            self.form_fields, self.prefix, self.context, self.request,
            form=self, adapters=self.adapters, ignore_request=True)
        try:
            self.widgets["parliament"]._messageNoValue = _(
                u"parliament...")
        except KeyError:
            pass
        start, end = self.get_start_end_restictions(self.context)
        self.widgets["range_start_date"].set_min_date(start)
        self.widgets["range_end_date"].set_min_date(start)
        self.widgets["range_start_date"].set_max_date(end)
        self.widgets["range_end_date"].set_max_date(end)
 def setUpWidgets(self, ignore_request=False):
     default_addable = default_addable_types(aq_inner(self.context))
     
     self.widgets = form.setUpWidgets(
         self.form_fields, self.prefix, self.context, self.request,
         data=dict(addable_types=default_addable),
         ignore_request=ignore_request)
Example #20
0
    def __call__(self, fname):
        res = {'errmsg': ''}

        form = aq_inner(self.context)
        context = aq_inner(form.context)
        request = self.request
        processInputs(request)
        setPageEncoding(request)

        raw_fname = fname[len(form.prefix) + 1:]
        formlib_field = form.form_fields[raw_fname]
 
        widgets = formlib.setUpWidgets(
            (formlib_field,), form.prefix, context,
            request, form=form, adapters={}, ignore_request=False)
        widget = widgets[raw_fname]
        error = None
        try:
            widget.getInputValue()
        except:
            pass
        error = widget.error()

        res['errmsg'] = error or ''
        self.request.response.setHeader('Content-Type', 'application/json')
        return json.dumps(res)
Example #21
0
 def setUpWidgets(self, ignore_request=False):
     if "form.b_start" in self.request.form \
     or "b_start" in self.request.form:
         self.template = self.results
     super(Search, self).setUpWidgets(ignore_request)
     self.widgets = form.setUpWidgets(
             self.search_fields, self.prefix, self.context,
             self.request, ignore_request=ignore_request)
Example #22
0
 def setUpWidgets(self, ignore_request=False):
     """ Sets up widgets
     """
     self.adapters = {}
     self.widgets = setUpWidgets(
         self.form_fields, self.prefix, self.context, self.request,
         form=self, data=self._data, adapters=self.adapters,
         ignore_request=ignore_request)
    def setUpWidgets(self, ignore_request=False):
        data = {'email': self.userEmail[0], }

        self.widgets = form.setUpWidgets(
            self.form_fields, self.prefix, self.context,
            self.request, form=self, data=data,
            ignore_request=ignore_request)
        assert self.widgets
Example #24
0
 def setUpWidgets(self, ignore_request=False):
     self.widgets = form.setUpWidgets(
             self.form_fields,
             self.prefix,
             self.context,
             self.request,
             ignore_request=ignore_request,
             )
Example #25
0
    def setUpWidgets(self, ignore_request=False):
        data = {'greeting': translate(self.welcomeMessage.greeting),
                'message': translate(self.welcomeMessage.message)}

        self.widgets = form.setUpWidgets(
            self.form_fields, self.prefix, self.context,
            self.request, form=self, data=data,
            ignore_request=ignore_request)
 def setUpWidgets(self, ignore_request=False, data={}):
     self.adapters = {}
     self.widgets = form.setUpWidgets(
         self.form_fields, self.prefix, self.context,
         self.request, form=self, data=data,
         ignore_request=ignore_request)
     for widget in self.widgets:
         widget._displayItemForMissingValue = False
     assert self.widgets
Example #27
0
    def setUpWidgets(self, ignore_request=False):
        """From zope.formlib.form.Formbase.
        Difference: pass extra data=self.request.form.
	"""
        self.adapters = {}
        self.widgets = form.setUpWidgets(
             self.form_fields, self.prefix, self.context, self.request,
             form=self, adapters=self.adapters, ignore_request=False,
             data=self.request.form)
Example #28
0
 def setUpWidgets(self, ignore_request=False):
     self.adapters = {}
     data = {}
     # make the recursive checked if context is folderish
     if self.context.isPrincipiaFolderish:
         data = {'recursive': True}
     self.widgets = setUpWidgets(
         self.form_fields, self.prefix, self.context, self.request,
         form=self, data=data, adapters=self.adapters, ignore_request=ignore_request)
Example #29
0
 def setUpWidgets(self, ignore_request=False, cookie=None):
     class context:
         range_start_date = None
         range_end_date = None
     self.adapters = {
         self.IDateRangeSchema: context,
         }
     self.widgets = form.setUpWidgets(
         self.form_fields, self.prefix, self.context, self.request,
         form=self, adapters=self.adapters, ignore_request=True)
 def setUpWidgets(self, ignore_request=False):
     divisionConfig = self.context.DivisionConfiguration
     data = {
       'greeting': divisionConfig.getProperty(self.greetingProp, 'Hi'),
     }
     self.widgets = form.setUpWidgets(
         self.form_fields, self.prefix, self.context,
         self.request, form=self, data=data,
         ignore_request=ignore_request)
     assert self.widgets