Exemplo n.º 1
0
    def get_select_action(self, path_info, params):
        """Generate a select action from a URL. Used unmodified by most
            subclasses. Handles attribute query by following the rules passed in
            the DS or in the request, bbox, maxfeatures, and startfeature by
            looking for the parameters in the params. """
        action = Action()
        action.method = "select"
        
        id = self.get_id_from_path_info(path_info)
        
        if id is not False:
            action.id = id
        
        else:
            import sys
            for ds in self.datasources:
                queryable = []
                #ds = self.service.datasources[self.datasource]
                if hasattr(ds, 'queryable'):
                    queryable = ds.queryable.split(",")
                elif params.has_key("queryable"):
                    queryable = params['queryable'].split(",")
                for key, value in params.items():
                    qtype = None
                    if "__" in key:
                        key, qtype = key.split("__")
                    if key == 'bbox':
                        action.bbox = map(float, value.split(","))
                    elif key == "maxfeatures":
                        action.maxfeatures = int(value)
                    elif key == "startfeature":
                        action.startfeature = int(value)
                    elif key == "request":
                        action.request = value
                    elif key == "version":
                        action.version = value
                    elif key == "filter":
                        action.wfsrequest = WFSRequest()
                        try:
                            action.wfsrequest.parse(value)
                        except Exception, E:
                            ''' '''

                    elif key in queryable or key.upper() in queryable and hasattr(self.service.datasources[ds], 'query_action_types'):
                        if qtype:
                            if qtype in self.service.datasources[ds].query_action_types:
                                action.attributes[key+'__'+qtype] = {'column': key, 'type': qtype, 'value':value}
                            else:
                                raise ApplicationException("%s, %s, %s\nYou can't use %s on this layer. Available query action types are: \n%s" % (self, self.query_action_types, qtype,
                                                                                                                                                   qtype, ",".join(self.service.datasources[ds].query_action_types) or "None"))
                        else:
                            action.attributes[key+'__eq'] = {'column': key, 'type': 'eq', 'value':value}