Example #1
0
 def afterSetUp(self):
     self.container = Folder('container').__of__(self.portal)
     self.container._setObject(
         'Base_viewProxyFieldLibrary',
         ERP5Form('Base_viewProxyFieldLibrary', 'Proxys'))
     self.container._setObject('Base_view', ERP5Form('Base_view', 'View'))
     from Products.CMFCore.tests.base.utils import _setUpDefaultTraversable
     _setUpDefaultTraversable()
Example #2
0
    def afterSetUp(self):
        self.auth = 'ERP5TypeTestCase:'
        portal = self.getPortal()
        container = portal.portal_skins.custom
        if self.form_id not in container.objectIds():
            container._setObject(self.form_id, ERP5Form(self.form_id, 'View'))
            form = getattr(container, self.form_id)

            # create some persons in person_module
            self.createPersons()
            # add a ListBox field
            form.manage_addField('listbox', 'listbox', 'ListBox')
            form.listbox.ListBox_setPropertyList(
                field_list_method='zCountDocumentPerOwner',
                field_count_method='',
                field_columns=[
                    'owner | Owner', 'owner_count | Owner Count',
                    'number_count | Reference Count'
                ],
            )

            # create a Field OOoChart
            form.manage_addField(self.ooo_chart_id, self.ooo_chart_id,
                                 'OOoChart')

            # create a Field OOoChart
            form.manage_addField('your_ooochart', 'your_ooochart', 'OOoChart')

            # create a ZSQL Method
            sql = """SELECT owner, count(uid) AS owner_count,
                count(reference) AS number_count
                FROM catalog
                WHERE portal_type = 'Person'
                GROUP BY owner ORDER BY owner_count DESC"""

            template = String(source_string=sql)
            container.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod(
                'zCountDocumentPerOwner', 'zCountDocumentPerOwner',
                'erp5_sql_connection', '', template)
            # enable preference
            preference = self.getPortal(
            ).portal_preferences.default_site_preference
            preference.setPriority(1)
            if preference.getPreferenceState() == 'disabled':
                self.getWorkflowTool().doActionFor(ob=preference,
                                                   action='enable_action',
                                                   wf_id='preference_workflow')

        self.validator = Validator()
        self.tic()
Example #3
0
    def test_03_renderJournal(self, quiet=0, run=run_all_test):
        """
    Everyting which is not event and task is rendered as journal.
    Here we render person module as iCal.
    In this case pt for render current form('Test_view') is default page template(form_view)
    """
        if not run: return
        self.request.set('portal_skin', 'iCal')
        self.portal.portal_skins.changeSkin('iCal')

        self.portal._setObject('Test_view', ERP5Form('Test_view', 'View'))
        self.portal.Test_view.manage_addField('listbox', 'listbox', 'ListBox')

        listbox = self.portal.Test_view.listbox
        self.assertNotEquals(listbox, None)

        listbox.manage_edit_xmlrpc(
            dict(columns=[('title', 'Title'),
                          ('creation_date', 'Creation date'),
                          ('description', 'Description'),
                          ('Base_getICalComponent', 'Component')],
                 sort=[('creation_date | descending')],
                 list_action='list',
                 list_method='searchFolder',
                 count_method='countFolder',
                 selection_name='ical_folder_selection'))

        module = self.portal.person_module
        one = self.portal.person_module.one
        feed_string = self.portal.person_module.Test_view()
        feed_dict = self.parseICalFeed(feed_string)

        self.assertTrue('BEGIN:VCALENDAR' in feed_dict)
        self.assertTrue('END:VCALENDAR' in feed_dict)
        self.assertTrue('BEGIN:VJOURNAL' in feed_dict)
        self.assertTrue('END:VJOURNAL' in feed_dict)
        self.assertEquals(feed_dict['SUMMARY'], 'One')
        self.assertEquals(feed_dict['DESCRIPTION'], 'Person One')
        self.assertEquals(
            feed_dict['CREATED'],
            one.getCreationDate().HTML4().replace('-', '').replace(':', ''))
