Exemplo n.º 1
0
    def error(self, values, continuation_url=None):
        """
        Construct HTTP error response.

        This is an application-specific override of a method defined 
        in ContentNegotiationView.

        values      is a dictionary of values to be passed as a context to the
                    error display page.  Typically, this contains more details
                    about the error (cf. ContentNegotiationView.errorvalues)
        continutation_url
                    is a URL to (re)display when any error is dismissed or has 
                    otherwise been handled.
        """
        # log.info(
        #     "AnnalistGenericView.error: values %r, continuation_url %s"%(values, continuation_url)
        #     )
        template = loader.get_template('annalist_error.html')
        context = RequestContext(self.request, values)
        if continuation_url:
            context['continuation_url'] = continuation_url
            context['continuation_param'] = uri_params(
                {'continuation_url': continuation_url})
        return HttpResponse(template.render(context),
                            status=values['status'],
                            reason=values['reason'])
Exemplo n.º 2
0
 def get_continuation_param(self):
     """
     Return continuation URL specified for the current request, or None.
     """
     cont_here = self.view.continuation_here(self.request_dict,
                                             self.default_continue)
     return uri_params({"continuation_url": cont_here})
Exemplo n.º 3
0
 def get_continuation_param(self):
     """
     Generate continuation parameter string for return back to the current request page
     """
     cparam = ""
     chere  = self.get_continuation_url()
     if chere:
         cparam = uri_params({'continuation_url': chere})
     return cparam
Exemplo n.º 4
0
 def get_continuation_param(self):
     """
     Generate continuation parameter string for return back to the current request page
     """
     cparam = ""
     chere = self.get_continuation_url()
     if chere:
         cparam = uri_params({'continuation_url': chere})
     return cparam
Exemplo n.º 5
0
    def error(self, values, continuation_url=None):
        """
        Construct HTTP error response.

        This is an application-specific override of a method defined 
        in ContentNegotiationView.

        values      is a dictionary of values to be passed as a context to the
                    error display page.  Typically, this contains more details
                    about the error (cf. ContentNegotiationView.errorvalues)
        continutation_url
                    is a URL to (re)display when any error is dismissed or has 
                    otherwise been handled.
        """
        # log.info(
        #     "AnnalistGenericView.error: values %r, continuation_url %s"%(values, continuation_url)
        #     )
        template = loader.get_template('annalist_error.html')
        context = dict(values)
        if continuation_url:
            context['continuation_url']   = continuation_url
            context['continuation_param'] = uri_params({ 'continuation_url': continuation_url })
        return HttpResponse(template.render(context), status=values['status'], reason=values['reason'])
Exemplo n.º 6
0
    def test_get_default_all_list(self):
        u = entitydata_list_all_url("testcoll") + "?continuation_url=/xyzzy/"
        r = self.client.get(u)
        self.assertEqual(r.status_code,   200)
        self.assertEqual(r.reason_phrase, "OK")
        self.assertContains(r, '<h2 class="page-heading">List entities with type information</h2>', html=True)
        self.assertMatch(r.content, r'<input.type="hidden".name="continuation_url".+value="/xyzzy/"/>')
        cont = uri_params({"continuation_url": u})
        tooltip1 = "" # 'title="%s"'%r.context['fields'][0]['field_help']
        tooltip2 = "" # 'title="%s"'%r.context['fields'][1]['field_help']
        tooltip3 = "" # 'title="%s"'%r.context['fields'][2]['field_help']
        rowdata = """
            <div class="tbody row select-row">
              <div class="small-1 columns">
                <input type="checkbox" class="select-box right" name="entity_select"
                       value="testtype/entity1" />
              </div>
              <div class="small-11 columns">
                <div class="row view-listrow">
                  <div class="view-value small-3 columns" %(tooltip1)s>
                    <a href="%(base)s/c/testcoll/d/testtype/entity1/%(cont)s">entity1</a>
                  </div>
                  <div class="view-value small-2 columns" %(tooltip2)s>
                    <a href="/testsite/c/testcoll/d/_type/testtype/%(cont)s">RecordType testcoll/_type/testtype</a>
                  </div>
                  <div class="view-value small-7 columns" %(tooltip3)s>
                    <span>Entity testcoll/testtype/entity1</span>
                  </div>
                </div>
              </div>
            </div>
            """%(
                { 'base':     TestBasePath
                , 'cont':     cont
                , 'tooltip1': tooltip1
                , 'tooltip2': tooltip2
                , 'tooltip3': tooltip3
                }
            )
        # log.info(r.content)
        self.assertContains(r, rowdata, html=True)

        # Test context
        #@@TODO: use new function to create list context for comparison,
        #        like entity view context tests, rather than pick out the fields.
        #
        # self.assertEqual(r.context['title'],            site_title())
        self.assertEqual(r.context['title'],            "List entities with type information - Collection testcoll")
        self.assertEqual(r.context['coll_id'],          "testcoll")
        self.assertEqual(r.context['type_id'],          None)
        list_choices = r.context['list_choices']
        self.assertEqual(set(list_choices.options),    set(self.list_ids))
        self.assertEqual(list_choices['field_value'],   "Default_list_all")
        self.assertEqual(r.context['continuation_url'], "/xyzzy/")
        # Field descriptions
        head_fields = context_list_head_fields(r.context)
        self.assertEqual(len(head_fields), 1)       # One row of 3 cols..
        self.assertEqual(len(head_fields[0].description['row_field_descs']), 3)
        f0 = context_view_field(r.context, 0, 0)
        f1 = context_view_field(r.context, 0, 1)
        f2 = context_view_field(r.context, 0, 2)
        #  1st field
        self.assertDictionaryMatch(f0, 
            get_bound_field("Entity_id", "", placement="small:0,3")
            )
        #  2nd field
        self.assertDictionaryMatch(f1, 
            get_bound_field("Entity_type", "", 
                placement="small:3,2",
                options=self.type_ids
                )
            )
        # 3rd field
        self.assertDictionaryMatch(f2, 
            get_bound_field("Entity_label", "", placement="small:5,7")
            )
        # Entities and bound fields
        entities = context_list_entities(r.context)
        self.assertEqual(len(entities), 6)
        entity_fields = (
            [ {'entity_type_id': "_type",     'annal:id': "testtype",  'rdfs:label': "RecordType testcoll/_type/testtype"}
            , {'entity_type_id': "_type",     'annal:id': "testtype2", 'rdfs:label': "RecordType testcoll/_type/testtype2"}
            , {'entity_type_id': "testtype",  'annal:id': "entity1",   'rdfs:label': "Entity testcoll/testtype/entity1"}
            , {'entity_type_id': "testtype",  'annal:id': "entity2",   'rdfs:label': "Entity testcoll/testtype/entity2"}
            , {'entity_type_id': "testtype",  'annal:id': "entity3",   'rdfs:label': "Entity testcoll/testtype/entity3"}
            , {'entity_type_id': "testtype2", 'annal:id': "entity4",   'rdfs:label': "Entity testcoll/testtype2/entity4"}
            ])
        field_keys = ('annal:id', 'entity_type_id', 'rdfs:label')
        for eid in range(6):
            item_fields = context_list_item_fields(r.context, entities[eid])
            for fid in range(3):
                item_field = item_fields[fid]
                head_field = head_fields[0].description['row_field_descs'][fid]
                # log.info("Item field: %r"%(item_field,))
                # log.info("Head field: %r"%(head_field,))
                # Check that row field descriptions match corresponding heading feld descriptions
                for fkey in (
                        'field_id', 'field_name', 'field_label', 
                        'field_property_uri', 'field_render_type',
                        'field_placement', 'field_value_type'):
                    self.assertEqual(item_field.description[fkey], head_field[fkey])
                # Check row field values
                fkey = field_keys[fid]
                self.assertEqual(item_field['field_value'],    entity_fields[eid][fkey])
                self.assertEqual(item_field['entity_type_id'], entity_fields[eid]['entity_type_id'])
        return
