def get_website_meta(self): """ This method will return final meta information. It will replace default values with user's custom value (if user modified it from the seo popup of frontend) This method is not meant for overridden. To customize meta values override `_default_website_meta` method instead of this method. This method only replaces user custom values in defaults. """ root_url = request.httprequest.url_root.strip('/') default_meta = self._default_website_meta() opengraph_meta, twitter_meta = default_meta[ 'default_opengraph'], default_meta['default_twitter'] if self.website_meta_title: opengraph_meta['og:title'] = self.website_meta_title twitter_meta['twitter:title'] = self.website_meta_title if self.website_meta_description: opengraph_meta['og:description'] = self.website_meta_description twitter_meta['twitter:description'] = self.website_meta_description opengraph_meta['og:image'] = url_join( root_url, url_for(self.website_meta_og_img or opengraph_meta['og:image'])) twitter_meta['twitter:image'] = url_join( root_url, url_for(self.website_meta_og_img or twitter_meta['twitter:image'])) return { 'opengraph_meta': opengraph_meta, 'twitter_meta': twitter_meta, 'meta_description': default_meta.get('default_meta_description') }
def webmanifest(self): """ Returns a WebManifest describing the metadata associated with a web application. Using this metadata, user agents can provide developers with means to create user experiences that are more comparable to that of a native application. """ company = request.env.company website = request.website manifest = { 'name': _('%s Online Events') % company.name, 'short_name': company.name, 'description': _('%s Online Events') % company.name, 'scope': url_for('/event'), 'start_url': url_for('/event'), 'display': 'standalone', 'background_color': '#ffffff', 'theme_color': '#875A7B', } icon_sizes = ['192x192', '512x512'] manifest['icons'] = [{ 'src': website.image_url(website, 'app_icon', size=size), 'sizes': size, 'type': 'image/png', } for size in icon_sizes] body = json.dumps(manifest, default=ustr) response = request.make_response(body, [ ('Content-Type', 'application/manifest+json'), ]) return response
def get_suggested_controllers(self): """ Returns a tuple (name, url, icon). Where icon can be a module name, or a path """ suggested_controllers = [ (_('Homepage'), url_for('/'), 'website'), (_('Contact Us'), url_for('/contactus'), 'website_crm'), ] return suggested_controllers
def _post_processing_att(self, tagName, atts, options): if atts.get('data-no-post-process'): return atts atts = super(QWeb, self)._post_processing_att(tagName, atts, options) if options.get('inherit_branding') or options.get('rendering_bundle') or \ options.get('edit_translations') or options.get('debug') or (request and request.debug): return atts website = request and getattr(request, 'website', None) if not website and options.get('website_id'): website = self.env['website'].browse(options['website_id']) if not website: return atts name = self.URL_ATTRS.get(tagName) if request and name and name in atts: atts[name] = url_for(atts[name]) if not website.cdn_activated: return atts if name and name in atts: atts = OrderedDict(atts) atts[name] = website.get_cdn_url(atts[name]) if isinstance(atts.get('style'), str) and 'background-image' in atts['style']: atts = OrderedDict(atts) atts['style'] = re_background_image.sub(lambda m: '%s%s' % (m.group(1), website.get_cdn_url(m.group(2))), atts['style']) return atts
def redirect(url, code=302): """Add the `redirect` method to the request. This method is added programatically by the module http_routing: odoo/addons/http_routing/models/ir_http.py (method _dispatch) """ return werkzeug.utils.redirect(url_for(url), code)
def _compute_embed_code(self): base_url = request and request.httprequest.url_root or self.env[ 'ir.config_parameter'].sudo().get_param('web.base.url') if base_url[-1] == '/': base_url = base_url[:-1] for record in self: if record.datas and (not record.document_id or record.slide_type in ['document', 'presentation']): slide_url = base_url + url_for( '/slides/embed/%s?page=1' % record.id) record.embed_code = '<iframe src="%s" class="o_wslides_iframe_viewer" allowFullScreen="true" height="%s" width="%s" frameborder="0"></iframe>' % ( slide_url, 315, 420) elif record.slide_type == 'video' and record.document_id: if not record.mime_type: # embed youtube video query = urls.url_parse(record.url).query query = query + '&theme=light' if query else 'theme=light' record.embed_code = '<iframe src="//www.youtube-nocookie.com/embed/%s?%s" allowFullScreen="true" frameborder="0"></iframe>' % ( record.document_id, query) else: # embed google doc video record.embed_code = '<iframe src="//drive.google.com/file/d/%s/preview" allowFullScreen="true" frameborder="0"></iframe>' % ( record.document_id) else: record.embed_code = False
def _post_processing_att(self, tagName, atts, options): if atts.get('data-no-post-process'): return atts atts = super(QWeb, self)._post_processing_att(tagName, atts, options) if options.get('inherit_branding') or options.get('rendering_bundle') or \ options.get('edit_translations') or options.get('debug') or (request and request.session.debug): return atts website = ir_http.get_request_website() if not website and options.get('website_id'): website = self.env['website'].browse(options['website_id']) if not website: return atts name = self.URL_ATTRS.get(tagName) if request and name and name in atts: atts[name] = url_for(atts[name]) if not website.cdn_activated: return atts if name and name in atts: atts = OrderedDict(atts) atts[name] = website.get_cdn_url(atts[name]) if isinstance(atts.get('style'), str) and 'background-image' in atts['style']: atts = OrderedDict(atts) atts['style'] = re_background_image.sub(lambda m: '%s%s' % (m.group(1), website.get_cdn_url(m.group(2))), atts['style']) return atts
def service_worker(self): """ Returns a ServiceWorker javascript file scoped for website_event """ sw_file = get_module_resource('website_event_track_online', 'static/src/js/service_worker.js') with open(sw_file, 'rb') as fp: body = fp.read() response = request.make_response(body, [ ('Content-Type', 'text/javascript'), ('Service-Worker-Allowed', url_for('/event')), ]) return response
def button_go_website(self, path='/', mode_edit=False): self._force() if mode_edit: # If the user gets on a translated page (e.g /fr) the editor will # never start. Forcing the default language fixes this issue. path = url_for(path, self.default_lang_id.url_code) path += '?enable_editor=1' return { 'type': 'ir.actions.act_url', 'url': path, 'target': 'self', }
def _default_website_meta(self): """ This method will return default meta information. It return the dict contains meta property as a key and meta content as a value. e.g. 'og:type': 'website'. Override this method in case you want to change default value from any model. e.g. change value of og:image to product specific images instead of default images """ self.ensure_one() company = request.website.company_id.sudo() title = (request.website or company).name if 'name' in self: title = '%s | %s' % (self.name, title) img_field = 'social_default_image' if request.website.has_social_default_image else 'logo' # Default meta for OpenGraph default_opengraph = { 'og:type': 'website', 'og:title': title, 'og:site_name': company.name, 'og:url': url_join(request.httprequest.url_root, url_for(request.httprequest.path)), 'og:image': request.website.image_url(request.website, img_field), } # Default meta for Twitter default_twitter = { 'twitter:card': 'summary_large_image', 'twitter:title': title, 'twitter:image': request.website.image_url(request.website, img_field, size='300x300'), } if company.social_twitter: default_twitter[ 'twitter:site'] = "@%s" % company.social_twitter.split('/')[-1] return { 'default_opengraph': default_opengraph, 'default_twitter': default_twitter }
def _get_embed_code(self): base_url = request and request.httprequest.url_root or self.env['ir.config_parameter'].sudo().get_param('web.base.url') if base_url[-1] == '/': base_url = base_url[:-1] for record in self: if record.datas and (not record.document_id or record.slide_type in ['document', 'presentation']): slide_url = base_url + url_for('/slides/embed/%s?page=1' % record.id) record.embed_code = '<iframe src="%s" class="o_wslides_iframe_viewer" allowFullScreen="true" height="%s" width="%s" frameborder="0"></iframe>' % (slide_url, 315, 420) elif record.slide_type == 'video' and record.document_id: if not record.mime_type: # embed youtube video record.embed_code = '<iframe src="//www.youtube.com/embed/%s?theme=light" allowFullScreen="true" frameborder="0"></iframe>' % (record.document_id) else: # embed google doc video record.embed_code = '<iframe src="//drive.google.com/file/d/%s/preview" allowFullScreen="true" frameborder="0"></iframe>' % (record.document_id) else: record.embed_code = False
def service_worker(self): """ Returns a ServiceWorker javascript file scoped for website_event """ sw_file = get_module_resource('website_event_track', 'static/src/js/service_worker.js') with open(sw_file, 'r') as fp: body = fp.read() js_cdn_url = 'undefined' if request.website.cdn_activated: cdn_url = request.website.cdn_url.replace('"', '%22').replace( '\x5c', '%5C') js_cdn_url = '"%s"' % cdn_url body = body.replace('__ODOO_CDN_URL__', js_cdn_url) response = request.make_response(body, [ ('Content-Type', 'text/javascript'), ('Service-Worker-Allowed', url_for('/event')), ]) return response
def _post_processing_att(self, tagName, atts): if atts.get('data-no-post-process'): return atts atts = super()._post_processing_att(tagName, atts) website = ir_http.get_request_website() if not website and self.env.context.get('website_id'): website = self.env['website'].browse( self.env.context['website_id']) if website and tagName == 'img' and 'loading' not in atts: atts['loading'] = 'lazy' # default is auto if self.env.context.get('inherit_branding') or self.env.context.get('rendering_bundle') or \ self.env.context.get('edit_translations') or self.env.context.get('debug') or (request and request.session.debug): return atts if not website: return atts name = self.URL_ATTRS.get(tagName) if request and name and name in atts: atts[name] = url_for(atts[name]) if not website.cdn_activated: return atts data_name = f'data-{name}' if name and (name in atts or data_name in atts): atts = OrderedDict(atts) if name in atts: atts[name] = website.get_cdn_url(atts[name]) if data_name in atts: atts[data_name] = website.get_cdn_url(atts[data_name]) if isinstance(atts.get('style'), str) and 'background-image' in atts['style']: atts = OrderedDict(atts) atts['style'] = re_background_image.sub( lambda m: '%s%s' % (m.group(1), website.get_cdn_url(m.group(2))), atts['style']) return atts
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('Appointment'), url_for('/calendar'), 'website_calendar')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append((_('Helpdesk Customer Satisfaction'), url_for('/helpdesk/rating'), 'helpdesk')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('Mailing Lists'), url_for('/groups'), 'website_mail_channel')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append((_('Resellers'), url_for('/partners'), 'website_crm_partner_assign')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('Blog'), url_for('/blog'), 'website_blog')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('Members'), url_for('/members'), 'website_membership')) return suggested_controllers
def test_01_url_for(self): with MockRequest(self.env, website=self.website): self.assertEqual( url_for('', '[lang]'), '/[lang]/hello/', "`[lang]` is used to be replaced in the url_return after installing a language, it should not be replaced or removed." )
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('Events'), url_for('/event'), 'website_event')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('Live Support'), url_for('/livechat'), 'website_livechat')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('References'), url_for('/customers'), 'website_customer')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('Jobs'), url_for('/jobs'), 'website_hr_recruitment')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('eCommerce'), url_for('/shop'), 'website_sale')) return suggested_controllers
def get_suggested_controllers(self): suggested_controllers = super(Website, self).get_suggested_controllers() suggested_controllers.append( (_('Courses'), url_for('/slides'), 'website_slides')) return suggested_controllers