Example #4
0
    def test_ProxyFieldRenderFormatLines(self):
        # tests that listbox default value in render_format=list mode is
        # compatible with proxy field.
        portal = self.getPortal()
        portal.ListBoxZuite_reset()
        form = portal.FooModule_viewFooList
        listbox = form.listbox
        listbox.ListBox_setPropertyList(
            field_list_method='contentValues',
            field_columns=[
                'listbox_value | Title',
            ],
        )

        # create a form, to store our proxy field inside
        portal._setObject('Test_view', ERP5Form('Test_view', 'View'))
        portal.Test_view.manage_addField('listbox', 'listbox', 'ProxyField')
        proxy_field = portal.Test_view.listbox
        proxy_field.manage_edit_xmlrpc(
            dict(form_id=form.getId(),
                 field_id='listbox',
                 columns=[('proxy_value', 'Proxy')]))

        # this proxy field will not delegate its "columns" value
        proxy_field._surcharged_edit(dict(columns=[('proxy_value', 'Proxy')]),
                                     ['columns'])

        request = get_request()
        request['here'] = portal.foo_module
        line_list = proxy_field.get_value('default',
                                          render_format='list',
                                          REQUEST=request)
        self.assertTrue(isinstance(line_list, list))

        title_line = line_list[0]
        self.assertTrue(title_line.isTitleLine())

        # title of columns is the value overloaded by the proxy field.
        self.assertEqual([('proxy_value', 'Proxy')],
                         title_line.getColumnItemList())
Example #5
0
    def afterSetUp(self):
        self.root = self.portal
        self.root.form = ERP5Form('form', 'Form')
        self.root.getProperty = lambda key, d=None: \
          dict(on_memory_field='123').get(key, d)

        form = self.root.form

        def addField(field):
            form._setObject(field.id, field, set_owner=0, suppress_events=1)

        addField(StringField('field'))
        form.field._p_oid = makeDummyOid()
        # method field
        form.field.values['external_validator'] = Method('this_is_a_method')
        # on-memory field (not in zodb)
        addField(StringField('my_on_memory_field'))
        form.my_on_memory_field._p_oid = None
        addField(StringField('my_on_memory_tales_field'))
        form.my_on_memory_tales_field.manage_tales_xmlrpc(
            {'default': 'python: repr(here)'})
        form.my_on_memory_field._p_oid = None
        # proxy field
        addField(ProxyField.ProxyField('proxy_field'))
        form.proxy_field._p_oid = makeDummyOid()
        form.proxy_field.values['form_id'] = 'form'
        form.proxy_field.values['field_id'] = 'field'
        # proxy field with tales
        addField(ProxyField.ProxyField('proxy_field_tales'))
        form.proxy_field_tales._p_oid = makeDummyOid()
        form.proxy_field_tales.tales['form_id'] = TALESMethod('string:form')
        form.proxy_field_tales.tales['field_id'] = TALESMethod('string:field')
        # datetime field (input style is list)
        addField(DateTimeField('datetime_field'))
        form.datetime_field._p_oid = makeDummyOid()
        form.datetime_field._edit(dict(input_style='list'))
        for i in form.datetime_field._get_sub_form().fields.values():
            i._p_oid = makeDummyOid()
Example #6
0
File: FSForm.py Project: poses/erp5
 def _createZODBClone(self):
     """Create a ZODB (editable) equivalent of this object."""
     obj = ERP5Form(self.getId(), self.title)
     obj.set_xml(self.get_xml())
     return obj