Exemplo n.º 7
0
 def test_get_fields_list_no_continuation(self):
     u = entitydata_list_type_url("testcoll",
                                  layout.FIELD_TYPEID,
                                  list_id="Field_list",
                                  scope="all",
                                  query_params={"foo": "bar"})
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     # self.assertContains(r, site_title("<title>%s</title>"))
     # self.assertContains(r, "<h3>List 'Field_list' of entities in collection 'testcoll'</h3>", html=True)
     curi = continuation_params_url(u)
     cont = uri_params({"continuation_url": curi})
     tooltip1 = ""
     tooltip2 = ""
     tooltip3 = ""
     tooltip4 = ""
     rowdata1 = """
         <div class="tbody row select-row">
           <div class="small-1 columns">
             <input type="checkbox" class="select-box right" name="entity_select"
                    value="%(field_typeid)s/Bib_address" />
           </div>
           <div class="small-11 columns">
             <div class="row view-listrow">
               <div class="view-value small-4 medium-3 columns" %(tooltip1)s>
                 <a href="%(base)s/c/testcoll/d/%(field_typeid)s/Bib_address/%(cont)s">Bib_address</a>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip2)s>
                 <a href="%(base)s/c/testcoll/d/_enum_render_type/Text/%(cont)s">Short text</a>
               </div>
               <div class="view-value small-12 medium-3 columns show-for-medium-up" %(tooltip3)s>
                 <span>annal:Text</span>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip4)s>
                 <span>Address</span>
               </div>
             </div>
           </div>
         </div>
         """ % ({
         'base': TestBasePath,
         'cont': cont,
         'tooltip1': tooltip1,
         'tooltip2': tooltip2,
         'tooltip3': tooltip3,
         'tooltip4': tooltip4,
         'field_typeid': layout.FIELD_TYPEID
     })
     # log.info("*** r.content: "+r.content)
     self.assertContains(r, rowdata1, html=True)
     # Test context
     self.assertEqual(r.context['coll_id'], "testcoll")
     self.assertEqual(r.context['type_id'], layout.FIELD_TYPEID)
     self.assertEqual(r.context['continuation_url'], "")
     list_choices = r.context['list_choices']
     self.assertEqual(set(list_choices.options), set(self.list_ids))
     self.assertEqual(list_choices['field_value'], "Field_list")
     # Fields
     head_fields = context_list_head_fields(r.context)
     self.assertEqual(len(head_fields), 1)  # One row of 4 cols..
     self.assertEqual(len(head_fields[0].description['row_field_descs']), 4)
     return
Exemplo n.º 8
0
 def get_continuation_param(self):
     cparam = self.continuation_url
     if cparam:
         cparam = uri_params({'continuation_url': cparam})
     log.debug('bound_field.get_continuation_param %s' % (cparam, ))  #@@
     return cparam
