1 | ## $Id: container.py 12684 2015-03-07 08:15:26Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """ |
---|
19 | Containers which contain product objects. |
---|
20 | """ |
---|
21 | import grok |
---|
22 | from grok import index |
---|
23 | from waeup.ikoba.interfaces import IIkobaPluggable |
---|
24 | from waeup.ikoba.products.interfaces import IProductsContainer, IProduct |
---|
25 | from waeup.ikoba.utils.helpers import attrs_to_fields |
---|
26 | from waeup.ikoba.utils.logger import Logger |
---|
27 | |
---|
28 | class ProductsContainer(grok.Container, Logger): |
---|
29 | """This is a container for all kind of products. |
---|
30 | """ |
---|
31 | grok.implements(IProductsContainer) |
---|
32 | grok.provides(IProductsContainer) |
---|
33 | |
---|
34 | def __init__(self, *args, **kw): |
---|
35 | super(ProductsContainer, self).__init__(*args, **kw) |
---|
36 | self.description_dict = {} |
---|
37 | |
---|
38 | def addProduct(self, product): |
---|
39 | if not IProduct.providedBy(product): |
---|
40 | raise TypeError( |
---|
41 | 'ProductsContainers contain only IProduct instances') |
---|
42 | self[product.product_id] = product |
---|
43 | return |
---|
44 | |
---|
45 | ProductsContainer = attrs_to_fields(ProductsContainer) |
---|
46 | |
---|
47 | |
---|
48 | class ContainerPlugin(grok.GlobalUtility): |
---|
49 | """A plugin that creates container for Container inside a company. |
---|
50 | """ |
---|
51 | grok.implements(IIkobaPluggable) |
---|
52 | grok.name('productscontainer') |
---|
53 | |
---|
54 | def setup(self, site, name, logger): |
---|
55 | return |
---|
56 | |
---|
57 | def update(self, site, name, logger): |
---|
58 | container = site['products'] |
---|
59 | if not getattr(container, 'description_dict', None): |
---|
60 | container.description_dict = {} |
---|
61 | for value in container.values(): |
---|
62 | if not getattr(value, 'description_dict', None): |
---|
63 | value.description_dict = {} |
---|
64 | return |
---|