def partners_detail(self, partner_id, **post): _, partner_id = unslug(partner_id) current_grade, current_country = None, None grade_id = post.get('grade_id') country_id = post.get('country_id') print post if grade_id: current_grade = request.env['res.partner.grade'].browse( int(grade_id)).exists() if country_id: current_country = request.env['res.country'].browse( int(country_id)).exists() if partner_id: partner = request.env['res.partner'].sudo().browse(partner_id) is_website_publisher = request.env['res.users'].has_group( 'base.group_website_publisher') if partner.exists() and (partner.website_published or is_website_publisher): values = { 'main_object': partner, 'partner': partner, 'current_grade': current_grade, 'current_country': current_country } return request.render("website_crm_partner_assign.partner", values) return self.partners(**post)
def unslug_url(s): parts = s.split('/') if parts: unslug_val = website.unslug(parts[-1]) if unslug_val[1]: parts[-1] = str(unslug_val[1]) return '/'.join(parts) return s
def partners_detail(self, partner_id, **post): _, partner_id = unslug(partner_id) if partner_id: partner = request.env['res.partner'].sudo().browse(partner_id) if partner.exists() and partner.website_published: values = {} values['main_object'] = values['partner'] = partner return request.render("website_customer.details", values) return self.customers(**post)
def website_image_cpo(self, model=None, id=None, **kw): id_data = unslug(id) id = id_data[len(id_data) - 1] model = kw.get('cpo_model') status, headers, content, image_base64 = self.cpo_get_binary_content( model=model, id=id, unique=False, width=0, height=0) response = request.make_response(image_base64, headers) response.status_code = status return response
def partners_detail(self, partner_id, **post): _, partner_id = unslug(partner_id) if partner_id: partner = request.env['res.partner'].sudo().browse(partner_id) if partner.exists() and partner.website_published: # TODO should be done with access rules values = {} values['main_object'] = values['partner'] = partner return request.website.render("website_membership.partner", values) return self.members(**post)
def partners_detail(self, partner_id, **post): _, partner_id = unslug(partner_id) if partner_id: partner_sudo = request.env['res.partner'].sudo().browse(partner_id) is_website_publisher = request.env['res.users'].has_group('base.group_website_publisher') if partner_sudo.exists() and (partner_sudo.website_published or is_website_publisher): values = { 'main_object': partner_sudo, 'partner': partner_sudo, 'edit_page': False } return request.render("website_partner.partner_page", values) return request.not_found()
def blog_categories(self, blog=None, category=None, page=1, **opt): """ It filters out blog posts not of correct category """ context = http.request.env.context.copy() category = http.request.env['blog.category'].browse( unslug(category)[1], ) context.update({ 'website_category_id': category.id, }) http.request.env.context = context res = self.blog(blog, None, page, **opt) res.qcontext.update({ 'category': category, }) return res
def partners_detail(self, partner_id, **post): _, partner_id = unslug(partner_id) if partner_id: partner_sudo = request.env['res.partner'].sudo().browse(partner_id) is_website_publisher = request.env['res.users'].has_group( 'base.group_website_publisher') if partner_sudo.exists() and (partner_sudo.website_published or is_website_publisher): values = { 'main_object': partner_sudo, 'partner': partner_sudo, 'edit_page': False } return request.render("website_partner.partner_page", values) return request.not_found()
def test_unslug(self): tests = { '': (None, None), 'foo': (None, None), 'foo-': (None, None), '-': (None, None), 'foo-1': ('foo', 1), 'foo-bar-1': ('foo-bar', 1), 'foo--1': ('foo', -1), '1': (None, 1), '1-1': ('1', 1), '--1': (None, None), 'foo---1': (None, None), 'foo1': (None, None), } for slug, expected in tests.iteritems(): self.assertEqual(unslug(slug), expected)
def partners_detail(self, partner_id, **post): _, partner_id = unslug(partner_id) current_grade, current_country = None, None grade_id = post.get('grade_id') country_id = post.get('country_id') if grade_id: current_grade = request.env['res.partner.grade'].browse(int(grade_id)).exists() if country_id: current_country = request.env['res.country'].browse(int(country_id)).exists() if partner_id: partner = request.env['res.partner'].sudo().browse(partner_id) is_website_publisher = request.env['res.users'].has_group('website.group_website_publisher') if partner.exists() and (partner.website_published or is_website_publisher): values = { 'main_object': partner, 'partner': partner, 'current_grade': current_grade, 'current_country': current_country } return request.render("website_crm_partner_assign.partner", values) return self.partners(**post)
def partners_detail(self, partner_id, **post): _, partner_id = unslug(partner_id) current_grade, current_country = None, None grade_id = post.get("grade_id") country_id = post.get("country_id") print post if grade_id: current_grade = request.env["res.partner.grade"].browse(int(grade_id)).exists() if country_id: current_country = request.env["res.country"].browse(int(country_id)).exists() if partner_id: partner = request.env["res.partner"].sudo().browse(partner_id) is_website_publisher = request.env["res.users"].has_group("base.group_website_publisher") if partner.exists() and (partner.website_published or is_website_publisher): values = { "main_object": partner, "partner": partner, "current_grade": current_grade, "current_country": current_country, } return request.website.render("website_crm_partner_assign.partner", values) return self.partners(**post)
def blog(self, blog=None, tag=None, page=1, **opt): """ Prepare all values to display the blog. :return dict values: values for the templates, containing - 'blog': current blog - 'blogs': all blogs for navigation - 'pager': pager of posts - 'active_tag_ids' : list of active tag ids, - 'tags_list' : function to built the comma-separated tag list ids (for the url), - 'tags': all tags, for navigation - 'state_info': state of published/unpublished filter - 'nav_list': a dict [year][month] for archives navigation - 'date': date_begin optional parameter, used in archives navigation - 'blog_url': help object to create URLs """ date_begin, date_end, state = opt.get('date_begin'), opt.get( 'date_end'), opt.get('state') published_count, unpublished_count = 0, 0 BlogPost = request.env['blog.post'] Blog = request.env['blog.blog'] blogs = Blog.search([], order="create_date asc") # build the domain for blog post to display domain = [] # retrocompatibility to accept tag as slug active_tag_ids = tag and [int(unslug(t)[1]) for t in tag.split(',')] or [] if active_tag_ids: domain += [('tag_ids', 'in', active_tag_ids)] if blog: domain += [('blog_id', '=', blog.id)] if date_begin and date_end: domain += [("post_date", ">=", date_begin), ("post_date", "<=", date_end)] if request.env.user.has_group('website.group_website_designer'): count_domain = domain + [("website_published", "=", True), ("post_date", "<=", fields.Datetime.now()) ] published_count = BlogPost.search_count(count_domain) unpublished_count = BlogPost.search_count(domain) - published_count if state == "published": domain += [("website_published", "=", True), ("post_date", "<=", fields.Datetime.now())] elif state == "unpublished": domain += [ '|', ("website_published", "=", False), ("post_date", ">", fields.Datetime.now()) ] else: domain += [("post_date", "<=", fields.Datetime.now())] blog_url = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end) blog_posts = BlogPost.search(domain, order="post_date desc") pager = request.website.pager( url=request.httprequest.path.partition('/page/')[0], total=len(blog_posts), page=page, step=self._blog_post_per_page, url_args=opt, ) pager_begin = (page - 1) * self._blog_post_per_page pager_end = page * self._blog_post_per_page blog_posts = blog_posts[pager_begin:pager_end] all_tags = blog.all_tags()[blog.id] # function to create the string list of tag ids, and toggle a given one. # used in the 'Tags Cloud' template. def tags_list(tag_ids, current_tag): tag_ids = list(tag_ids) # required to avoid using the same list if current_tag in tag_ids: tag_ids.remove(current_tag) else: tag_ids.append(current_tag) tag_ids = request.env['blog.tag'].browse(tag_ids).exists() return ','.join(slug(tag) for tag in tag_ids) values = { 'blog': blog, 'blogs': blogs, 'main_object': blog, 'tags': all_tags, 'state_info': { "state": state, "published": published_count, "unpublished": unpublished_count }, 'active_tag_ids': active_tag_ids, 'tags_list': tags_list, 'blog_posts': blog_posts, 'blog_posts_cover_properties': [json.loads(b.cover_properties) for b in blog_posts], 'pager': pager, 'nav_list': self.nav_list(blog), 'blog_url': blog_url, 'date': date_begin, } response = request.render("website_blog.blog_post_short", values) return response
def customers(self, country_id=0, page=0, country_name='', tag_id=0, **post): Country = request.env['res.country'] Tag = request.env['res.partner.tag'] Partner = request.env['res.partner'] partner_name = post.get('search', '') domain = [('website_published', '=', True), ('assigned_partner_id', '!=', False)] if partner_name: domain += [ '|', ('name', 'ilike', post.get("search")), ('website_description', 'ilike', post.get("search")) ] if tag_id: tag_id = unslug(tag_id)[1] or 0 domain += [('tag_ids', 'in', tag_id)] # group by country, based on customers found with the search(domain) countries = Partner.sudo().read_group(domain, ["id", "country_id"], groupby="country_id", orderby="country_id") country_count = Partner.sudo().search_count(domain) if country_id: domain += [('country_id', '=', country_id)] if not any(x['country_id'][0] == country_id for x in countries if x['country_id']): country = Country.browse(country_id).read(['name']) if country: countries.append({ 'country_id_count': 0, 'country_id': (country_id, country['name']) }) countries.sort(key=lambda d: d['country_id'] and d['country_id'][1]) curr_country = Country.browse(country_id) countries.insert(0, { 'country_id_count': country_count, 'country_id': (0, _("All Countries")) }) # search customers to display partner_count = Partner.sudo().search_count(domain) # pager url = '/customers' if country_id: url += '/country/%s' % country_id pager = request.website.pager( url=url, total=partner_count, page=page, step=self._references_per_page, scope=7, url_args=post ) partners = Partner.sudo().search(domain, offset=pager['offset'], limit=self._references_per_page) google_map_partner_ids = ','.join(map(str, partners.ids)) google_maps_api_key = request.env['ir.config_parameter'].sudo().get_param('google_maps_api_key') tags = Tag.search([('website_published', '=', True), ('partner_ids', 'in', partners.ids)], order='classname, name ASC') tag = tag_id and Tag.browse(tag_id) or False values = { 'countries': countries, 'current_country_id': country_id or 0, 'current_country': curr_country if country_id else False, 'partners': partners, 'google_map_partner_ids': google_map_partner_ids, 'pager': pager, 'post': post, 'search_path': "?%s" % werkzeug.url_encode(post), 'tag': tag, 'tags': tags, 'google_maps_api_key': google_maps_api_key, } return request.render("website_customer.index", values)
def customers(self, country=None, industry=None, page=0, **post): Tag = request.env['res.partner.tag'] Partner = request.env['res.partner'] search_value = post.get('search') domain = [('website_published', '=', True), ('assigned_partner_id', '!=', False)] if search_value: domain += [ '|', '|', ('name', 'ilike', search_value), ('website_description', 'ilike', search_value), ('industry_id.name', 'ilike', search_value), ] tag_id = post.get('tag_id') if tag_id: tag_id = unslug(tag_id)[1] or 0 domain += [('website_tag_ids', 'in', tag_id)] # group by industry, based on customers found with the search(domain) industries = Partner.sudo().read_group(domain, ["id", "industry_id"], groupby="industry_id", orderby="industry_id") partners_count = Partner.sudo().search_count(domain) if industry: domain.append(('industry_id', '=', industry.id)) if industry.id not in (x['industry_id'][0] for x in industries if x['industry_id']): if industry.exists(): industries.append({ 'industry_id_count': 0, 'industry_id': (industry.id, industry.name) }) industries.sort(key=lambda d: (d.get('industry_id') or (0, ''))[1]) industries.insert(0, { 'industry_id_count': partners_count, 'industry_id': (0, _("All Sectors of Activity")) }) # group by country, based on customers found with the search(domain) countries = Partner.sudo().read_group(domain, ["id", "country_id"], groupby="country_id", orderby="country_id") country_count = Partner.sudo().search_count(domain) if country: domain += [('country_id', '=', country.id)] if country.id not in (x['country_id'][0] for x in countries if x['country_id']): if country.exists(): countries.append({ 'country_id_count': 0, 'country_id': (country.id, country.name) }) countries.sort(key=lambda d: d['country_id'] and d['country_id'][1]) countries.insert(0, { 'country_id_count': country_count, 'country_id': (0, _("All Countries")) }) # search customers to display partner_count = Partner.sudo().search_count(domain) # pager url = '/customers' if industry: url += '/industry/%s' % industry.id if country: url += '/country/%s' % country.id pager = request.website.pager( url=url, total=partner_count, page=page, step=self._references_per_page, scope=7, url_args=post ) partners = Partner.sudo().search(domain, offset=pager['offset'], limit=self._references_per_page) google_map_partner_ids = ','.join(str(it) for it in partners.ids) google_maps_api_key = request.env['ir.config_parameter'].sudo().get_param('google_maps_api_key') tags = Tag.search([('website_published', '=', True), ('partner_ids', 'in', partners.ids)], order='classname, name ASC') tag = tag_id and Tag.browse(tag_id) or False values = { 'countries': countries, 'current_country_id': country.id if country else 0, 'current_country': country or False, 'industries': industries, 'current_industry_id': industry.id if industry else 0, 'current_industry': industry or False, 'partners': partners, 'google_map_partner_ids': google_map_partner_ids, 'pager': pager, 'post': post, 'search_path': "?%s" % werkzeug.url_encode(post), 'tag': tag, 'tags': tags, 'google_maps_api_key': google_maps_api_key, } return request.render("website_customer.index", values)
def customers(self, country_id=0, page=0, country_name='', tag_id=0, **post): Country = request.env['res.country'] Tag = request.env['res.partner.tag'] Partner = request.env['res.partner'] partner_name = post.get('search', '') domain = [('website_published', '=', True), ('assigned_partner_id', '!=', False)] if partner_name: domain += [ '|', ('name', 'ilike', post.get("search")), ('website_description', 'ilike', post.get("search")) ] if tag_id: tag_id = unslug(tag_id)[1] or 0 domain += [('tag_ids', 'in', tag_id)] # group by country, based on customers found with the search(domain) countries = Partner.sudo().read_group(domain, ["id", "country_id"], groupby="country_id", orderby="country_id") country_count = Partner.sudo().search_count(domain) if country_id: domain += [('country_id', '=', country_id)] if not any(x['country_id'][0] == country_id for x in countries if x['country_id']): country = Country.browse(country_id).read(['name']) if country: countries.append({ 'country_id_count': 0, 'country_id': (country_id, country['name']) }) countries.sort( key=lambda d: d['country_id'] and d['country_id'][1]) curr_country = Country.browse(country_id) countries.insert( 0, { 'country_id_count': country_count, 'country_id': (0, _("All Countries")) }) # search customers to display partner_count = Partner.sudo().search_count(domain) # pager url = '/customers' if country_id: url += '/country/%s' % country_id pager = request.website.pager(url=url, total=partner_count, page=page, step=self._references_per_page, scope=7, url_args=post) partners = Partner.sudo().search(domain, offset=pager['offset'], limit=self._references_per_page) google_map_partner_ids = ','.join(map(str, partners.ids)) tags = Tag.search([('website_published', '=', True), ('partner_ids', 'in', partners.ids)], order='classname, name ASC') tag = tag_id and Tag.browse(tag_id) or False values = { 'countries': countries, 'current_country_id': country_id or 0, 'current_country': curr_country if country_id else False, 'partners': partners, 'google_map_partner_ids': google_map_partner_ids, 'pager': pager, 'post': post, 'search_path': "?%s" % werkzeug.url_encode(post), 'tag': tag, 'tags': tags, } return request.render("website_customer.index", values)
def blog(self, blog=None, tag=None, page=1, **opt): """ Prepare all values to display the blog. :return dict values: values for the templates, containing - 'blog': current blog - 'blogs': all blogs for navigation - 'pager': pager of posts - 'active_tag_ids' : list of active tag ids, - 'tags_list' : function to built the comma-separated tag list ids (for the url), - 'tags': all tags, for navigation - 'state_info': state of published/unpublished filter - 'nav_list': a dict [year][month] for archives navigation - 'date': date_begin optional parameter, used in archives navigation - 'blog_url': help object to create URLs """ date_begin, date_end, state = opt.get('date_begin'), opt.get('date_end'), opt.get('state') published_count, unpublished_count = 0, 0 BlogPost = request.env['blog.post'] Blog = request.env['blog.blog'] blogs = Blog.search([], order="create_date asc") # build the domain for blog post to display domain = [] # retrocompatibility to accept tag as slug active_tag_ids = tag and map(int, [unslug(t)[1] for t in tag.split(',')]) or [] if active_tag_ids: domain += [('tag_ids', 'in', active_tag_ids)] if blog: domain += [('blog_id', '=', blog.id)] if date_begin and date_end: domain += [("post_date", ">=", date_begin), ("post_date", "<=", date_end)] if request.env.user.has_group('website.group_website_designer'): count_domain = domain + [("website_published", "=", True), ("post_date", "<=", fields.Datetime.now())] published_count = BlogPost.search_count(count_domain) unpublished_count = BlogPost.search_count(domain) - published_count if state == "published": domain += [("website_published", "=", True), ("post_date", "<=", fields.Datetime.now())] elif state == "unpublished": domain += ['|', ("website_published", "=", False), ("post_date", ">", fields.Datetime.now())] else: domain += [("post_date", "<=", fields.Datetime.now())] blog_url = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end) blog_posts = BlogPost.search(domain, order="post_date desc") pager = request.website.pager( url=request.httprequest.path.partition('/page/')[0], total=len(blog_posts), page=page, step=self._blog_post_per_page, url_args=opt, ) pager_begin = (page - 1) * self._blog_post_per_page pager_end = page * self._blog_post_per_page blog_posts = blog_posts[pager_begin:pager_end] all_tags = blog.all_tags()[blog.id] # function to create the string list of tag ids, and toggle a given one. # used in the 'Tags Cloud' template. def tags_list(tag_ids, current_tag): tag_ids = list(tag_ids) # required to avoid using the same list if current_tag in tag_ids: tag_ids.remove(current_tag) else: tag_ids.append(current_tag) tag_ids = request.env['blog.tag'].browse(tag_ids).exists() return ','.join(map(slug, tag_ids)) values = { 'blog': blog, 'blogs': blogs, 'main_object': blog, 'tags': all_tags, 'state_info': {"state": state, "published": published_count, "unpublished": unpublished_count}, 'active_tag_ids': active_tag_ids, 'tags_list' : tags_list, 'blog_posts': blog_posts, 'blog_posts_cover_properties': [json.loads(b.cover_properties) for b in blog_posts], 'pager': pager, 'nav_list': self.nav_list(blog), 'blog_url': blog_url, 'date': date_begin, } response = request.render("website_blog.blog_post_short", values) return response
def customers(self, country=None, industry=None, page=0, **post): Tag = request.env['res.partner.tag'] Partner = request.env['res.partner'] search_value = post.get('search') domain = [('website_published', '=', True), ('assigned_partner_id', '!=', False)] if search_value: domain += [ '|', '|', ('name', 'ilike', search_value), ('website_description', 'ilike', search_value), ('industry_id.name', 'ilike', search_value), ] tag_id = post.get('tag_id') if tag_id: tag_id = unslug(tag_id)[1] or 0 domain += [('website_tag_ids', 'in', tag_id)] # group by industry, based on customers found with the search(domain) industries = Partner.sudo().read_group(domain, ["id", "industry_id"], groupby="industry_id", orderby="industry_id") partners_count = Partner.sudo().search_count(domain) if industry: domain.append(('industry_id', '=', industry.id)) if industry.id not in (x['industry_id'][0] for x in industries if x['industry_id']): if industry.exists(): industries.append({ 'industry_id_count': 0, 'industry_id': (industry.id, industry.name) }) industries.sort(key=lambda d: (d.get('industry_id') or (0, ''))[1]) industries.insert(0, { 'industry_id_count': partners_count, 'industry_id': (0, _("All Sectors of Activity")) }) # group by country, based on customers found with the search(domain) countries = Partner.sudo().read_group(domain, ["id", "country_id"], groupby="country_id", orderby="country_id") country_count = Partner.sudo().search_count(domain) if country: domain += [('country_id', '=', country.id)] if country.id not in (x['country_id'][0] for x in countries if x['country_id']): if country.exists(): countries.append({ 'country_id_count': 0, 'country_id': (country.id, country.name) }) countries.sort(key=lambda d: (d['country_id'] or (0, ""))[1]) countries.insert(0, { 'country_id_count': country_count, 'country_id': (0, _("All Countries")) }) # search customers to display partner_count = Partner.sudo().search_count(domain) # pager url = '/customers' if industry: url += '/industry/%s' % industry.id if country: url += '/country/%s' % country.id pager = request.website.pager( url=url, total=partner_count, page=page, step=self._references_per_page, scope=7, url_args=post ) partners = Partner.sudo().search(domain, offset=pager['offset'], limit=self._references_per_page) google_map_partner_ids = ','.join(str(it) for it in partners.ids) google_maps_api_key = request.env['ir.config_parameter'].sudo().get_param('google_maps_api_key') tags = Tag.search([('website_published', '=', True), ('partner_ids', 'in', partners.ids)], order='classname, name ASC') tag = tag_id and Tag.browse(tag_id) or False values = { 'countries': countries, 'current_country_id': country.id if country else 0, 'current_country': country or False, 'industries': industries, 'current_industry_id': industry.id if industry else 0, 'current_industry': industry or False, 'partners': partners, 'google_map_partner_ids': google_map_partner_ids, 'pager': pager, 'post': post, 'search_path': "?%s" % werkzeug.url_encode(post), 'tag': tag, 'tags': tags, 'google_maps_api_key': google_maps_api_key, } return request.render("website_customer.index", values)