Exemplo n.º 9
0
 def test_get_fields_list_no_continuation(self):
     u = entitydata_list_type_url(
         "testcoll", layout.FIELD_TYPEID, list_id="Field_list", scope="all",
         query_params={"foo": "bar"}
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     # self.assertContains(r, site_title("<title>%s</title>"))
     # self.assertContains(r, "<h3>List 'Field_list' of entities in collection 'testcoll'</h3>", html=True)
     curi     = continuation_params_url(u)
     cont     = uri_params({"continuation_url": curi})
     tooltip1 = ""
     tooltip2 = ""
     tooltip3 = ""
     tooltip4 = ""
     rowdata1 = """
         <div class="tbody row select-row">
           <div class="small-1 columns">
             <input type="checkbox" class="select-box right" name="entity_select"
                    value="%(field_typeid)s/Bib_address" />
           </div>
           <div class="small-11 columns">
             <div class="row view-listrow">
               <div class="view-value small-4 medium-3 columns" %(tooltip1)s>
                 <a href="%(base)s/c/testcoll/d/%(field_typeid)s/Bib_address/%(cont)s">Bib_address</a>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip2)s>
                 <a href="%(base)s/c/testcoll/d/_enum_render_type/Text/%(cont)s">Short text</a>
               </div>
               <div class="view-value small-12 medium-3 columns show-for-medium-up" %(tooltip3)s>
                 <span>annal:Text</span>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip4)s>
                 <span>Address</span>
               </div>
             </div>
           </div>
         </div>
         """%(
             { 'base':           TestBasePath
             , 'cont':           cont
             , 'tooltip1':       tooltip1
             , 'tooltip2':       tooltip2
             , 'tooltip3':       tooltip3
             , 'tooltip4':       tooltip4
             , 'field_typeid':   layout.FIELD_TYPEID
             }
         )
     # log.info("*** r.content: "+r.content)
     self.assertContains(r, rowdata1, html=True)
     # Test context
     self.assertEqual(r.context['coll_id'],          "testcoll")
     self.assertEqual(r.context['type_id'],          layout.FIELD_TYPEID)
     self.assertEqual(r.context['continuation_url'], "")
     list_choices = r.context['list_choices']
     self.assertEqual(set(list_choices.options),     set(self.list_ids))
     self.assertEqual(list_choices['field_value'],   "Field_list")
     # Fields
     head_fields = context_list_head_fields(r.context)
     self.assertEqual(len(head_fields), 1)       # One row of 4 cols..
     self.assertEqual(len(head_fields[0].description['row_field_descs']), 4)
     return
Exemplo n.º 10
0
    def test_get_default_all_list(self):
        u = entitydata_list_all_url("testcoll") + "?continuation_url=/xyzzy/"
        r = self.client.get(u)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.reason_phrase, "OK")
        # self.assertContains(r, site_title("<title>%s</title>"))
        self.assertContains(r,
                            "<h3>List entities with type information</h3>",
                            html=True)
        self.assertMatch(
            r.content,
            r'<input.type="hidden".name="continuation_url".+value="/xyzzy/"/>')
        cont = uri_params({"continuation_url": u})
        # rowdata = """
        #     <tr class="select-row">
        #         <td class="small-2 columns"><a href="%(base)s/c/testcoll/d/testtype/entity1/%(cont)s">entity1</a></td>
        #         <td class="small-2 columns"><a href="%(base)s/c/testcoll/d/_type/testtype/%(cont)s">testtype</a></td>
        #         <td class="small-8 columns">Entity testcoll/testtype/entity1</td>
        #         <td class="select-row">
        #             <input type="checkbox" name="entity_select" value="testtype/entity1" />
        #         </td>
        #     </tr>
        #     """%({'base': TestBasePath, 'cont': cont})
        rowdata = """
            <div class="trow row select-row">
              <div class="small-1 columns">
                <input type="checkbox" class="select-box right" name="entity_select"
                       value="testtype/entity1" />
              </div>
              <div class="small-11 columns">
                <div class="row">
                    <div class="small-3 columns"><a href="%(base)s/c/testcoll/d/testtype/entity1/%(cont)s">entity1</a></div>
                    <div class="small-2 columns"><a href="/testsite/c/testcoll/d/_type/testtype/%(cont)s">testtype</a></div>
                    <div class="small-7 columns">
                    Entity testcoll/testtype/entity1
                    </div>
                </div>
              </div>
            </div>
            """ % ({
            'base': TestBasePath,
            'cont': cont
        })
        # log.info(r.content)
        self.assertContains(r, rowdata, html=True)
        # Test context
        # self.assertEqual(r.context['title'],            site_title())
        self.assertEqual(r.context['title'], "Collection testcoll")
        self.assertEqual(r.context['coll_id'], "testcoll")
        self.assertEqual(r.context['type_id'], None)
        list_choices = r.context['list_choices']
        self.assertEqual(set(list_choices.options), set(self.initial_list_ids))
        self.assertEqual(list_choices['field_value'], "Default_list_all")
        self.assertEqual(r.context['continuation_url'], "/xyzzy/")

        # Unbound field descriptions
        self.assertEqual(len(r.context['fields']), 3)
        #  1st field
        self.assertEqual(r.context['fields'][0]['field_id'], 'Entity_id')
        self.assertEqual(r.context['fields'][0]['field_name'], 'entity_id')
        self.assertEqual(r.context['fields'][0]['field_label'], 'Id')
        self.assertEqual(r.context['fields'][0]['field_placeholder'],
                         "(entity id)")
        self.assertEqual(r.context['fields'][0]['field_property_uri'],
                         "annal:id")
        self.assertEqual(r.context['fields'][0]['field_render_type'],
                         "EntityId")
        self.assertEqual(r.context['fields'][0]['field_placement'].field,
                         "small-3 columns")
        self.assertEqual(r.context['fields'][0]['field_value_type'],
                         "annal:Slug")
        self.assertEqual(r.context['fields'][0]['field_value'], "")
        self.assertEqual(r.context['fields'][0]['entity_type_id'], "")
        #  2nd field
        self.assertEqual(r.context['fields'][1]['field_id'], 'Entity_type')
        self.assertEqual(r.context['fields'][1]['field_name'], 'entity_type')
        self.assertEqual(r.context['fields'][1]['field_label'], 'Type')
        self.assertEqual(r.context['fields'][1]['field_placeholder'],
                         "(type id)")
        self.assertEqual(r.context['fields'][1]['field_property_uri'],
                         "annal:type_id")
        self.assertEqual(r.context['fields'][1]['field_render_type'],
                         "EntityTypeId")
        self.assertEqual(r.context['fields'][1]['field_placement'].field,
                         "small-2 columns")
        self.assertEqual(r.context['fields'][1]['field_value_type'],
                         "annal:Slug")
        self.assertEqual(r.context['fields'][1]['field_value'], "")
        self.assertEqual(r.context['fields'][1]['entity_type_id'], "")
        # 3rd field
        self.assertEqual(r.context['fields'][2]['field_id'], 'Entity_label')
        self.assertEqual(r.context['fields'][2]['field_name'], 'Entity_label')
        self.assertEqual(r.context['fields'][2]['field_label'], 'Label')
        self.assertEqual(r.context['fields'][2]['field_placeholder'],
                         "(label)")
        self.assertEqual(r.context['fields'][2]['field_property_uri'],
                         "rdfs:label")
        self.assertEqual(r.context['fields'][2]['field_render_type'], "Text")
        self.assertEqual(r.context['fields'][2]['field_placement'].field,
                         "small-7 columns")
        self.assertEqual(r.context['fields'][2]['field_value_type'],
                         "annal:Text")
        self.assertEqual(r.context['fields'][2]['field_value'], "")
        self.assertEqual(r.context['fields'][2]['entity_type_id'], "")
        # Entities and bound fields
        entities = context_list_entities(r.context)
        self.assertEqual(len(entities), 6)
        entity_fields = ([{
            'entity_type_id': "_type",
            'annal:id': "testtype",
            'rdfs:label': "RecordType testcoll/testtype"
        }, {
            'entity_type_id': "_type",
            'annal:id': "testtype2",
            'rdfs:label': "RecordType testcoll/testtype2"
        }, {
            'entity_type_id': "testtype",
            'annal:id': "entity1",
            'rdfs:label': "Entity testcoll/testtype/entity1"
        }, {
            'entity_type_id': "testtype",
            'annal:id': "entity2",
            'rdfs:label': "Entity testcoll/testtype/entity2"
        }, {
            'entity_type_id': "testtype",
            'annal:id': "entity3",
            'rdfs:label': "Entity testcoll/testtype/entity3"
        }, {
            'entity_type_id': "testtype2",
            'annal:id': "entity4",
            'rdfs:label': "Entity testcoll/testtype2/entity4"
        }])
        field_keys = ('annal:id', 'entity_type_id', 'rdfs:label')
        for eid in range(6):
            for fid in range(3):
                item_field = context_list_item_fields(r.context,
                                                      entities[eid])[fid]
                head_field = context_list_head_fields(r.context)[fid]
                # log.info("Item field: %r"%(item_field,))
                # log.info("Head field: %r"%(head_field,))
                # Check that row field descriptions match corresponding heading feld descriptions
                for fkey in ('field_id', 'field_name', 'field_label',
                             'field_property_uri', 'field_render_type',
                             'field_placement', 'field_value_type'):
                    self.assertEqual(item_field[fkey], head_field[fkey])
                # Check row field values
                fkey = field_keys[fid]
                self.assertEqual(item_field['field_value'],
                                 entity_fields[eid][fkey])
                self.assertEqual(item_field['entity_type_id'],
                                 entity_fields[eid]['entity_type_id'])
        return
    def test_get_default_all_list(self):
        u = entitydata_list_all_url("testcoll") + "?continuation_url=/xyzzy/"
        r = self.client.get(u)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.reason_phrase, "OK")
        self.assertContains(
            r,
            '<h2 class="page-heading">List entities with type information</h2>',
            html=True)
        self.assertMatch(
            r.content,
            r'<input.type="hidden".name="continuation_url".+value="/xyzzy/"/>')
        cont = uri_params({"continuation_url": u})
        # cont = ""
        # print "@@ "+repr(r.context['fields'][0]['field_help'])
        # print "@@ "+repr(r.context['fields'][1]['field_help'])
        # print "@@ "+repr(r.context['fields'][2]['field_help'])
        tooltip1 = ""  # 'title="%s"'%r.context['fields'][0]['field_help']
        tooltip2 = ""  # 'title="%s"'%r.context['fields'][1]['field_help']
        tooltip3 = ""  # 'title="%s"'%r.context['fields'][2]['field_help']
        rowdata = """
            <div class="tbody row select-row">
              <div class="small-1 columns">
                <input type="checkbox" class="select-box right" name="entity_select"
                       value="testtype/entity1" />
              </div>
              <div class="small-11 columns">
                <div class="row view-listrow">
                  <div class="view-value small-3 columns" %(tooltip1)s>
                    <a href="%(base)s/c/testcoll/d/testtype/entity1/%(cont)s">entity1</a>
                  </div>
                  <div class="view-value small-2 columns" %(tooltip2)s>
                    <a href="/testsite/c/testcoll/d/_type/testtype/%(cont)s">RecordType testcoll/testtype</a>
                  </div>
                  <div class="view-value small-7 columns" %(tooltip3)s>
                    <span>Entity testcoll/testtype/entity1</span>
                  </div>
                </div>
              </div>
            </div>
            """ % ({
            'base': TestBasePath,
            'cont': cont,
            'tooltip1': tooltip1,
            'tooltip2': tooltip2,
            'tooltip3': tooltip3
        })
        # log.info(r.content)
        self.assertContains(r, rowdata, html=True)
        # Test context
        # self.assertEqual(r.context['title'],            site_title())
        self.assertEqual(
            r.context['title'],
            "List entities with type information - Collection testcoll")
        self.assertEqual(r.context['coll_id'], "testcoll")
        self.assertEqual(r.context['type_id'], "Default_type")
        list_choices = r.context['list_choices']
        self.assertEqual(set(list_choices.options), set(self.list_ids))
        self.assertEqual(list_choices['field_value'], "Default_list_all")
        self.assertEqual(r.context['continuation_url'], "/xyzzy/")

        # Unbound field descriptions
        head_fields = context_list_head_fields(r.context)
        self.assertEqual(len(head_fields), 1)  # One row of 3 cols..
        self.assertEqual(len(head_fields[0]['row_field_descs']), 3)
        f0 = context_view_field(r.context, 0, 0)
        f1 = context_view_field(r.context, 0, 1)
        f2 = context_view_field(r.context, 0, 2)
        #  1st field
        self.assertEqual(f0['field_id'], 'Entity_id')
        self.assertEqual(f0['field_name'], 'entity_id')
        self.assertEqual(f0['field_label'], 'Id')
        self.assertEqual(f0['field_placeholder'], "(entity id)")
        self.assertEqual(f0['field_property_uri'], "annal:id")
        self.assertEqual(f0['field_render_type'], "EntityId")
        self.assertEqual(f0['field_value_mode'], "Value_direct")
        self.assertEqual(f0['field_value_type'], "annal:Slug")
        self.assertEqual(f0['field_placement'].field, "small-3 columns")
        self.assertEqual(f0['field_value'], "")
        self.assertEqual(f0['entity_type_id'], "")
        #  2nd field
        self.assertEqual(f1['field_id'], 'Entity_type')
        self.assertEqual(f1['field_name'], 'entity_type')
        self.assertEqual(f1['field_label'], 'Type')
        self.assertEqual(f1['field_placeholder'], "(type id)")
        self.assertEqual(f1['field_property_uri'], "annal:type_id")
        self.assertEqual(f1['field_render_type'], "EntityTypeId")
        self.assertEqual(f1['field_value_mode'], "Value_direct")
        self.assertEqual(f1['field_value_type'], "annal:Slug")
        self.assertEqual(f1['field_placement'].field, "small-2 columns")
        self.assertEqual(f1['field_value'], "")
        self.assertEqual(f1['entity_type_id'], "")
        # 3rd field
        self.assertEqual(f2['field_id'], 'Entity_label')
        self.assertEqual(f2['field_name'], 'Entity_label')
        self.assertEqual(f2['field_label'], 'Label')
        self.assertEqual(f2['field_placeholder'], "(label)")
        self.assertEqual(f2['field_property_uri'], "rdfs:label")
        self.assertEqual(f2['field_render_type'], "Text")
        self.assertEqual(f2['field_value_mode'], "Value_direct")
        self.assertEqual(f2['field_value_type'], "annal:Text")
        self.assertEqual(f2['field_placement'].field, "small-7 columns")
        self.assertEqual(f2['field_value'], "")
        self.assertEqual(f2['entity_type_id'], "")
        # Entities and bound fields
        entities = context_list_entities(r.context)
        self.assertEqual(len(entities), 6)
        entity_fields = ([{
            'entity_type_id': "_type",
            'annal:id': "testtype",
            'rdfs:label': "RecordType testcoll/testtype"
        }, {
            'entity_type_id': "_type",
            'annal:id': "testtype2",
            'rdfs:label': "RecordType testcoll/testtype2"
        }, {
            'entity_type_id': "testtype",
            'annal:id': "entity1",
            'rdfs:label': "Entity testcoll/testtype/entity1"
        }, {
            'entity_type_id': "testtype",
            'annal:id': "entity2",
            'rdfs:label': "Entity testcoll/testtype/entity2"
        }, {
            'entity_type_id': "testtype",
            'annal:id': "entity3",
            'rdfs:label': "Entity testcoll/testtype/entity3"
        }, {
            'entity_type_id': "testtype2",
            'annal:id': "entity4",
            'rdfs:label': "Entity testcoll/testtype2/entity4"
        }])
        field_keys = ('annal:id', 'entity_type_id', 'rdfs:label')
        for eid in range(6):
            item_fields = context_list_item_fields(r.context, entities[eid])
            for fid in range(3):
                item_field = item_fields[fid]
                head_field = head_fields[0]['row_field_descs'][fid]
                # log.info("Item field: %r"%(item_field,))
                # log.info("Head field: %r"%(head_field,))
                # Check that row field descriptions match corresponding heading feld descriptions
                for fkey in ('field_id', 'field_name', 'field_label',
                             'field_property_uri', 'field_render_type',
                             'field_placement', 'field_value_type'):
                    self.assertEqual(item_field[fkey], head_field[fkey])
                # Check row field values
                fkey = field_keys[fid]
                self.assertEqual(item_field['field_value'],
                                 entity_fields[eid][fkey])
                self.assertEqual(item_field['entity_type_id'],
                                 entity_fields[eid]['entity_type_id'])
        return
