Exemple #1
0
 def get_categories(cls, page=1):
     """Return list of categories
     """
     return Pagination(cls, [
         ('displayed_on_eshop', '=', True),
         ('sites', '=', request.nereid_website.id)
     ], page, cls.per_page)
Exemple #2
0
    def render(cls, uri, page=1):
        """
        Renders the category
        """
        Article = Pool().get('nereid.cms.article')

        # Find in cache or load from DB
        try:
            category, = cls.search([('unique_name', '=', uri)])
        except ValueError:
            abort(404)

        order = []
        if category.sort_order == 'recent_first':
            order.append(('write_date', 'DESC'))
        elif category.sort_order == 'older_first':
            order.append(('write_date', 'ASC'))
        elif category.sort_order == 'sequence':
            order.append(('sequence', 'ASC'))

        articles = Pagination(
            Article, [
                ('categories', '=', category.id),
                ('state', '=', 'published')
            ], page, category.articles_per_page, order=order
        )
        return render_template(
            category.template, category=category, articles=articles)
Exemple #3
0
    def render(cls, uri, page=1):
        """
        Renders the template 'category.jinja' with the category and the
        products of the category paginated in the context

        :param uri: URI of the product category
        :param page: Integer value of the page
        """
        ProductTemplate = Pool().get('product.template')

        categories = cls.search([
            ('displayed_on_eshop', '=', True),
            ('uri', '=', uri),
            ('sites', '=', request.nereid_website.id)
        ])
        if not categories:
            return NotFound('Product Category Not Found')

        # if only one category is found then it is rendered and
        # if more than one are found then the first one is rendered
        category = categories[0]
        products = Pagination(ProductTemplate, [
            ('products.displayed_on_eshop', '=', True),
            ('category', '=', category.id),
        ], page=page, per_page=cls.per_page)
        return render_template(
            'category.jinja', category=category, products=products
        )
 def sales(cls, page=1):
     'All sales'
     Sale = Pool().get('sale.sale')
     sales = Pagination(Sale, [('party', '=', current_user.party.id),
                               ('state', '!=', 'draft')], page,
                        cls.per_page)
     return render_template('sales.jinja', sales=sales)
Exemple #5
0
    def all_leads(cls, page=1):
        """
        All leads captured
        """
        Country = Pool().get('country.country')

        countries = Country.search([])
        filter_domain = []

        company = request.args.get('company', None)
        if company:
            filter_domain.append(('party.name', 'ilike', '%%%s%%' % company))

        name = request.args.get('name', None)
        if name:
            filter_domain.append(('address.name', 'ilike', '%%%s%%' % name))

        email = request.args.get('email', None)
        if email:
            filter_domain.append(('address.email', 'ilike', '%%%s%%' % email))

        state = request.args.get('state', None)
        if state:
            filter_domain.append(('state', '=', '%s' % state))

        leads = Pagination(cls, filter_domain, page, 10)
        return render_template('crm/leads.jinja',
                               leads=leads,
                               countries=countries)
Exemple #6
0
    def render(self, uri, page=1):
        """
        Renders the template
        """
        product_obj = Pool().get('product.product')
        category_ids = self.search([('displayed_on_eshop', '=', True),
                                    ('uri', '=', uri),
                                    ('sites', '=', request.nereid_website.id)])
        if not category_ids:
            return NotFound('Product Category Not Found')

        # if only one product is found then it is rendered and
        # if more than one are found then the first one is rendered
        category = self.browse(category_ids[0])
        child_categories = self.search([('childs', 'child_of', [category.id])])
        print child_categories
        products = Pagination(product_obj, [
            ('displayed_on_eshop', '=', True),
            ('category', 'in', child_categories + [category.id]),
        ],
                              page=page,
                              per_page=self.per_page)
        return render_template(
            'category.jinja',
            category=category,
            products=products,
        )
Exemple #7
0
    def test_0030_model_pagination_serialization(self):
        """
        Test serialization of pagination for models
        """
        self.setup_defaults()

        # Create a 100 nereid users
        for id in xrange(0, 100):
            self.nereid_user_obj.create([{
                'party': self.guest_party,
                'display_name': 'User %s' % id,
                'email': '*****@*****.**' % id,
                'password': '******',
                'company': self.company.id,
            }])

        pagination = Pagination(self.nereid_user_obj, [], 1, 10)
        serialized = pagination.serialize()

        self.assertEqual(serialized['count'], 100)
        self.assertEqual(serialized['pages'], 10)
        self.assertEqual(serialized['page'], 1)
        self.assertEqual(len(serialized['items']), 10)

        self.assert_('display_name' in serialized['items'][0])
