Exemplo n.º 1
0
    def test_get_collections_statistics__with_account(self):

        self.account_1_items.add_item(self.item_3_1)
        self.account_1_items.save()

        self.assertEqual(
            get_collections_statistics(self.account_1_items), {
                'total_items_in_collections': {
                    self.collection_2.id: 2
                },
                'total_items_in_kits':
                collections.Counter({
                    self.kit_2.id: 1,
                    self.kit_3.id: 1
                }),
                'account_items_in_collections': {
                    self.collection_2.id: 1
                },
                'account_items_in_kits':
                collections.Counter({self.kit_3.id: 1}),
                'total_items':
                2,
                'account_items':
                1
            })
Exemplo n.º 2
0
    def index(self, account=None):

        if account is None and self.account.is_authenticated:
            return self.redirect(
                url('collections:collections:', account=self.account.id))

        self.master_account = account

        master_account_items = None
        last_items = []
        if self.master_account:
            master_account_items = AccountItemsPrototype.get_by_account_id(
                self.master_account.id)
            last_items = master_account_items.last_items(
                number=collections_settings.LAST_ITEMS_NUMBER)

        account_items = None
        if self.account.is_authenticated:
            account_items = AccountItemsPrototype.get_by_account_id(
                self.account.id)

        collections_statistics = get_collections_statistics(
            account_items=master_account_items)

        collections_table = split_into_table(self.collections, 3)

        return self.template(
            'collections/collections/index.html', {
                'collections_statistics': collections_statistics,
                'collections_table': collections_table,
                'account_items': account_items,
                'master_account_items': master_account_items,
                'last_items': last_items
            })
Exemplo n.º 3
0
    def index(self, account=None):

        if account is None and self.account.is_authenticated:
            return self.redirect(url('collections:collections:', account=self.account.id))

        self.master_account = account

        master_account_items = None
        last_items = []
        if self.master_account:
            master_account_items = AccountItemsPrototype.get_by_account_id(self.master_account.id)
            last_items = master_account_items.last_items(number=collections_settings.LAST_ITEMS_NUMBER)

        account_items = None
        if self.account.is_authenticated:
            account_items = AccountItemsPrototype.get_by_account_id(self.account.id)

        collections_statistics = get_collections_statistics(account_items=master_account_items)

        collections_table = split_into_table(self.collections, 3)


        return self.template('collections/collections/index.html',
                             {'collections_statistics': collections_statistics,
                              'collections_table': collections_table,
                              'account_items': account_items,
                              'master_account_items': master_account_items,
                              'last_items': last_items})
Exemplo n.º 4
0
 def test_get_collections_statistics__no_account(self):
     self.assertEqual(get_collections_statistics(None),
                      {'total_items_in_collections': {self.collection_2.id: 2},
                       'total_items_in_kits': collections.Counter({self.kit_2.id: 1, self.kit_3.id: 1}),
                       'account_items_in_collections': {},
                       'account_items_in_kits': {},
                       'total_items': 2,
                       'account_items': 0})
Exemplo n.º 5
0
    def show(self, account=None):

        if account is None and self.account.is_authenticated:
            return self.redirect(
                url('collections:collections:show',
                    self.collection.id,
                    account=self.account.id))

        self.master_account = account

        master_account_items = None
        if self.master_account:
            master_account_items = AccountItemsPrototype.get_by_account_id(
                self.master_account.id)

        account_items = None
        if self.account.is_authenticated:
            account_items = AccountItemsPrototype.get_by_account_id(
                self.account.id)

        collections_statistics = get_collections_statistics(
            account_items=master_account_items)

        kits = sorted([
            kit for kit in kits_storage.all()
            if kit.collection_id == self.collection.id
        ],
                      key=lambda k: k.caption)

        if not (self.can_edit_kit or self.can_moderate_kit):
            kits = [kit for kit in kits if kit.approved]

        items = {kit.id: [] for kit in kits}

        items_query = items_storage.all()

        if not self.edit_item_permission and not self.moderate_item_permission:
            items_query = (item for item in items_query if item.approved)

        items_query = sorted(
            [item for item in items_query if item.kit_id in items],
            key=lambda i: i.caption)

        for item in items_query:
            items[item.kit_id].append(item)

        return self.template(
            'collections/collections/show.html', {
                'kits': kits,
                'items': items,
                'account_items': account_items,
                'master_account_items': master_account_items,
                'collections_statistics': collections_statistics
            })
Exemplo n.º 6
0
    def test_get_collections_statistics__with_account(self):

        self.account_1_items.add_item(self.item_3_1)
        self.account_1_items.save()

        self.assertEqual(get_collections_statistics(self.account_1_items),
                         {'total_items_in_collections': {self.collection_2.id: 2},
                          'total_items_in_kits': collections.Counter({self.kit_2.id: 1, self.kit_3.id: 1}),
                          'account_items_in_collections': {self.collection_2.id: 1},
                          'account_items_in_kits': collections.Counter({self.kit_3.id: 1}),
                          'total_items': 2,
                          'account_items': 1})
Exemplo n.º 7
0
 def test_get_collections_statistics__no_account(self):
     self.assertEqual(
         get_collections_statistics(None), {
             'total_items_in_collections': {
                 self.collection_2.id: 2
             },
             'total_items_in_kits':
             collections.Counter({
                 self.kit_2.id: 1,
                 self.kit_3.id: 1
             }),
             'account_items_in_collections': {},
             'account_items_in_kits': {},
             'total_items':
             2,
             'account_items':
             0
         })
Exemplo n.º 8
0
    def show(self, account=None):

        if account is None and self.account.is_authenticated:
            return self.redirect(url('collections:collections:show', self.collection.id, account=self.account.id))

        self.master_account = account

        master_account_items = None
        if self.master_account:
            master_account_items = AccountItemsPrototype.get_by_account_id(self.master_account.id)

        account_items = None
        if self.account.is_authenticated:
            account_items = AccountItemsPrototype.get_by_account_id(self.account.id)

        collections_statistics = get_collections_statistics(account_items=master_account_items)


        kits = sorted([kit for kit in kits_storage.all() if kit.collection_id == self.collection.id], key=lambda k: k.caption)

        if not (self.can_edit_kit or self.can_moderate_kit):
            kits = [kit for kit in kits if kit.approved]

        items = {kit.id: [] for kit in kits}

        items_query = items_storage.all()

        if not self.edit_item_permission and not self.moderate_item_permission:
            items_query = (item for item in items_query if item.approved)

        items_query = sorted([item for item in items_query if item.kit_id in items], key=lambda i: i.caption)

        for item in items_query:
            items[item.kit_id].append(item)

        return self.template('collections/collections/show.html',
                             {'kits': kits,
                              'items': items,
                              'account_items': account_items,
                              'master_account_items': master_account_items,
                              'collections_statistics': collections_statistics})