Exemplo n.º 12
0
 def test_get_fields_list_no_continuation(self):
     u = entitydata_list_type_url(
         "testcoll", layout.FIELD_TYPEID, list_id="Field_list", scope="all",
         query_params={"foo": "bar"}
         )
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     list_label = "Field definitions" 
     list_title = "Field definitions - Collection testcoll"
     self.assertContains(r, "<title>%s</title>"%list_title, html=True)
     self.assertContains(r, '<h2 class="page-heading">%s</h2>'%list_label, html=True)
     curi = continuation_params_url(u)
     field_params = (
         { 'base':           TestBasePath
         , 'cont':           uri_params({"continuation_url": curi})
         , 'tooltip1':       "" # 'title="%s"'%r.context['fields'][0]['field_help']
         , 'tooltip2':       "" # 'title="%s"'%r.context['fields'][1]['field_help']
         , 'tooltip3':       "" # 'title="%s"'%r.context['fields'][2]['field_help']
         , 'tooltip4':       "" # 'title="%s"'%r.context['fields'][3]['field_help']
         , 'field_typeid':   layout.FIELD_TYPEID
         })
     rowdata1 = """
         <div class="tbody row select-row">
           <div class="small-1 columns">
             <input type="checkbox" class="select-box right" name="entity_select"
                    value="%(field_typeid)s/Coll_comment" />
           </div>
           <div class="small-11 columns">
             <div class="view-listrow row">
               <div class="view-value small-4 medium-3 columns" %(tooltip1)s>
                 <a href="%(base)s/c/testcoll/d/%(field_typeid)s/Coll_comment/%(cont)s">Coll_comment</a>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip2)s>
                 <a href="%(base)s/c/testcoll/d/Enum_render_type/Markdown/%(cont)s">
                   Markdown rich text
                 </a>
               </div>
               <div class="view-value small-12 medium-3 columns show-for-medium-up" %(tooltip3)s>
                 <span>annal:Richtext</span>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip4)s>
                 <span>Collection metadata</span>
               </div>
             </div>
           </div>
         </div>
         """%field_params
     rowdata2 = """
         <div class="tbody row select-row">
           <div class="small-1 columns">
             <input type="checkbox" class="select-box right" name="entity_select"
                    value="%(field_typeid)s/Coll_parent" />
           </div>
           <div class="small-11 columns">
             <div class="view-listrow row">
               <div class="view-value small-4 medium-3 columns" %(tooltip1)s>
                 <a href="%(base)s/c/testcoll/d/%(field_typeid)s/Coll_parent/%(cont)s">Coll_parent</a>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip2)s>
                 <a href="%(base)s/c/testcoll/d/Enum_render_type/Enum_choice_opt/%(cont)s">Optional entity choice</a>
               </div>
               <div class="view-value small-12 medium-3 columns show-for-medium-up" %(tooltip3)s>
                 <span>annal:Slug</span>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip4)s>
                 <span>Parent</span>
               </div>
             </div>
           </div>
         </div>
         """%field_params
     rowdata3 = """
         <div class="tbody row select-row">
           <div class="small-1 columns">
             <input type="checkbox" class="select-box right" name="entity_select"
                    value="%(field_typeid)s/Coll_software_version" />
           </div>
           <div class="small-11 columns">
             <div class="view-listrow row">
               <div class="view-value small-4 medium-3 columns" %(tooltip1)s>
                 <a href="%(base)s/c/testcoll/d/%(field_typeid)s/Coll_software_version/%(cont)s">Coll_software_version</a>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip2)s>
                 <a href="%(base)s/c/testcoll/d/Enum_render_type/Showtext/%(cont)s">Display text</a>
               </div>
               <div class="view-value small-12 medium-3 columns show-for-medium-up" %(tooltip3)s>
                 <span>annal:Text</span>
               </div>
               <div class="view-value small-4 medium-3 columns" %(tooltip4)s>
                 <span>S/W version</span>
               </div>
             </div>
           </div>
         </div>
         """%field_params
     # log.info("*** r.content: "+r.content) #@@
     self.assertContains(r, rowdata1, html=True)
     self.assertContains(r, rowdata2, html=True)
     self.assertContains(r, rowdata3, html=True)
     # Test context
     self.assertEqual(r.context['coll_id'],          "testcoll")
     self.assertEqual(r.context['type_id'],          layout.FIELD_TYPEID)
     self.assertEqual(r.context['continuation_url'], "")
     list_choices = r.context['list_choices']
     self.assertEqual(set(list_choices.options),     set(self.list_ids))
     self.assertEqual(list_choices['field_value'],   "Field_list")
     # Fields
     head_fields = context_list_head_fields(r.context)
     self.assertEqual(len(head_fields), 1)       # One row of 4 cols..
     self.assertEqual(len(head_fields[0]['row_field_descs']), 4)
     return
