Esempio n. 1
0
    def set(self, instance, value, **kwargs):
        """
        The passed in object should be a records object, or a sequence of dictionaries
        About link data:
          * interpretations:
            * if data not starts with standard protocol names (http://, ftp://) than
              *uid* field data will be used as reference
          * record removed if:
            * no data;
            * data contains UID of not existent object
        About title:
          * if there is UID of existent object and record has same title to the original
            object - title will not be saved.
        """
        catalog = getToolByName(instance, "uid_catalog")

        if value is None:
            value = ()

        if not isinstance(value, (ListType, TupleType)):
            value = value,

        result = []
        for row in value:
            data = {}
            for key in [
                    key for key in set(row)
                    if not (key.startswith('_') or key.endswith('_'))
            ]:
                data[key] = str(row[key]).strip()
            uid = str(row.get("uid", "")).strip()
            link = str(row.get("link", "")).strip()
            title = str(row.get("title", ""))

            if not title == "":
                data["title"] = title

            if link == "":
                continue
            elif self.isRemoteURL(link):
                data["link"] = urlparse.urlunparse(urlparse.urlparse(link))
            else:
                if uid == '':
                    continue

                brains = catalog(UID=uid)
                if len(brains) == 0:
                    continue
                # Found objects with pointed UID
                brain = brains[0]
                data["uid"] = uid
                # Fix title for uid
                if data.get("title", "") == getattr(brain, "Title", ""):
                    data['title'] = ""
            result.append(data)

        DataGridField.set(self, instance, result, **kwargs)

        uids = [r["uid"] for r in result if r.get("uid")]
        ReferenceField.set(self, instance, uids, **kwargs)
    def set(self, instance, value, **kwargs):
        """The passed in object should be a records object, or a sequence of
        dictionaries

        About link data:
          * interpretations:
            * if data not starts with standard protocol names (http://, ftp://)
              than *uid* field data will be used as reference
          * record removed if:
            * no data;
            * data contains UID of not existent object

        About title:
          * if there is UID of existent object and record has same title to the
            original object - title will not be saved.
        """
        catalog = getToolByName(instance, "uid_catalog")

        if value is None:
            value = ()

        if not isinstance(value, (ListType, TupleType)):
            value = value,

        result = []
        for row in value:
            data = {}
            for key in [key for key in set(row)
                        if not(key.startswith('_') or key.endswith('_'))]:
                data[key] = str(encode(row[key], self)).strip()
            uid = str(row.get("uid", "")).strip()
            link = str(row.get("link", "")).strip()
            title = str(encode(row.get("title", ""), self))

            if not title == "":
                data["title"] = title

            if link == "":
                continue
            elif self.isRemoteURL(link):
                data["link"] = urlparse.urlunparse(urlparse.urlparse(link))
            else:
                if uid == '':
                    continue

                brains = catalog(UID=uid)
                if len(brains) == 0:
                    continue
                # Found objects with pointed UID
                brain = brains[0]
                data["uid"] = uid
                # Fix title for uid
                if data.get("title", "") == getattr(brain, "Title", ""):
                    data['title'] = ""
            result.append(data)

        DataGridField.set(self, instance, result, **kwargs)

        uids = [r["uid"] for r in result if r.get("uid")]
        ReferenceField.set(self, instance, uids, **kwargs)
    def get(self, instance, **kwargs):
        """ Return DataGridField value

        Value is a list object of rows.
        Row id dictionary object with standard 'link', 'uid' and 'title' keys
        plus extra informal *url* and *url_title* keys
        """
        purl = getToolByName(instance, "portal_url")
        # use portal_catalog to hide protected object for the logged in user.
        catalog = getToolByName(instance, "portal_catalog")

        result = []
        uids = {}
        rows = DataGridField.get(self, instance, **kwargs)

        for row in rows:
            uid = row.get("uid","")
            link = row.get("link","")
            title = decode(row.get("title",""), self)
            dataGridFieldRowData = row
            dataGridFieldRowData["url"] = ""
            dataGridFieldRowData["default_title"] = None
            if title:
                dataGridFieldRowData["title"] = title
            result.append(dataGridFieldRowData) 
            data = result[-1]
            if uid:
                uids[uid] = data
            else:
                # Process remote URL and collect UIDs
                data["url"] = quote(link, safe='?$#@/:=+;$,&%')
                data["default_title"] = link
                # if title not set for remote url - set it equals to url
                # manually entered link does not have title column field
                if not data.get("title"):
                    data["title"] = data["default_title"]
        # Process UIDs
        if uids:
            brains = catalog(UID=uids.keys())
            for b in brains:
                data = uids[b.UID]
                data["url"] = b.getURL()
                data["link"] = b.getPath()
                data["default_title"] = self._brains_title_or_id(b, instance)
                # If title not set - get it from the brain
                if not data["title"]:
                    data["title"] = data["default_title"]
            # Remove records with links to unexistent objects
            del_uids = set(uids.keys()) - set([b.UID for b in brains])
            result = filter(lambda r: not r["uid"] in del_uids, result)
        return result
