Example #1
0
    def __call__(self):
        """Request parameters are 'type' and 'coordinates'."""
        request = self.request
        response = request.response
        try:
            gtype = request.form.get('type')
            coords = request.form.get('coordinates')
            data = '{"type": "%s", "coordinates": %s}' % (gtype, coords)
            obj = geojson.loads(data, object_hook=geojson.GeoJSON.to_instance)
        except:
            raise
            response.setStatus(400)
            return "Input geometry is not acceptable"

        # Input is 900913, transform back to lon/lat
        result = self.transform(obj, inverse=True)
        g = IGeoreferenced(self.context)
        g.setGeoInterface(result.type, result.coordinates)
        notify(ObjectGeoreferencedEvent(g))

        if request.get('HTTP_REFERER'):
            response.redirect(
                request.get('HTTP_REFERER').split('?')[0] +
                '?portal_status_message=Changes%20saved.')
        else:
            response.setStatus(200)
            return "Geometry edited successfully"
Example #2
0
    def __call__(self):
        """Request parameters are 'type' and 'coordinates'."""
        request = self.request
        response = request.response
        try:
            gtype = request.form.get('type')
            coords = request.form.get('coordinates')
            data = '{"type": "%s", "coordinates": %s}' % (gtype, coords)
            obj = geojson.loads(data, object_hook=geojson.GeoJSON.to_instance)
        except:
            raise
            response.setStatus(400)
            return "Input geometry is not acceptable"

        # Input is 900913, transform back to lon/lat
        result = self.transform(obj, inverse=True)
        g = IGeoreferenced(self.context)
        g.setGeoInterface(result.type, result.coordinates)
        notify(ObjectGeoreferencedEvent(g))

        if request.get('HTTP_REFERER'):
            response.redirect(request.get('HTTP_REFERER').split('?')[0] + '?portal_status_message=Changes%20saved.')
        else:
            response.setStatus(200)
            return "Geometry edited successfully"
Example #3
0
    def test_override_geo_with_related_contact(self):
        add_behavior(
            'Event',
            'cpskin.agenda.behaviors.related_contacts.IRelatedContacts'
        )  # noqa
        add_behavior('Event', ICoordinates.__identifier__)
        event = api.content.create(container=self.portal,
                                   type='Event',
                                   id='myevent')

        # add some contacts
        applyProfile(self.portal, 'collective.contact.core:default')
        add_behavior('organization', ICoordinates.__identifier__)
        directory = api.content.create(container=self.portal,
                                       type='directory',
                                       id='directory')
        organization = api.content.create(container=directory,
                                          type='organization',
                                          id='organization')
        organization.title = u'IMIO'
        organization.street = u'Rue Léon Morel'
        organization.number = u'1'
        organization.zip_code = u'5032'
        organization.city = u'Isnes'

        # set related contact
        intids = getUtility(IIntIds)
        to_id = intids.getId(organization)
        rv = RelationValue(to_id)
        event.location = rv
        notify(ObjectModifiedEvent(event))

        # coord = ICoordinates(event)
        view = getMultiAdapter((event, event.REQUEST), name='geoview')
        coord = view.getCoordinates()
        self.assertEqual(coord, (None, None))
        coordinates = ICoordinates(event).coordinates

        self.assertEqual(coordinates, u'')

        # check if event georeferenced is correct
        orga_geo = IGeoreferenced(organization)
        orga_geo.setGeoInterface('Point', (4.711178, 50.504827))
        notify(ObjectModifiedEvent(event))
        view = getMultiAdapter((event, event.REQUEST), name='geoview')
        coord = view.getCoordinates()
        self.assertEqual(coord, ('Point', (4.711178, 50.504827)))
        coordinates = ICoordinates(event).coordinates
        self.assertEqual(coordinates, 'POINT (4.711178 50.504827)')