Exemplo n.º 13
0
 def test_get_default_all_list(self):
     # List all entities in current collection
     u = entitydata_list_all_url("testcoll", list_id="Default_list_all") + "?continuation_url=/xyzzy/"
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     list_label = "List entities with type information" 
     list_title = "List entities with type information - Collection testcoll"
     self.assertContains(r, "<title>%s</title>"%list_title, html=True)
     self.assertContains(r, '<h2 class="page-heading">%s</h2>'%list_label, html=True)
     self.assertMatch(r.content, r'<input.type="hidden".name="continuation_url".+value="/xyzzy/"/>')
     # log.info(r.content) #@@
     cont = uri_params({"continuation_url": u})
     #@@ cont = ""
     tooltip1 = "" # 'title="%s"'%r.context['fields'][0]['field_help']
     tooltip2 = "" # 'title="%s"'%r.context['fields'][1]['field_help']
     tooltip3 = "" # 'title="%s"'%r.context['fields'][2]['field_help']
     rowdata = """
         <div class="tbody row select-row">
           <div class="small-1 columns">
             <input type="checkbox" class="select-box right" name="entity_select"
                    value="testtype/entity1" />
           </div>
           <div class="small-11 columns">
             <div class="row view-listrow">
               <div class="view-value small-3 columns" %(tooltip1)s>
                 <a href="%(base)s/c/testcoll/d/testtype/entity1/%(cont)s">entity1</a>
               </div>
               <div class="view-value small-2 columns" %(tooltip2)s>
                 <a href="/testsite/c/testcoll/d/_type/testtype/%(cont)s">RecordType testcoll/testtype</a>
               </div>
               <div class="view-value small-7 columns" %(tooltip3)s>
                 <span>Entity testcoll/testtype/entity1</span>
               </div>
             </div>
           </div>
         </div>
         """%(
             { 'base':     TestBasePath
             , 'cont':     cont
             , 'tooltip1': tooltip1
             , 'tooltip2': tooltip2
             , 'tooltip3': tooltip3
             }
         )
     # log.info(r.content)
     # log.info(r.context["fields"])
     # log.info(r.context["List_rows"])
     self.assertContains(r, rowdata, html=True)
     # Test context
     self.assertEqual(r.context['title'],            list_title)
     self.assertEqual(r.context['heading'],          list_label)
     self.assertEqual(r.context['coll_id'],          "testcoll")
     self.assertEqual(r.context['type_id'],          "Default_type")
     self.assertEqual(r.context['continuation_url'], "/xyzzy/")
     list_choices = r.context['list_choices']
     self.assertEqual(set(list_choices.options),     set(self.list_ids))
     self.assertEqual(list_choices['field_value'],   "Default_list_all")
     # Unbound field descriptions
     head_fields = context_list_head_fields(r.context)
     self.assertEqual(len(head_fields), 1)       # One row of 3 cols..
     self.assertEqual(len(head_fields[0]['row_field_descs']), 3)
     f0 = context_view_field(r.context, 0, 0)
     f1 = context_view_field(r.context, 0, 1)
     f2 = context_view_field(r.context, 0, 2)
     self.assertEqual(f0['field_id'], 'Entity_id')
     self.assertEqual(f1['field_id'], 'Entity_type')
     self.assertEqual(f2['field_id'], 'Entity_label')
     # Entities and bound fields
     # log.info(entities)  #@@
     entities = context_list_entities(r.context)
     self.assertEqual(len(entities), 6)
     entity_fields = (
         [ {'entity_type_id': "_type",     'annal:id': "testtype",  'rdfs:label': "RecordType testcoll/testtype"}
         , {'entity_type_id': "_type",     'annal:id': "testtype2", 'rdfs:label': "RecordType testcoll/testtype2"}
         , {'entity_type_id': "testtype",  'annal:id': "entity1",   'rdfs:label': "Entity testcoll/testtype/entity1"}
         , {'entity_type_id': "testtype",  'annal:id': "entity2",   'rdfs:label': "Entity testcoll/testtype/entity2"}
         , {'entity_type_id': "testtype",  'annal:id': "entity3",   'rdfs:label': "Entity testcoll/testtype/entity3"}
         , {'entity_type_id': "testtype2", 'annal:id': "entity4",   'rdfs:label': "Entity testcoll/testtype2/entity4"}
         ])
     field_keys = ('annal:id', 'entity_type_id', 'rdfs:label')
     for eid in range(6):
         item_fields = context_list_item_fields(r.context, entities[eid])
         for fid in range(3):
             item_field = item_fields[fid]
             head_field = head_fields[0]['row_field_descs'][fid]
             # Check that row field descriptions match corresponding heading feld descriptions
             for fkey in (
                     'field_id', 'field_name', 'field_label', 
                     'field_property_uri', 'field_render_type',
                     'field_placement', 'field_value_type'):
                 self.assertEqual(item_field[fkey], head_field[fkey])
             # Check row field values
             fkey = field_keys[fid]
             self.assertEqual(item_field['field_value'],    entity_fields[eid][fkey])
             self.assertEqual(item_field['entity_type_id'], entity_fields[eid]['entity_type_id'])
     return