Esempio n. 4
0
    def get(self, instance, **kwargs):
        """ Return DataGridField value

        Value is a list object of rows.
        Row id dictionary object with standard 'link', 'uid' and 'title' keys
        plus extra informal *url* and *url_title* keys
        """
        purl = getToolByName(instance, "portal_url")
        # use portal_catalog to hide protected object for the logged in user.
        catalog = getToolByName(instance, "portal_catalog")

        result = []
        uids = {}
        rows = DataGridField.get(self, instance, **kwargs)

        for row in rows:
            uid = row.get("uid", "")
            link = row.get("link", "")
            title = row.get("title", "")
            dataGridFieldRowData = row
            dataGridFieldRowData["url"] = ""
            dataGridFieldRowData["default_title"] = None
            result.append(dataGridFieldRowData)
            data = result[-1]
            if uid:
                uids[uid] = data
            else:
                # Process remote URL and collect UIDs
                data["url"] = quote(link, safe='?$#@/:=+;$,&%')
                data["default_title"] = link
                # if title not set for remote url - set it equals to url
                # manually entered link does not have title column field
                if not data.get("title"):
                    data["title"] = data["default_title"]
        # Process UIDs
        if uids:
            brains = catalog(UID=uids.keys())
            for b in brains:
                data = uids[b.UID]
                data["url"] = b.getURL()
                data["link"] = b.getPath()
                data["default_title"] = self._brains_title_or_id(b, instance)
                # If title not set - get it from the brain
                if not data["title"]:
                    data["title"] = data["default_title"]
            # Remove records with links to unexistent objects
            del_uids = set(uids.keys()) - set([b.UID for b in brains])
            result = filter(lambda r: not r["uid"] in del_uids, result)
        return result
Esempio n. 5
0
                "If the return value is None then the adapter will use request.form "
                "If the return value is a dictionary then the adapter will use the "
                "returned dictionary. "
                "PLEASE NOTE: errors in the evaluation of this expression will "
                "cause an error on form display."),
            size=70,
            ),
        ),
    DataGridField(
        name='field_map',
        widget=DataGridWidget(
            label=u'Field Map',
            description=u"Map the PFG field to the Sharepoint list column.",
            columns={
                'pfg_field': SelectColumn(u'PFG Field',
                                          vocabulary='fgFieldsDisplayList',),
                'sharepoint_column': SelectColumn(u'Sharepoint Column',
                                                  vocabulary='getColumnsVocab'),
                },
            ),
        allow_empty_rows=False,
        required=False,
        columns=('pfg_field', 'sharepoint_column'),
    ),

    #DataGridField(
    #    name='upload_field_map',
    #    widget=DataGridWidget(
    #        label=u'Field Map',
    #        description=u"Map the PFG field to the Sharepoint list column.",
    #        columns={
    #            'pfg_field': SelectColumn(u'PFG Field',
Esempio n. 6
0
 DataGridField('pageColumns',
               required=True,
               storage=atapi.AnnotationStorage(),
               columns=("id", "label", "description", "type", "vocabulary", "options"),
               widget=DataGridWidget(
                   label=_(u"Columns"),
                   description=_('help_pageColumns',
                                 default=u"Definition of rows inside the table"),
                   visible={'view': 'invisible', 'edit': 'visible'},
                   helper_js=('datagridwidget.js', 'datagridwidget_patches.js', 'datagridmultiselect.js'),
                   columns={
                       'id': Column(_(u"Column id"), required=True),
                       'label': Column(_(u"Column label"), required=True),
                       'description': TextAreaColumn(_(u"Column description")),
                       'type': SelectColumn(_(u"Type of data"),
                                            vocabulary_factory="collective.tablepage.vocabulary.column_types",
                                            required=True,
                                            default="String"),
                       'vocabulary': TextAreaColumn(_(u"Column configuration"),
                                                    col_description=_("vocabulary_column_description",
                                                                      default=u"Some columns types will need this.\n"
                                                                              u"For \"Select\" type: used for defining the "
                                                                              u"vocabulary (one item on per row).\n"
                                                                              u"For \"Computed\" type: write there the TALES expression.")),
                       'options': MultiSelectColumn(_(u"Additional features"),
                                                    col_description=_("options_column_description",
                                                                      default=u"Other options you can activate on the column"),
                                                    vocabulary_factory="collective.tablepage.vocabulary.row_options"),
                   },
               ),
               ),
    StringField(
        'title',
        required=True,
        searchable=0,
        default='List of Students',
        widget=StringWidget(
            label='Title',
            description='title',
        ),
    ),
    DataGridField(
        'StudentIdList',
        searchable=True,  # One unit tests checks whether text search works
        widget=DataGridWidget(label='StudentIds',
                              columns={
                                  "studentid": Column("Student Id"),
                                  "randomnumber": Column("Random id number"),
                                  "email": Column("Student email"),
                              }),
        columns=('studentid', 'randomnumber', 'email'),
    ),
))