Example #7
0
def getSearchDialog(self, REQUEST=None):
  """Generate a dynamic search dialog from a listbox.
  """
  request = get_request()
  portal = self.getPortalObject()
  category_tool = getToolByName(portal, 'portal_categories')
  types_tool = getToolByName(portal, 'portal_types')
  workflow_tool = getToolByName(portal, 'portal_workflow')

  default_view = self.getTypeInfo().getDefaultViewFor(self)
  listbox = default_view.listbox

  temp_form = ERP5Form('Folder_viewSearchDialog', 'Search').__of__(portal).__of__(self)
  temp_form.pt = 'form_dialog'
  temp_form.action = 'Folder_search'

  selection_name = listbox.get_value('selection_name')
  request.set('selection_name', selection_name)
  request.set('form_id', default_view.getId())


  def addListField(field_id, field_title):
    # this one is for categories
    request_key = field_id
    field_id = 'your_%s_relative_url' % field_id
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, field_title, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewDialogFieldLibrary',
        field_id='your_category_list'))
    field._surcharged_edit(dict(title=field_title), ['title'])
    field._surcharged_tales(
        dict(
            default=TALESMethod(
              'here/portal_selections/%s/dialog_%s_relative_url | '
              'here/portal_selections/%s/dialog_strict_%s_relative_url | nothing'
                                    % (selection_name, request_key,
                                       selection_name, request_key)),
            items=TALESMethod('python: getattr(here.portal_categories["%s"],'
                             'here.portal_preferences.getPreference("'
                             'preferred_category_child_item_list_method_id",'
                             '"getCategoryChildCompactLogicalPathItemList"))('
                             'checked_permission="View", base=1,'
                             'display_none_category=False,'
                             'local_sort_id="int_index")' % request_key)),
            ['title', 'items', 'default'])

    field_id = 'your_%s_relative_url_is_strict_' % request_key
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, field_title, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewFieldLibrary',
        field_id='your_checkbox'))
    field._surcharged_edit(dict(title='%s Strict' % field_title), ['title'])
    field._surcharged_tales(
        dict(
            default=TALESMethod(
              'here/portal_selections/%s/dialog_strict_%s_relative_url | nothing'
                                    % (selection_name, request_key,))),
        ['title', 'default'])

    field_id = 'your_%s_relative_url_is_excluded_' % request_key
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, field_title, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewFieldLibrary',
        field_id='your_checkbox'))
    field._surcharged_edit(dict(title='%s Excluded' % field_title), ['title'])
    from zLOG import LOG
    LOG("selection_name %r, request_key %r" %(selection_name, request_key), 300, field_id)
    field._surcharged_tales(
        dict(
            default=TALESMethod(
              'here/portal_selections/%s/dialog_excluded_%s_relative_url | nothing'
                                    % (selection_name, request_key,))),
        ['title', 'default'])



  def addFloatField(field_id, field_title):
    request_key = field_id
    field_id = 'your_%s' % field_id
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, field_title, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewDialogFieldLibrary',
        field_id='your_money_quantity'))
    field._surcharged_edit(dict(title=field_title), ['title'])
    field._surcharged_tales(
        dict(default=TALESMethod(
            'here/portal_selections/%s/%s_value_ | nothing'
                % (selection_name, request_key))), ['title', 'default'])
    field_id = 'your_%s_usage_' % request_key
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, field_title, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewDialogFieldLibrary',
        field_id='your_category'))
    field._surcharged_edit(dict(
      title=translateString('${key} ${usage}',
                            mapping=dict(key=translateString(column_title),
                                         usage=translateString('Usage'))),
      items=[(translateString('Equals To'), ''),
             (translateString('Greater Than'), 'min'),
             (translateString('Less Than'),'max'),
             (translateString('Not Greater Than'), 'ngt'),
             (translateString('Not Less Than'), 'nlt'),
             ]),

                           ['title', 'items'])
    field._surcharged_tales(
        dict(
            default=TALESMethod(
              'here/portal_selections/%s/%s_usage_ | nothing'
                  % (selection_name, request_key))),
            ['title', 'items', 'default'])

  def addDateTimeField(field_id, field_title):
    request_key = field_id
    field_id = 'your_%s' % field_id
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, field_title, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewDialogFieldLibrary',
        field_id='your_date'))
    field._surcharged_edit(dict(title=field_title), ['title'])
    field._surcharged_tales(
        dict(default=TALESMethod(
            'here/portal_selections/%s/%s_value_ | nothing'
                % (selection_name, request_key))), ['title', 'default'])
    field_id = 'your_%s_usage_' % request_key
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, field_title, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewDialogFieldLibrary',
        field_id='your_category'))
    field._surcharged_edit(dict(title=translateString('${key} ${usage}', mapping=dict(key=translateString(column_title), usage=translateString('Usage'))),
                                items=[(translateString('Equals To'), ''),
                                       (translateString('Greater Than'), 'min'),
                                       (translateString('Less Than'),'max'),
                                       (translateString('Not Greater Than'), 'ngt'),
                                       (translateString('Not Less Than'), 'nlt'),
                                       ]),

                           ['title', 'items'])
    field._surcharged_tales(
        dict(
            default=TALESMethod(
              'here/portal_selections/%s/%s_usage_ | nothing'
                  % (selection_name, request_key))),
            ['title', 'items', 'default'])


  def addStringField(field_id, field_title):
    request_key = field_id
    field_id = 'your_%s' % field_id
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, field_title, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewDialogFieldLibrary',
        field_id='your_title'))
    field._surcharged_edit(dict(title=field_title,
                                description=''), ['title', 'description'])
    field._surcharged_tales(
        dict(default=TALESMethod(
          'here/portal_selections/%s/%s/query |'
          'here/portal_selections/%s/%s | string:'
       % (selection_name, request_key, selection_name, request_key))),
        ['title', 'description', 'default'])


  def addFullTextStringField(field_id, field_title):
    addStringField(field_id, field_title)

  def addKeywordSearchStringField(column_id, column_title,
                                  default_search_key='ExactMatch'):
    addStringField(column_id, column_title)
    request_key = column_id
    field_id = 'your_%s_search_key' % column_id
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, column_title, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewDialogFieldLibrary',
        field_id='your_category'))
    field._surcharged_edit(dict(title=translateString('${key} ${usage}', mapping=dict(key=translateString(column_title), usage=translateString('Search Key'))),
                                description='',
                                items=[(translateString('Default (${search_key})',
                                            mapping=dict(search_key=
                                               translateString(default_search_key))), ''),
                                       (translateString('Exact Match'), 'ExactMatch' ),
                                       (translateString('Keyword'), 'Keyword'),
                                       ]),

                           ['title', 'items'])
    field._surcharged_tales(
        dict(
            default=TALESMethod(
              'here/portal_selections/%s/%s_search_key | nothing'
                      % (selection_name, request_key))),
            ['title', 'items', 'default'])


  base_category_list = set(category_tool.getBaseCategoryList())
  catalog_schema = portal.portal_catalog.schema()
  sql_catalog = portal.portal_catalog.getSQLCatalog()
  sql_catalog_keyword_search_keys = sql_catalog.sql_catalog_keyword_search_keys
  sql_catalog_full_text_search_keys =\
              sql_catalog.sql_catalog_full_text_search_keys

  column_list = ListBoxListRenderer(
                      listbox.widget, listbox, request).getAllColumnList()

  search_list = ListBoxListRenderer(
                      listbox.widget, listbox, request).getSearchColumnIdSet()

  added_column_set = set()

  for column_id, column_title in column_list:
    if column_id in added_column_set:
      continue
    added_column_set.add(column_id)
    short_column_id = column_id
    # strip the usual default_ and _title that are on standard fields.
    if short_column_id.endswith('_translated_title'):
      short_column_id = short_column_id[:-len('_translated_title')]
    if short_column_id.endswith('_title'):
      short_column_id = short_column_id[:-len('_title')]
    if short_column_id.endswith('_reference') and short_column_id not in (
        'source_reference', 'destination_reference'):
      short_column_id = short_column_id[:-len('_reference')]
    if short_column_id.startswith('default_'):
      short_column_id = short_column_id[len('default_'):]
    # is it a base category ?
    if short_column_id in base_category_list:
      # is this base category empty ? then it might be used to relate documents,
      # in that case, simply provide a text input
      if not len(category_tool[short_column_id]):
        default_search_key = 'ExactMatch'
        if column_id in sql_catalog_keyword_search_keys:
          default_search_key = 'Keyword'
        addKeywordSearchStringField(column_id, column_title,
                                    default_search_key=default_search_key)
        continue
      else:
        addListField(short_column_id, column_title)
        continue


    if column_id in catalog_schema:
      if column_id.endswith('state') or column_id.endswith('state_title'):
        # this is a workflow state, it will be handled later
        continue
      elif 'date' in column_id:
        # is it date ? -> provide exact + range
        # TODO: do we need an API in catalog for this ?
        addDateTimeField(column_id, column_title)

      elif 'quantity' in column_id or 'price' in column_id:
        # is it float ? -> provide exact + range
        # TODO: do we need an API in catalog for this ?
        addFloatField(column_id, column_title)
      else:
        if column_id in sql_catalog_full_text_search_keys:
          addFullTextStringField(column_id, column_title)
        else:
          default_search_key = 'ExactMatch'
          if column_id in sql_catalog_keyword_search_keys:
            default_search_key = 'Keyword'
          addKeywordSearchStringField(column_id, column_title,
                          default_search_key=default_search_key)

  allowed_content_types = self.getTypeInfo().getTypeAllowedContentTypeList()
  # remember which workflow we already displayed
  workflow_set = set()
  # possible workflow states
  for type_name in allowed_content_types:
    for workflow_id in workflow_tool.getChainFor(type_name):
      workflow = workflow_tool.getWorkflowById(workflow_id)
      state_var = workflow.variables.getStateVar()

      if state_var in workflow_set:
        continue

      workflow_set.add(state_var)
      if workflow.states is None or \
                len(workflow.states.objectIds()) <= 1:
        continue

      field_id = 'your_%s' % state_var
      if field_id not in temp_form.objectIds():
        temp_form.manage_addField(field_id, field_id, 'ProxyField')
      field = temp_form._getOb(field_id)
      field.manage_edit_xmlrpc(dict(
          form_id='Base_viewDialogFieldLibrary',
          field_id='your_category_list'))
      items = sorted([(translateString(x.title), x.id) for x
                         in workflow.states.objectValues()],
                         key=lambda x:str(x[0]))
      field._surcharged_edit(
              dict(title=translateString(workflow.title),
                   items=items,
                   size=len(items)),
              ['title', 'items', 'size'])
      field._surcharged_tales(
          dict(
              default=TALESMethod(
                'here/portal_selections/%s/%s | python:[]'
                        % (selection_name, state_var))),
              ['title', 'items', 'size', 'default'])


  # if more than 1 allowed content types -> list possible content types
  if len(allowed_content_types) > 1:
    field_id = 'your_portal_type'
    if field_id not in temp_form.objectIds():
      temp_form.manage_addField(field_id, field_id, 'ProxyField')
    field = temp_form._getOb(field_id)
    field.manage_edit_xmlrpc(dict(
        form_id='Base_viewDialogFieldLibrary',
        field_id='your_category_list'))
    field._surcharged_edit(
            dict(title=translateString('Type'),
                 items=[(translateString(x), x) for x in allowed_content_types]),

            ['title', 'items'])
    field._surcharged_tales(
        dict(
            default=TALESMethod(
              'here/portal_selections/%s/portal_type | nothing'
                                    % selection_name)),
            ['title', 'items', 'default'])


  addFullTextStringField('SearchableText', 'Full Text Search')

  # Order fields
  default_group = temp_form.group_list[0]
  field_list = temp_form.get_fields()
  for field in field_list:
    field_id = field.getId()
    if field_id.endswith('search_key') or field_id.endswith('_usage_'):
      temp_form.move_field_group([field_id], default_group, 'right')
    elif field.get_value('field_id') in ('your_category_list',
                                         'your_checkbox') \
        or field_id == 'your_SearchableText':
      temp_form.move_field_group([field_id], default_group, 'center')

  if REQUEST is not None:
    # if called from the web, render the form, other wise return it (for
    # Base_callDialogMethod)
    return temp_form(REQUEST)
  return temp_form
