Exemplo n.º 1
0
    def _handle_parameters(self):

        response = self.request.response

        # Make sure the _LOCATION_ cookie is correctly set: The old version GUI
        # version used to store the map center and the zoom level which is not
        # understood by new GUI (which stores the map extent as 4 coordinates)
        if '_LOCATION_' in self.request.cookies:
            c = urllib.unquote(self.request.cookies['_LOCATION_'])
            if len(c.split('|')) == 3:
                response.delete_cookie('_LOCATION_')

        # Check if language (_LOCALE_) is set
        if self.request is not None:
            if '_LOCALE_' in self.request.params:
                response.set_cookie('_LOCALE_', self.request.params.get(
                    '_LOCALE_'), timedelta(days=90))
            elif '_LOCALE_' in self.request.cookies:
                pass

        # Check if profile (_PROFILE_) is set
        if self.request is not None:
            if '_PROFILE_' in self.request.params:
                # Set the profile cookie
                profile_code = self.request.params.get('_PROFILE_')
                response.set_cookie(
                    '_PROFILE_', profile_code, timedelta(days=90))

                # Update _LOCATION_ from cookies to profile geometry bbox
                # retrieved from database
                profile_db = DBSession.query(Profile).\
                    filter(Profile.code == profile_code).\
                    first()

                if profile_db is not None:
                    # Calculate and transform bounding box
                    bbox = DBSession.scalar(geofunctions.envelope(
                        geofunctions.transform(
                            profile_db.geometry, '900913')).wkt)

                    geojson = utils.from_wkt(bbox)

                    coords = geojson['coordinates'][0]
                    p1 = coords[0]
                    p2 = coords[2]

                    l = '%s,%s' % (','.join([str(x) for x in p1]),
                        ','.join([str(x) for x in p2]))

                    response.set_cookie(
                        '_LOCATION_', urllib.quote(l), timedelta(days=90))

            elif '_PROFILE_' in self.request.cookies:
                # Profile already set, leave it
                pass
            else:
                # If no profile is set, set the default profile
                response.set_cookie('_PROFILE_', get_default_profile(
                    self.request), timedelta(days=90))
Exemplo n.º 2
0
 def to_json(self):
     # The geometry as Shapely object
     geometry = None
     if self.point is not None:
         shape = wkb.loads(str(self.point.geom_wkb))
         geometry = from_wkt(shape.wkt)
     return {
         'id': str(self.activity_identifier),
         'version': self.version,
         'geometry': geometry,
         'taggroups': [t.to_json() for t in self.tag_groups]
     }
Exemplo n.º 3
0
 def to_json(self):
     geometry = None
     if self.geometry is not None:
         shape = wkb.loads(str(self.geometry.geom_wkb))
         geometry = from_wkt(shape.wkt)
     return {'id': self.id, 'code': self.code, 'geometry': geometry}
Exemplo n.º 4
0
 def coords(self, session):
     wkt = session.scalar(self.wkt)
     return from_wkt(wkt)["coordinates"]
Exemplo n.º 5
0
 def geom_type(self, session):
     wkt = session.scalar(self.wkt)
     return from_wkt(wkt)["type"]