|
17 | 17 | NoPandasInstalledError, |
18 | 18 | ) |
19 | 19 |
|
20 | | -__all__ = ['AccountManager', 'Advertiser', 'BanReason', 'Bidder', 'Browser', 'CampaignDebugReason', |
| 20 | +__all__ = ['AccountManager', 'Advertiser', 'Bidder', 'Browser', 'CampaignDebugReason', |
21 | 21 | 'Campaign', 'Category', 'ConnectionType', 'ConversionPixel', 'Country', 'Creative', |
22 | 22 | 'Datacenter', 'DeviceType', 'Domain', 'Fallback', 'Isp', 'Languages', 'Network', |
23 | 23 | 'OperatingSystem', 'Placement', 'PlacementType', 'Profile', 'Publisher', 'Reason', |
@@ -81,9 +81,9 @@ def __setattr__(self, key, value): |
81 | 81 | def __delattr__(self, item): |
82 | 82 | if item in self._dirty: |
83 | 83 | self._dirty.remove(item) |
84 | | - else: |
85 | | - self._attributes[item] = None |
86 | | - self._dirty.add(item) |
| 84 | + |
| 85 | + self._attributes[item] = [] if isinstance(self._attributes[item], list) else None |
| 86 | + self._dirty.add(item) |
87 | 87 |
|
88 | 88 | def __dir__(self): |
89 | 89 | """Manually add dynamic attributes for autocomplete""" |
@@ -190,6 +190,27 @@ def reload(self, session=None): |
190 | 190 | self.__init__(session=session, **res.json) |
191 | 191 | return self |
192 | 192 |
|
| 193 | + def history(self, session=None, offset=0, limit=100, sort='date.asc'): |
| 194 | + """Show the changelog of the model. |
| 195 | +
|
| 196 | + :param session: The :class:`atomx.Atomx` session to use for the api call. |
| 197 | + (Optional if you specified a `session` at initialization) |
| 198 | + :param int offset: Skip first ``offset`` history entries. (default: 0) |
| 199 | + :param int limit: Only return ``limit`` history entries. (default: 100) |
| 200 | + :param str sort: Sort by `date.asc` or `date.desc`. (default: 'date.asc') |
| 201 | + :return: `list` of `dict`s with `date`, `user` and the attributes that changed (`history`). |
| 202 | + :rtype: list |
| 203 | + """ |
| 204 | + session = session or self.session |
| 205 | + if not session: |
| 206 | + raise NoSessionError |
| 207 | + if not hasattr(self, 'id'): |
| 208 | + raise ModelNotFoundError("Can't reload without 'id' parameter. " |
| 209 | + "Forgot to save() first?") |
| 210 | + res = session.get('history', self._resource_name, self.id, |
| 211 | + offset=offset, limit=limit, sort=sort) |
| 212 | + return res |
| 213 | + |
193 | 214 |
|
194 | 215 | for m in __all__: |
195 | 216 | locals()[m] = type(m, (AtomxModel,), |
|
0 commit comments