Exemple #8
0
    def render_list(cls, page=1):
        """Render all orders
        """
        filter_by = request.args.get('filter_by', None)

        domain = [
            ('party', '=', current_user.party.id),
        ]
        req_date = (date.today() + relativedelta(months=-3))

        if filter_by == 'done':
            domain.append(('state', '=', 'done'))

        elif filter_by == 'canceled':
            domain.append(('state', '=', 'cancel'))

        elif filter_by == 'archived':
            domain.append(('state', 'not in', ('draft', 'quotation')))

            # Add a sale_date domain for recent orders.
            domain.append(('sale_date', '<', req_date))

        else:
            domain.append(
                ('state', 'not in', ('draft', 'quotation', 'cancel')))

            # Add a sale_date domain for recent orders.
            domain.append(('sale_date', '>=', req_date))

        # Handle order duration
        sales = Pagination(cls, domain, page, cls.per_page)

        return render_template('sales.jinja', sales=sales)
 def invoices(cls, page=1):
     'List of Invoices'
     Invoice = Pool().get('account.invoice')
     invoices = Pagination(Invoice, [('party', '=', current_user.party.id),
                                     ('state', '!=', 'draft')], page,
                           cls.per_page)
     return render_template('invoices.jinja', invoices=invoices)
Exemple #10
0
    def test_0020_model_pagination(self):
        """
        Test pagination for models
        """
        with Transaction().start(DB_NAME, USER, CONTEXT):
            self.setup_defaults()

            # Create a 100 nereid users
            for id in xrange(0, 100):
                self.nereid_user_obj.create([{
                    'party':
                    self.guest_party,
                    'display_name':
                    'User %s' % id,
                    'email':
                    '*****@*****.**' % id,
                    'password':
                    '******',
                    'company':
                    self.company.id,
                }])

            pagination = Pagination(self.nereid_user_obj, [], 1, 10)
            self.assertEqual(pagination.count, 100)
            self.assertEqual(pagination.pages, 10)
            self.assertEqual(pagination.begin_count, 1)
            self.assertEqual(pagination.end_count, 10)
Exemple #11
0
 def get_root_categories(cls, page=1):
     """Return list of Root Categories."""
     return Pagination(cls, [
         ('displayed_on_eshop', '=', True),
         ('sites', '=', request.nereid_website.id),
         ('parent', '=', None),
     ], page, cls.per_page)
Exemple #12
0
 def shipments(cls, page=1):
     'List of Shipments'
     Shipment = Pool().get('stock.shipment.out')
     shipments = Pagination(Shipment, [
         ('customer', '=', current_user.party.id),
         ('state', '!=', 'draft'),
     ], page, cls.per_page)
     return render_template('shipments.jinja', shipments=shipments)
Exemple #13
0
    def cms_static_list(cls, page=1):
        """
            Return JSON with list of all files inside cms static folder
        """
        StaticFile = Pool().get("nereid.static.file")

        files = Pagination(
            StaticFile,
            [('folder', '=', current_website.cms_static_folder.id)], page, 10)
        return jsonify(items=[item.serialize() for item in files])
Exemple #14
0
    def account_context(cls):
        """
        When the account page is displayed it may be required to display a
        lot of information, and this depends from site to site. So rather than
        rewriting the render page everytime it is optimal to have a context
        being rebuilt by subclassing.

        This basic context builder builds sales, invoices and shipments,
        (only last 5) of the customer.

        To add more items to the context, subclass the method and call super
        to get the result of this method and then add your content to it.

        :return: A dictionary of items to render a context
        """
        Sale = Pool().get('sale.sale')
        Invoice = Pool().get('account.invoice')
        Shipment = Pool().get('stock.shipment.out')

        sales = Pagination(Sale, [
            ('party', '=', current_user.party.id),
            ('state', '!=', 'draft')
        ], 1, 5)

        invoices = Pagination(Invoice, [
            ('party', '=', current_user.party.id),
            ('state', '!=', 'draft'),
        ], 1, 5)

        shipments = Pagination(Shipment, [
            ('customer', '=', current_user.party.id),
            ('state', '!=', 'draft'),
        ], 1, 5)

        context = super(Website, cls).account_context()
        context.update({
            'sales': sales,
            'invoices': invoices,
            'shipments': shipments,
        })
        return context
