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}
Exemplo n.º 2
0
 def handle_post(self, params, path_info, host, post_data, request_method, format_obj = None):
     """Read data from the request and turn it into an UPDATE/DELETE action."""
     
     if format_obj:
         actions = []
         
         id = self.get_id_from_path_info(path_info)
         if id is not False:
             action = Action()
             action.method = "update"
             action.id = id
             
             features = format_obj.decode(post_data)
             
             action.feature = features[0]
             actions.append(action)
         
         else:
             if hasattr(format_obj, 'decode'):
                 features = format_obj.decode(post_data)
                 
                 for feature in features:
                     action = Action()
                     action.method = "insert"
                     action.feature = feature
                     actions.append(action)
         
             elif hasattr(format_obj, 'parse'):
                 format_obj.parse(post_data)
                 
                 transactions = format_obj.getActions()
                 if transactions is not None:
                     for transaction in transactions:
                         action = Action()
                         action.method = transaction.__class__.__name__.lower()
                         action.wfsrequest = transaction
                         actions.append(action)
         
         return actions
     else:
         raise Exception("Service type does not support adding features.")