コード例 #1
0
ファイル: api.py プロジェクト: edelvalle/djspine
    def data(self):
        """Return the data passed in the request method data."""
        if self._data is None:
            data = self._real_data

            # Delete the page_param and manager_methods from the data
            data.pop(self.page_param_name, None)
            for manager_method_name in self.manager_methods:
                data.pop(manager_method_name, None)

            # Extract the pks of related fields
            local, single, multiple = self.get_serialize_fields()
            relational = list(chain(single, multiple))
            date_fields = {
                field.name
                for field in self.model._meta.fields
                if isinstance(field, (DateField, TimeField, DateTimeField))
            }

            for field_name, value in data.items():
                cuted_field = cut_suffix(field_name, '_id')
                if field_name.endswith('_id') and cuted_field in relational:
                    field_name = cuted_field
                field_base_name = field_name.split('__', 1)[0]
                if value is not None and field_base_name in date_fields:
                    value = parse_date(value)
                data[field_name] = value
            self._data = data
        return self._data
コード例 #2
0
def test_cutting_is_stable(s, p):
    from xoutil.string import cut_prefix, cut_suffix
    if not s.startswith(p):
        assert cut_prefix(s, p) == s == cut_prefix(cut_prefix(s, p), p)
    if not s.endswith(p):
        assert cut_suffix(s, p) == s == cut_suffix(cut_suffix(s, p), p)
コード例 #3
0
def test_cutting_is_inverse_to_adding(s, p):
    from xoutil.string import cut_prefix, cut_suffix
    assert cut_prefix(p + s, p) == s
    assert cut_suffix(s + p, p) == s
    assert cut_suffix(s, '') == s
    assert cut_prefix(s, '') == s
コード例 #4
0
ファイル: utils.py プロジェクト: merchise-autrement/xoeuf
        def _format_time(time):
            from xoutil.string import cut_suffix

            return cut_suffix(time.isoformat(), ":00")