Пример #1
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
            })
Пример #2
0
def get_items_count(items):

    items = (item
             for item in items
             if item.approved and item.kit.approved and item.kit.collection)

    items_in_kits = collections.Counter(item.kit_id for item in items)

    kits_in_collections = [(kit.id, kit.collection_id)
                           for kit in kits_storage.all()
                           if kit.approved and kit.collection.approved]

    items_in_collections = {}

    for kit_id, collection_id in kits_in_collections:
        items_in_collections[collection_id] = items_in_collections.get(collection_id, 0) + items_in_kits[kit_id]

    return items_in_kits, items_in_collections
Пример #3
0
def get_items_count(items):

    items = (item for item in items
             if item.approved and item.kit.approved and item.kit.collection)

    items_in_kits = collections.Counter(item.kit_id for item in items)

    kits_in_collections = [(kit.id, kit.collection_id)
                           for kit in kits_storage.all()
                           if kit.approved and kit.collection.approved]

    items_in_collections = {}

    for kit_id, collection_id in kits_in_collections:
        items_in_collections[collection_id] = items_in_collections.get(
            collection_id, 0) + items_in_kits[kit_id]

    return items_in_kits, items_in_collections
Пример #4
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})