Пример #1
0
Файл: db.py Проект: h1ds/h1ds
    def do_query_from_path_components(self, shot_str, attr_str, filter_str, as_dict=True):
        """Do SQL query from the URL API path components.

        Arguments:
            shot_str (str) - shot path component, e.g. "76523-76593"
            attr_str (str) - attribute path component, e.g.: "attr1+attr2"
            filter_str (str) - filter path component, e.g.: "attr1__lt__10"

        Keyword arguments:
            as_dict (bool, default=True) - if true then the responses will be returned as list of dicts: [{'attr':value, }, ]

        Returns:
            list of dicts (if as_dict is True)
            raw response from sqlite (if as_dict is False)

        """

        shot_where = get_where_from_shot_slug(self.device, shot_str)
        if shot_where is None:
            return []
        attr_list = parse_attr_str(self.device, attr_str)
        filter_where = parse_filter_str(filter_str)

        for special_attr in ['timestamp', 'shot']:
            if not special_attr in attr_list:
                attr_list.insert(0, special_attr)

        if filter_where is None:
            where = shot_where
        else:
            where = ' AND '.join([shot_where, filter_where])

        return self.do_query(select=attr_list, where=where, as_dict=as_dict)
Пример #2
0
Файл: forms.py Проект: h1ds/h1ds
 def get_cleaned_data_for_device(self, device):
     cleaned_data = self.clean()
     cleaned_data['shots'] = parse_shot_slug(device, cleaned_data['shots'])
     cleaned_data['attributes'] = parse_attr_str(device, cleaned_data['attributes'])
     return cleaned_data