forked from Shopify/shopify_python_api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmixins.py
More file actions
34 lines (25 loc) · 1.08 KB
/
mixins.py
File metadata and controls
34 lines (25 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import shopify.resources
class Countable(object):
@classmethod
def count(cls, _options=None, **kwargs):
if _options is None:
_options = kwargs
return int(cls.get("count", **_options))
class Metafields(object):
def metafields(self, _options=None, **kwargs):
if _options is None:
_options = kwargs
return shopify.resources.Metafield.find(resource=self.__class__.plural, resource_id=self.id, **_options)
def metafields_count(self, _options=None, **kwargs):
if _options is None:
_options = kwargs
return int(self.get("metafields/count", **_options))
def add_metafield(self, metafield):
if self.is_new():
raise ValueError("You can only add metafields to a resource that has been saved")
metafield._prefix_options = {"resource": self.__class__.plural, "resource_id": self.id}
metafield.save()
return metafield
class Events(object):
def events(self):
return shopify.resources.Event.find(resource=self.__class__.plural, resource_id=self.id)