Exemple #15
0
    def render_list(cls, page=1):
        """
        Renders the list of all categories which are displayed_on_shop=True
        paginated.

        :param page: Integer ID of the page
        """
        categories = Pagination(cls, [
            ('displayed_on_eshop', '=', True),
            ('sites', '=', request.nereid_website.id),
        ], page, cls.per_page)
        return render_template('category-list.jinja', categories=categories)
Exemple #16
0
 def quick_search(cls):
     """A quick and dirty search which searches through the product.product
     for an insensitive like and returns a pagination object the same.
     """
     page = request.args.get('page', 1, type=int)
     query = request.args.get('q', '')
     categories = request.nereid_website.get_categories() + [None]
     products = Pagination(cls, [
         ('displayed_on_eshop', '=', True),
         ('category', 'in', categories),
         ('template.active', '=', True),
         ('name', 'ilike', '%' + query + '%'),
     ], page, cls.per_page)
     return render_template('search-results.jinja', products=products)
Exemple #17
0
    def my_posts(self, page=1):
        """Render all the posts of the logged in user
        """
        posts = Pagination(self, [
            ('nereid_user', '=', request.nereid_user.id),
        ], page, self.per_page)
        if request.is_xhr:
            return jsonify({
                'has_next': posts.has_next,
                'has_prev': posts.has_prev,
                'items': [post.serialize() for post in posts],
            })

        return render_template('my_blog_posts.jinja', posts=posts)
Exemple #18
0
    def quick_search(cls):
        """A quick and dirty search which searches through the product.product
        for an insensitive like and returns a pagination object the same.
        """
        Product = Pool().get('product.product')

        page = request.args.get('page', 1, type=int)
        query = request.args.get('q', '')
        products = Pagination(Product, [
            ('displayed_on_eshop', '=', True),
            ('template.active', '=', True),
            ('name', 'ilike', '%' + query + '%'),
        ], page, Product.per_page)
        return render_template('search-results.jinja', products=products)
Exemple #19
0
    def render(cls, uri, page=1):
        """
        Renders the category
        """
        Article = Pool().get('nereid.cms.article')

        # Find in cache or load from DB
        try:
            category, = cls.search([('unique_name', '=', uri)])
        except ValueError:
            return NotFound()

        articles = Pagination(Article, [('category', '=', category.id)], page,
                              cls.per_page)
        return render_template(category.template,
                               category=category,
                               articles=articles)
Exemple #20
0
    def render_list(cls, page=1):
        """Render all orders
        """
        filter_by = request.args.get('filter_by', None)

        domain = [
            ('party', '=', current_user.party.id),
        ]
        req_date = (
            date.today() + relativedelta(months=-3)
        )

        if filter_by == 'done':
            domain.append(('state', '=', 'done'))

        elif filter_by == 'canceled':
            domain.append(('state', '=', 'cancel'))

        elif filter_by == 'archived':
            # only done and cancelled orders should be in archive
            # irrespective of the date. Pre orders for example
            # could be over 3 months old and still be in the
            # processing state
            domain.append(
                ('state', 'in', ('done', 'cancel'))
            )

            # Add a sale_date domain for recent orders.
            domain.append((
                'sale_date', '<', req_date
            ))

        else:
            domain.append([
                'OR',
                ('state', 'in', ('confirmed', 'processing')),
                [
                    ('state', 'in', ('done', 'cancel')),
                    ('sale_date', '>=', req_date),
                ]
            ])

        # Handle order duration
        sales = Pagination(cls, domain, page, cls.per_page)

        return render_template('sales.jinja', sales=sales)
Exemple #21
0
    def test_0040_model_pagination_serialization(self):
        """
        Test serialization of pagination for model which does not have
        serialize method
        """
        self.setup_defaults()

        # Create a 100 addresses
        for id in xrange(0, 100):
            self.address_obj.create([{
                'party': self.guest_party,
                'name': 'User %s' % id,
            }])

        pagination = Pagination(self.address_obj, [], 1, 10)
        serialized = pagination.serialize()

        self.assert_('id' in serialized['items'][0])
        self.assert_('rec_name' in serialized['items'][0])