#########################################################
## check can course code be editited??????, if not FIXME
########################################################


class StudentTesting(base.ATCTContent):
    """
    A Course belongs to a specific Department although it can contain tutorials from any Department.
Esempio n. 8
0
 DataGridField(
     name='availableAreas',
     default=({
         'id': 'ui',
         'title': 'User interface',
         'description': 'User interface issues'
     }, {
         'id': 'functionality',
         'title': 'Functionality',
         'description': 'Issues with the basic functionality'
     }, {
         'id':
         'process',
         'title':
         'Process',
         'description':
         'Issues relating to the development process itself'
     }),
     widget=DataGridWidget(
         label=_(u'Poi_label_availableAreas', default=u"Areas"),
         description=_(
             u'Poi_help_availableAreas',
             default="Enter the issue topics/areas for this tracker."),
         column_names=('Short name', 'Title', 'Description'),
     ),
     allow_empty_rows=False,
     required=True,
     validators=('isDataGridFilled', ),
     columns=(
         'id',
         'title',
         'description',
     )),
            "Enter any introductory help text you'd like to display on the tracker front page.",
            label_msgid='gcommons_label_helpText',
            description_msgid='gcommons_help_helpText',
            i18n_domain='gcommons.Core',
        ),
        default_output_type='text/html',
        searchable=True,
        default="""
        <h3>Payment system</h3>
        """),
    DataGridField(
        name='items',
        widget=DataGridWidget(
            label=_("Items"),
            description=
            _('Take your time to fill in the items that will be billed. For radio buttons use same id plus colon (see help).'
              ),
            column_names=('Id', 'Name', 'Description', 'Price'),
        ),
        allow_empty_rows=False,
        required=False,
        columns=('id', 'name', 'description', 'price')),
))


def finalizeConferencePaymentSchema(schema):
    schema['title'].storage = atapi.AnnotationStorage()
    schema['description'].storage = atapi.AnnotationStorage()
    schemata.finalizeATCTSchema(schema, moveDiscussion=False)
    return schema

 DataGridField(
     'fieldMapping',
     required=False,
     write_permission=ModifyPortalContent,
     read_permission=ModifyPortalContent,
     storage=atapi.AnnotationStorage(),
     searchable=False,
     allow_delete=True,
     allow_insert=True,
     allow_reorder=True,
     columns=('form', 'content'),
     widget=DataGridWidget(
         label=_('field_mapping_label', default=u'Field mapping'),
         description=_('field_mapping_help',
                       default=u'Map form fields to field of the '
                       u'selected content type. Please note, '
                       u'that you must first select the '
                       u'content type, then save this adapter, '
                       u"and only then you'll be able to see the "
                       u'fields of the selected content type.'),
         columns={
             'form':
             SelectColumn(_('field_mapping_form_label',
                            default=u'Select a form field'),
                          vocabulary='listFormFields'),
             'content':
             SelectColumn(_('field_mapping_content_label',
                            default=u'to be mapped to a content field.'),
                          vocabulary='listContentFields')
         },
     )),
Esempio n. 11
0
    ),

    # This field is used
    #    if invitations are allowed, and users enforced: to hold invitations, else hidden
    #    if gcommons.Users not installed, to hold users
    DataGridField(
        name='unregisteredRelators',
        widget=DataGridWidget(
            label=_("Other Authors"),
            condition="here/condition_unregistered",
            description=
            _('If applicable, other authors or contributors of the paper or persons responsible for this piece, besides the principal author.'
              ),
            columns={
                'relationship':
                SelectColumn(_(u'Relation'), vocabulary="listRelatorTypes"),
                'name':
                Column(_(u'Name')),
                'institution':
                Column(_('Institution')),
                'email':
                Column(_('email')),
            },
        ),
        allow_empty_rows=False,
        required=False,
        columns=('relationship', 'name', 'institution', 'email')),

    #
    # Overrride default fields creators and contributors
    atapi.ComputedField(
        name='creators',