Example #8
0
    def test_02_renderRSS(self, quiet=0, run=run_all_test):
        """
      View person module as RSS, parse XML, see if everything is there.
      In this case pt for render current form('Test_view') is default page template
      and some listbox's columns(i.e. description) label not present in required channel fields
    """
        portal = self.getPortal()
        request = self.app.REQUEST

        request.set('portal_skin', 'RSS')
        portal.portal_skins.changeSkin('RSS')

        self.getPortal()._setObject('Test_view', ERP5Form('Test_view', 'View'))
        portal.Test_view.manage_addField('listbox', 'listbox', 'ListBox')
        portal.Test_view.manage_addField('listbox_link', 'listbox_link',
                                         'StringField')

        listbox = portal.Test_view.listbox
        self.assertNotEquals(listbox, None)
        listbox_link = portal.Test_view.listbox_link
        self.assertNotEquals(listbox_link, None)

        listbox.manage_edit_xmlrpc(
            dict(columns=[('title', 'Title'), ('creation_date', 'pubDate'),
                          ('Base_getRSSAuthor', 'author'), ('link', 'link'),
                          ('absolute_url', 'guid')],
                 sort=[('creation_date | descending')],
                 list_action='list',
                 search=1,
                 select=1,
                 list_method='searchFolder',
                 count_method='countFolder',
                 selection_name='rss_folder_selection'))

        listbox_link.manage_tales_xmlrpc(
            dict(default="python: cell.absolute_url()"))

        one = self.portal.person_module.one
        two = self.portal.person_module.two

        feed_string = self.portal.person_module.Test_view()
        doc = parseString(feed_string)
        rss = doc.childNodes[0]
        channel = rss.getElementsByTagName('channel')[0]
        self.assertEquals(len(rss.getElementsByTagName('channel')), 1)
        self.assertEquals(len(channel.getElementsByTagName('item')), 2)

        titles = [
            getNodeContent(n) for n in channel.getElementsByTagName('title')
        ]
        titles.sort()
        self.assertEquals(titles,
                          ['One', 'Persons', 'Two'
                           ])  # there is channel title and person titles

        item = channel.getElementsByTagName('item')[
            0]  # the two person, because we have default sorting in form
        self.assertEquals(getSubnodeContent(item, 'title'), 'Two')
        self.assertEquals(getSubnodeContent(item, 'description'), 'Person Two')
        self.assertEquals(getSubnodeContent(item, 'author'), 'seb')
        expected_link = two.absolute_url()
        self.assertEquals(getSubnodeContent(item, 'link'), expected_link)
        self.assertEquals(len(item.getElementsByTagName('pubDate')), 1)
        # is date formatted correctly?
        self.assertEquals(two.getCreationDate().rfc822(),
                          getSubnodeContent(item, 'pubDate'))

        item = channel.getElementsByTagName('item')[1]  # the one person
        self.assertEquals(getSubnodeContent(item, 'title'), 'One')
        self.assertEquals(getSubnodeContent(item, 'description'), 'Person One')
        self.assertEquals(getSubnodeContent(item, 'author'), 'seb')
        expected_link = one.absolute_url()
        self.assertEquals(getSubnodeContent(item, 'link'), expected_link)
        self.assertEquals(len(item.getElementsByTagName('pubDate')), 1)
        # is date formatted correctly?
        self.assertEquals(one.getCreationDate().rfc822(),
                          getSubnodeContent(item, 'pubDate'))