Exemple #22
0
    def render_list(cls, user_id, page=1):
        """Render the blog posts for a user
        This should render the list of only published posts of the user
        """
        NereidUser = Pool().get('nereid.user')

        user = NereidUser(user_id)

        posts = Pagination(cls, [
            ('nereid_user', '=', user.id),
            ('state', '=', 'Published'),
        ], page, cls.per_page)
        if request.is_xhr:
            return jsonify({
                'has_next': posts.has_next,
                'has_prev': posts.has_prev,
                'items': [post.serialize() for post in posts],
            })

        return render_template('blog_posts.jinja', posts=posts, poster=user)
Exemple #23
0
    def render_list(cls, page=1):
        """
        Renders the list of all products which are displayed_on_shop=True

        .. tip::

            The implementation uses offset for pagination and could be
            extremely resource intensive on databases. Hence you might want to
            either have an alternate cache/search server based pagination or
            limit the pagination to a maximum page number.

            The base implementation does NOT limit this and could hence result
            in poor performance

        :param page: The page in pagination to be displayed
        """

        products = Pagination(cls, [
            ('displayed_on_eshop', '=', True),
            ('template.active', '=', True),
        ], page, cls.per_page)
        return render_template('product-list.jinja', products=products)
Exemple #24
0
    def render_task_list(cls, project_id):
        """
        Renders a project's task list page
        """
        project = cls.get_project(project_id)
        state = request.args.get('state', None)
        page = request.args.get('page', 1, int)

        filter_domain = [
            ('type', '=', 'task'),
            ('parent', '=', project.id),
        ]

        query = request.args.get('q', None)
        if query:
            # This search is probably the suckiest search in the
            # history of mankind in terms of scalability and utility
            # TODO: Figure out something better
            filter_domain.append(('work.name', 'ilike', '%%%s%%' % query))

        tag = request.args.get('tag', None, int)
        if tag:
            filter_domain.append(('tags', '=', tag))

        if request.args.get('user') == 'no one':
            filter_domain.append(('assigned_to', '=', None))
        elif request.args.get('user', None, int):
            filter_domain.append(
                ('assigned_to', '=', request.args.get('user', None, int)))

        counts = {}
        counts['opened_tasks_count'] = cls.search(filter_domain +
                                                  [('state', '=', 'opened')],
                                                  count=True)
        counts['done_tasks_count'] = cls.search(filter_domain +
                                                [('state', '=', 'done')],
                                                count=True)
        counts['all_tasks_count'] = cls.search(filter_domain, count=True)

        if state and state in ('opened', 'done'):
            filter_domain.append(('state', '=', state))

        counts['backlog'] = cls.search(filter_domain +
                                       [('progress_state', '=', 'Backlog')],
                                       count=True)
        counts['planning'] = cls.search(filter_domain +
                                        [('progress_state', '=', 'Planning')],
                                        count=True)
        counts['in_progress'] = cls.search(
            filter_domain + [('progress_state', '=', 'In Progress')],
            count=True)
        counts['review'] = cls.search(filter_domain +
                                      [('progress_state', '=', 'Review')],
                                      count=True)

        if request.is_xhr:
            tasks = cls.search(filter_domain)
            return jsonify({
                'items':
                map(lambda task: task.serialize('listing'), tasks),
                'domain':
                filter_domain,
            })

        if state and state == 'opened':
            # Group and return tasks for regular web viewing
            tasks_by_state = defaultdict(list)
            for task in cls.search(filter_domain):
                tasks_by_state[task.progress_state].append(task)
            return render_template('project/task-list-kanban.jinja',
                                   active_type_name='render_task_list',
                                   counts=counts,
                                   state_filter=state,
                                   tasks_by_state=tasks_by_state,
                                   states=PROGRESS_STATES[:-1],
                                   project=project)

        tasks = Pagination(cls, filter_domain, page, 20)
        return render_template('project/task-list.jinja',
                               project=project,
                               active_type_name='render_task_list',
                               counts=counts,
                               state_filter=state,
                               tasks=tasks)