1 from samplebc.samples.models import Container, Sample
4 def __get_container(string_or_container):
6 returns a container object given container object or
9 if isinstance(string_or_container, Container):
10 return string_or_container
11 elif isinstance(string_or_container, types.StringType):
12 return Container.objects.get(name=string_or_container
14 raise ValueError, 'Invalid type: %s' % (string_or_container)
17 def item_count(string_or_container):
19 Returns the number of items in a container given container
22 container_obj = __get_container(string_or_container)
23 return len(Sample.objects.filter(container__name=container_obj.name))
26 def available_space(string_or_container):
28 Returns the available space in a container by passing in either
29 the container object or the name of the container.
31 count = item_count(string_or_container)
32 container_obj = __get_container(string_or_container)
34 return (container_obj.max_items - count)