Exemplo n.º 14
0
 def test_get_default_type_list(self):
     u = entitydata_list_type_url("testcoll",
                                  "testtype") + "?continuation_url=/xyzzy/"
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     # self.assertContains(r, site_title("<title>%s</title>"))
     self.assertContains(r, "<title>Collection testcoll</title>")
     self.assertContains(r, "<h3>List entities</h3>", html=True)
     cont = uri_params({"continuation_url": u})
     # log.info(r.content)
     rowdata = """
         <div class="trow row select-row">
           <div class="small-1 columns">
             <input type="checkbox" class="select-box right" name="entity_select"
                    value="testtype/entity1" />
           </div>
           <div class="small-11 columns">
             <div class="row">
                 <div class="small-3 columns"><a href="%(base)s/c/testcoll/d/testtype/entity1/%(cont)s">entity1</a></div>
                 <div class="small-9 columns">
                 Entity testcoll/testtype/entity1
                 </div>
             </div>
           </div>
         </div>
         """ % ({
         'base': TestBasePath,
         'cont': cont
     })
     self.assertContains(r, rowdata, html=True)
     # Test context
     # self.assertEqual(r.context['title'],            site_title())
     self.assertEqual(r.context['title'], "Collection testcoll")
     self.assertEqual(r.context['coll_id'], "testcoll")
     self.assertEqual(r.context['type_id'], "testtype")
     list_choices = r.context['list_choices']
     self.assertEqual(set(list_choices.options), set(self.initial_list_ids))
     self.assertEqual(list_choices['field_value'], "Default_list")
     self.assertEqual(r.context['continuation_url'], "/xyzzy/")
     # Fields
     self.assertEqual(len(r.context['fields']), 2)
     # 1st field
     self.assertEqual(r.context['fields'][0]['field_id'], 'Entity_id')
     self.assertEqual(r.context['fields'][0]['field_name'], 'entity_id')
     self.assertEqual(r.context['fields'][0]['field_label'], 'Id')
     self.assertEqual(r.context['fields'][0]['field_placeholder'],
                      "(entity id)")
     self.assertEqual(r.context['fields'][0]['field_property_uri'],
                      "annal:id")
     self.assertEqual(r.context['fields'][0]['field_render_type'],
                      "EntityId")
     self.assertEqual(r.context['fields'][0]['field_placement'].field,
                      "small-3 columns")
     self.assertEqual(r.context['fields'][0]['field_value_type'],
                      "annal:Slug")
     self.assertEqual(r.context['fields'][0]['field_value'], "")
     # 2nd field
     self.assertEqual(r.context['fields'][1]['field_id'], 'Entity_label')
     self.assertEqual(r.context['fields'][1]['field_name'], 'Entity_label')
     self.assertEqual(r.context['fields'][1]['field_label'], 'Label')
     self.assertEqual(r.context['fields'][1]['field_placeholder'],
                      "(label)")
     self.assertEqual(r.context['fields'][1]['field_property_uri'],
                      "rdfs:label")
     self.assertEqual(r.context['fields'][1]['field_render_type'], "Text")
     self.assertEqual(r.context['fields'][1]['field_placement'].field,
                      "small-9 columns")
     self.assertEqual(r.context['fields'][1]['field_value_type'],
                      "annal:Text")
     self.assertEqual(r.context['fields'][1]['field_value'], "")
     # Entities
     entities = context_list_entities(r.context)
     self.assertEqual(len(entities), 3)
     field_val = ("entity%d", "Entity testcoll/testtype/entity%d")
     for eid in range(3):
         for fid in range(2):
             item_field = context_list_item_fields(r.context,
                                                   entities[eid])[fid]
             head_field = context_list_head_fields(r.context)[fid]
             for fkey in ('field_id', 'field_name', 'field_label',
                          'field_property_uri', 'field_render_type',
                          'field_placement', 'field_value_type'):
                 self.assertEqual(item_field[fkey], head_field[fkey])
             self.assertEqual(item_field['field_value'],
                              field_val[fid] % (eid + 1))
     return