Example #9
0
        def generateERP5Form():
            form_name = "view"
            form = ERP5Form(form_name, self.getId())
            parsed_scribus = self._getParsedScribusFile()
            pages = range(len(parsed_scribus))
            #get the context for default values
            context = None
            context_parent = self.aq_parent
            if context_parent is not None:
                context = context_parent.aq_parent
            for page in pages:
                page_content = parsed_scribus[page]
                group_id = page_id = "page_%s" % page
                if page != 0:
                    group = form.add_group(group_id)
                for field_name, fields_values in page_content:
                    field_id = field_name
                    field_title = fields_values["title"]
                    field_order = fields_values["order"]
                    field_erp5_order = fields_values["nb"]
                    field_type = fields_values["type"]
                    field_required = fields_values["required"]
                    field_editable = fields_values["editable"]
                    field_rendering = fields_values["rendering"]
                    field_size_x = fields_values["size_x"]
                    field_size_y = fields_values["size_y"]
                    field_position_x = fields_values["position_x"]
                    field_position_y = fields_values["position_y"]
                    old_group = 'left'
                    # creating new field in form
                    if field_type in ['ListField', 'MultiListField']:
                        field = form.manage_addField(field_id, field_title,
                                                     'ProxyField')
                        field = form[field_name]
                        field.values['form_id'] = 'Base_viewFieldLibrary'
                        if field_type == 'ListField':
                            field.values['field_id'] = 'my_list_field'
                        else:
                            field.values['field_id'] = 'my_multi_list_field'
                        # ne pas déléguer les propriétés items et default
                        field.delegated_list += ('items', 'default')
                        field.manage_tales_xmlrpc({"items":
                          "python: here.EGov_getCategoryChildItemListByFieldName('%s')"\
                          % field_id})
                        field.manage_tales_xmlrpc({
                            "default":
                            "python: here.getProperty('%s')" % field_id[3:]
                        })
                    elif field_type == 'DateTimeField':
                        field = form.manage_addField(field_id, field_title,
                                                     field_type)
                        field = form[field_name]
                        field.values['date_only'] = 1
                        preferences = self.getPortalObject().portal_preferences
                        date_order = preferences.getPreferredDateOrder()
                        if date_order is not None and date_order != '':
                            field.values['input_order'] = date_order
                    else:
                        field = form.manage_addField(field_id, field_title,
                                                     field_type)
                    field = form[field_name]
                    field.values['required'] = field_required
                    field.values['editable'] = field_editable

                    if page != 0:
                        # move fields to destination group
                        form.move_field_group(field_id, old_group, group_id)

            default_groups = ['right', 'center', 'bottom', 'hidden']
            old_group = 'left'
            group_id = 'page_0'
            form.rename_group(old_group, group_id)
            # remove all other groups:
            for existing_group in default_groups:
                form.remove_group(existing_group)
            # updating form settings
            # building dict containing (property, value)
            values = {}
            values['title'] = self.getId()
            values['row_length'] = 4
            values['name'] = form_name
            values['pt'] = "form_render_PDFeForm"
            values['action'] = "PDFDocument_edit"
            values['update_action'] = ""
            values['method'] = 'POST'
            values['enctype'] = 'multipart/form-data'
            values['encoding'] = "UTF-8"
            values['stored_encoding'] = 'UTF-8'
            values['unicode_mode'] = 0
            values['getBackgroundUrl'] = lambda page: \
              'portal_types/%s/renderFormImage?page=%s' % (self.getId(), page)
            values[
                'getCSSUrl'] = lambda: 'portal_types/%s/renderFormCSS' % self.getId(
                )
            # using the dict declared just above to set the attributes
            for key, value in values.items():
                setattr(form, key, value)
            return form