Example #4
0
    def test_override_geo_with_related_contact(self):
        add_behavior(
            'Event', 'cpskin.agenda.behaviors.related_contacts.IRelatedContacts')  # noqa
        add_behavior('Event', ICoordinates.__identifier__)
        event = api.content.create(
            container=self.portal,
            type='Event',
            id='myevent'
        )

        # add some contacts
        applyProfile(self.portal, 'collective.contact.core:default')
        add_behavior('organization', ICoordinates.__identifier__)
        directory = api.content.create(
            container=self.portal, type='directory', id='directory')
        organization = api.content.create(
            container=directory, type='organization', id='organization')
        organization.title = u'IMIO'
        organization.street = u'Rue Léon Morel'
        organization.number = u'1'
        organization.zip_code = u'5032'
        organization.city = u'Isnes'

        # set related contact
        intids = getUtility(IIntIds)
        to_id = intids.getId(organization)
        rv = RelationValue(to_id)
        event.location = rv
        notify(ObjectModifiedEvent(event))

        # coord = ICoordinates(event)
        view = getMultiAdapter((event, event.REQUEST), name='geoview')
        coord = view.getCoordinates()
        self.assertEqual(coord, (None, None))
        coordinates = ICoordinates(event).coordinates

        self.assertEqual(coordinates, u'')

        # check if event georeferenced is correct
        orga_geo = IGeoreferenced(organization)
        orga_geo.setGeoInterface('Point', (4.711178, 50.504827))
        notify(ObjectModifiedEvent(event))
        view = getMultiAdapter((event, event.REQUEST), name='geoview')
        coord = view.getCoordinates()
        self.assertEqual(coord, ('Point', (4.711178, 50.504827)))
        coordinates = ICoordinates(event).coordinates
        self.assertEqual(coordinates, 'POINT (4.711178 50.504827)')
    def test_show_map_if_address_is_given(self, browser):
        addressblock = create(
            Builder("address block")
            .within(self.contentpage)
            .having(address="Engehaldenstrasse 53", zip="3012", city="Bern")
        )

        geo = IGeoreferenced(addressblock)
        geo.setGeoInterface("Point", (-105.08, 40.59))

        transaction.commit()

        browser.login().visit(addressblock, view="block_view")
        self.assertEqual(1, len(browser.css(".addressMap")))

        browser.login().visit(addressblock, view="addressblock_detail_view")
        self.assertEqual(1, len(browser.css(".addressMap")))
Example #6
0
    def test_save_zgeo_catalog_from_contact(self):
        applyProfile(self.portal, 'collective.geo.leaflet:default')
        add_behavior('Event', IRelatedContacts.__identifier__)
        add_behavior('Event', ICoordinates.__identifier__)
        event = api.content.create(
            container=self.portal,
            type='Event',
            id='myevent'
        )

        # add some contacts
        applyProfile(self.portal, 'collective.contact.core:default')
        add_behavior('organization', ICoordinates.__identifier__)
        directory = api.content.create(
            container=self.portal, type='directory', id='directory')
        organization = api.content.create(
            container=directory, type='organization', id='organization')
        organization.title = u'IMIO'
        organization.street = u'Rue Léon Morel'
        organization.number = u'1'
        organization.zip_code = u'5032'
        organization.city = u'Isnes'

        # set related contact
        intids = getUtility(IIntIds)
        to_id = intids.getId(organization)
        rv = RelationValue(to_id)
        event.location = rv
        notify(ObjectModifiedEvent(event))
        event.reindexObject()
        # geo = IGeoreferenced(event)
        brain = api.content.find(UID=event.UID())[0]
        # brain.zgeo_geometry
        import Missing
        self.assertTrue(brain.zgeo_geometry == Missing.Value)
        orga_geo = IGeoreferenced(organization)
        orga_geo.setGeoInterface('Point', (4.711178, 50.504827))
        notify(ObjectModifiedEvent(event))
        brain = api.content.find(UID=event.UID())[0]
        self.assertEqual(brain.zgeo_geometry['type'], 'Point')
Example #7
0
    def test_save_zgeo_catalog_from_contact(self):
        applyProfile(self.portal, 'collective.geo.leaflet:default')
        add_behavior('Event', IRelatedContacts.__identifier__)
        add_behavior('Event', ICoordinates.__identifier__)
        event = api.content.create(container=self.portal,
                                   type='Event',
                                   id='myevent')

        # add some contacts
        applyProfile(self.portal, 'collective.contact.core:default')
        add_behavior('organization', ICoordinates.__identifier__)
        directory = api.content.create(container=self.portal,
                                       type='directory',
                                       id='directory')
        organization = api.content.create(container=directory,
                                          type='organization',
                                          id='organization')
        organization.title = u'IMIO'
        organization.street = u'Rue Léon Morel'
        organization.number = u'1'
        organization.zip_code = u'5032'
        organization.city = u'Isnes'

        # set related contact
        intids = getUtility(IIntIds)
        to_id = intids.getId(organization)
        rv = RelationValue(to_id)
        event.location = rv
        notify(ObjectModifiedEvent(event))
        event.reindexObject()
        # geo = IGeoreferenced(event)
        brain = api.content.find(UID=event.UID())[0]
        # brain.zgeo_geometry
        import Missing
        self.assertTrue(brain.zgeo_geometry == Missing.Value)
        orga_geo = IGeoreferenced(organization)
        orga_geo.setGeoInterface('Point', (4.711178, 50.504827))
        notify(ObjectModifiedEvent(event))
        brain = api.content.find(UID=event.UID())[0]
        self.assertEqual(brain.zgeo_geometry['type'], 'Point')