Exemplo n.º 15
0
 def test_get_default_type_list(self):
     u = entitydata_list_type_url("testcoll", "testtype") + "?continuation_url=/xyzzy/"
     r = self.client.get(u)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertContains(r, "<title>List entities - Collection testcoll</title>")
     self.assertContains(r, '<h2 class="page-heading">List entities</h2>', html=True)
     cont = uri_params({"continuation_url": u})
     # cont = ""
     # log.info(r.content)
     tooltip1 = ""
     tooltip2 = ""
     rowdata = """
         <div class="tbody row select-row">
           <div class="small-1 columns">
             <input type="checkbox" class="select-box right" name="entity_select"
                    value="testtype/entity1" />
           </div>
           <div class="small-11 columns">
             <div class="row view-listrow">
               <div class="view-value small-3 columns" %(tooltip1)s>
                 <a href="%(base)s/c/testcoll/d/testtype/entity1/%(cont)s">entity1</a>
               </div>
               <div class="view-value small-9 columns" %(tooltip2)s>
                 <span>Entity testcoll/testtype/entity1</span>
               </div>
             </div>
           </div>
         </div>
         """%(
             { 'base':     TestBasePath
             , 'cont':     cont
             , 'tooltip1': tooltip1
             , 'tooltip2': tooltip2
             }
         )
     self.assertContains(r, rowdata, html=True)
     # Test context
     # self.assertEqual(r.context['title'],            site_title())
     self.assertEqual(r.context['title'],            "List entities - Collection testcoll")
     self.assertEqual(r.context['coll_id'],          "testcoll")
     self.assertEqual(r.context['type_id'],          "testtype")
     list_choices = r.context['list_choices']
     self.assertEqual(set(list_choices.options),     set(self.list_ids))
     self.assertEqual(list_choices['field_value'],   "Default_list")
     self.assertEqual(r.context['continuation_url'], "/xyzzy/")
     # Fields
     head_fields = context_list_head_fields(r.context)
     self.assertEqual(len(head_fields), 1)       # One row of 2 cols..
     self.assertEqual(len(head_fields[0].description['row_field_descs']), 2)
     f0 = context_view_field(r.context, 0, 0)
     f1 = context_view_field(r.context, 0, 1)
     self.assertDictionaryMatch(f0, 
         get_bound_field("Entity_id", "", placement="small:0,3")
         )
     self.assertDictionaryMatch(f1, 
         get_bound_field("Entity_label", "", placement="small:3,9")
         )
     # Entities
     entities = context_list_entities(r.context)
     self.assertEqual(len(entities), 3)
     field_val = ("entity%d", "Entity testcoll/testtype/entity%d")
     for eid in range(3):
         item_fields = context_list_item_fields(r.context, entities[eid])
         for fid in range(2):
             item_field = item_fields[fid]
             head_field = head_fields[0].description['row_field_descs'][fid]
             for fkey in (
                     'field_id', 'field_name', 'field_label', 
                     'field_property_uri', 'field_render_type',
                     'field_placement', 'field_value_type'):
                 self.assertEqual(item_field.description[fkey], head_field[fkey])
             self.assertEqual(item_field['field_value'], field_val[fid]%(eid+1))
     return
 def test_get_default_type_list(self):
     u = entitydata_list_type_url("testcoll",
                                  "testtype") + "?continuation_url=/xyzzy/"
     r = self.client.get(u)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertContains(
         r, "<title>List entities - Collection testcoll</title>")
     self.assertContains(r,
                         '<h2 class="page-heading">List entities</h2>',
                         html=True)
     cont = uri_params({"continuation_url": u})
     # cont = ""
     # log.info(r.content)
     tooltip1 = ""
     tooltip2 = ""
     rowdata = """
         <div class="tbody row select-row">
           <div class="small-1 columns">
             <input type="checkbox" class="select-box right" name="entity_select"
                    value="testtype/entity1" />
           </div>
           <div class="small-11 columns">
             <div class="row view-listrow">
               <div class="view-value small-3 columns" %(tooltip1)s>
                 <a href="%(base)s/c/testcoll/d/testtype/entity1/%(cont)s">entity1</a>
               </div>
               <div class="view-value small-9 columns" %(tooltip2)s>
                 <span>Entity testcoll/testtype/entity1</span>
               </div>
             </div>
           </div>
         </div>
         """ % ({
         'base': TestBasePath,
         'cont': cont,
         'tooltip1': tooltip1,
         'tooltip2': tooltip2
     })
     self.assertContains(r, rowdata, html=True)
     # Test context
     # self.assertEqual(r.context['title'],            site_title())
     self.assertEqual(r.context['title'],
                      "List entities - Collection testcoll")
     self.assertEqual(r.context['coll_id'], "testcoll")
     self.assertEqual(r.context['type_id'], "testtype")
     list_choices = r.context['list_choices']
     self.assertEqual(set(list_choices.options), set(self.list_ids))
     self.assertEqual(list_choices['field_value'], "Default_list")
     self.assertEqual(r.context['continuation_url'], "/xyzzy/")
     # Fields
     head_fields = context_list_head_fields(r.context)
     self.assertEqual(len(head_fields), 1)  # One row of 2 cols..
     self.assertEqual(len(head_fields[0]['row_field_descs']), 2)
     f0 = context_view_field(r.context, 0, 0)
     f1 = context_view_field(r.context, 0, 1)
     # 1st field
     self.assertEqual(f0['field_id'], 'Entity_id')
     self.assertEqual(f0['field_name'], 'entity_id')
     self.assertEqual(f0['field_label'], 'Id')
     self.assertEqual(f0['field_placeholder'], "(entity id)")
     self.assertEqual(f0['field_property_uri'], "annal:id")
     self.assertEqual(f0['field_render_type'], "EntityId")
     self.assertEqual(f0['field_value_mode'], "Value_direct")
     self.assertEqual(f0['field_value_type'], "annal:Slug")
     self.assertEqual(f0['field_placement'].field, "small-3 columns")
     self.assertEqual(f0['field_value'], "")
     # 2nd field
     self.assertEqual(f1['field_id'], 'Entity_label')
     self.assertEqual(f1['field_name'], 'Entity_label')
     self.assertEqual(f1['field_label'], 'Label')
     self.assertEqual(f1['field_placeholder'], "(label)")
     self.assertEqual(f1['field_property_uri'], "rdfs:label")
     self.assertEqual(f1['field_render_type'], "Text")
     self.assertEqual(f1['field_value_mode'], "Value_direct")
     self.assertEqual(f1['field_value_type'], "annal:Text")
     self.assertEqual(f1['field_placement'].field, "small-9 columns")
     self.assertEqual(f1['field_value'], "")
     # Entities
     entities = context_list_entities(r.context)
     self.assertEqual(len(entities), 3)
     field_val = ("entity%d", "Entity testcoll/testtype/entity%d")
     for eid in range(3):
         item_fields = context_list_item_fields(r.context, entities[eid])
         for fid in range(2):
             item_field = item_fields[fid]
             head_field = head_fields[0]['row_field_descs'][fid]
             for fkey in ('field_id', 'field_name', 'field_label',
                          'field_property_uri', 'field_render_type',
                          'field_placement', 'field_value_type'):
                 self.assertEqual(item_field[fkey], head_field[fkey])
             self.assertEqual(item_field['field_value'],
                              field_val[fid] % (eid + 1))
     return
Exemplo n.º 17
0
 def get_continuation_param(self):
     """
     Return continuation URL specified for the current request, or None.
     """
     cont_here = self.view.continuation_here(self.request_dict, self.default_continue)
     return uri_params({"continuation_url": cont_here})