Example #10
0
    def afterSetUp(self):
        # base field library
        self.container = Folder('container').__of__(self.portal)
        self.container._setObject('Base_view', ERP5Form('Base_view', 'Base'))
        base_view = self.base_view = self.container.Base_view
        base_view.manage_addField('my_string_field', 'String Field',
                                  'StringField')
        base_view.manage_addField('my_list_field', 'List Field', 'ListField')
        base_view.manage_addField('my_relation_string_field',
                                  'Old Relation String Field',
                                  'RelationStringField')
        base_view.manage_addField('my_gender', 'Gender', 'ListField')
        base_view.manage_addField('my_custom_description', 'Description',
                                  'TextAreaField')
        base_view.manage_addField('my_another_description', 'Description',
                                  'TextAreaField')
        base_view.my_string_field.values['display_width'] = 30
        base_view.my_list_field.values['size'] = 1
        base_view.my_gender.values['items'] = [('Male', 'Male'),
                                               ('Female', 'Female')]
        base_view.my_another_description.values['editable'] = 0

        # old instance does not have recently added properties.
        del base_view.my_relation_string_field.values['proxy_listbox_ids']
        del base_view.my_relation_string_field.values['relation_form_id']

        # address view
        self.container._setObject('Address_view',
                                  ERP5Form('Address_view', 'Address'))
        address_view = self.address_view = self.container.Address_view
        address_view.manage_addField('my_region', 'Country', 'StringField')
        address_view.my_region.values['size'] = 1
        address_view.my_region.tales['items'] = TALESMethod(
            'here/portal_categories/region/getCategoryChildTitleItemList')

        # person view
        self.container._setObject('Person_view',
                                  ERP5Form('Person_view', 'Person'))
        person_view = self.person_view = self.container.Person_view
        person_view.manage_addField('my_name', 'Name', 'StringField')
        person_view.manage_addField('my_default_region', 'Country',
                                    'ListField')
        person_view.manage_addField('my_custom_description', 'Description',
                                    'TextAreaField')
        person_view.manage_addField('my_custom_description2', 'Description',
                                    'TextAreaField')
        person_view.manage_addField('my_another_description', 'Description',
                                    'TextAreaField')
        person_view.my_name.values['display_maxwidth'] = 20
        person_view.my_default_region.values['size'] = 1
        person_view.my_default_region.tales['items'] = TALESMethod(
            'here/portal_categories/region/getCategoryChildTranslatedLogicalPathItemList'
        )
        person_view.my_default_region.values['scrap_variable'] = 'obsolete'
        person_view.manage_addField('my_career_subordination_title',
                                    'Organisation', 'RelationStringField')
        person_view.my_career_subordination_title.values[
            'base_category'] = 'subordination'
        person_view.my_career_subordination_title.values['portal_type'] = [
            ('Organisation', 'Organisation')
        ]
        person_view.my_career_subordination_title.values[
            'proxy_listbox_ids'] = [
                ('OrganisationModule_viewOrganisationList/listbox',
                 'Organisation')
            ]
        person_view.my_custom_description.values['editable'] = 0
        person_view.my_another_description.values['editable'] = 0