style: Fix code correctness issues

This commit is contained in:
Suraj Shetty 2021-04-28 13:37:48 +05:30
parent d7fcc60ac7
commit 9f1f3ae3fc
5 changed files with 11 additions and 19 deletions

View file

@ -10,7 +10,6 @@ import requests.exceptions
from jinja2.exceptions import TemplateSyntaxError
import frappe
from frappe import _
from frappe.utils import get_datetime, now, strip_html, quoted
from frappe.utils.jinja import render_template
from frappe.website.doctype.website_slideshow.website_slideshow import get_slideshow

View file

@ -1,7 +1,4 @@
import os
import frappe
from frappe import _
from frappe.website.doctype.website_settings.website_settings import \
get_website_settings
from frappe.website.page_controllers.web_page import WebPage
@ -69,10 +66,11 @@ class BaseTemplatePage(WebPage):
def init_metatags_from_context(self):
for key in ('title', 'description', 'image', 'author', 'url', 'published_on'):
if not key in self.tags and self.context.get(key):
if key not in self.tags and self.context.get(key):
self.tags[key] = self.context[key]
if not self.tags.get('title'): self.tags['title'] = self.context.get('name')
if not self.tags.get('title'):
self.tags['title'] = self.context.get('name')
if self.tags.get('image'):
self.tags['image'] = frappe.utils.get_url(self.tags['image'])

View file

@ -1,5 +1,4 @@
import frappe
from frappe import _
from frappe.model.document import get_controller
from frappe.website.page_controllers.base_template_page import BaseTemplatePage
from frappe.website.render import build_response
@ -36,7 +35,8 @@ class DocumentPage(BaseTemplatePage):
self.meta = meta
return True
except Exception as e:
if not frappe.db.is_missing_column(e): raise e
if not frappe.db.is_missing_column(e):
raise e
def search_web_page_dynamic_routes(self):
d = get_page_info_from_web_page_with_dynamic_routes(self.path)
@ -74,7 +74,7 @@ class DocumentPage(BaseTemplatePage):
self.context.update(ret)
for prop in ("no_cache", "sitemap"):
if not prop in self.context:
if prop not in self.context:
self.context[prop] = getattr(self.doc, prop, False)
def get_condition_field(self, meta):

View file

@ -2,7 +2,6 @@ import io
import os
import frappe
from frappe import _
from frappe.website.page_controllers.base_template_page import BaseTemplatePage
from frappe.website.context import add_sidebar_and_breadcrumbs
from frappe.website.render import build_response
@ -95,8 +94,6 @@ class TemplatePage(BaseTemplatePage):
if self.extends_template():
self.context.base_template_path = self.context.base_template_path
# TODO: setup index.txt ?
def update_context(self):
@ -110,10 +107,9 @@ class TemplatePage(BaseTemplatePage):
self.set_pymodule_properties()
data = self.run_pymodule_method('get_context')
# some methods may return a "context" object
if data: self.context.update(data)
if data:
self.context.update(data)
# TODO: self.context.children = self.run_pymodule_method('get_children')
self.context.developer_mode = frappe.conf.developer_mode
@ -128,7 +124,7 @@ class TemplatePage(BaseTemplatePage):
def set_page_properties(self):
self.context.template = self.template_path
self.context.base_template = self.context.base_template or 'templates/web.html'
self.context.base_template = self.context.base_template or 'templates/web.html'
def set_properties_from_source(self):
if not self.source:
@ -154,7 +150,7 @@ class TemplatePage(BaseTemplatePage):
return getattr(self.pymodule, method)(self.context)
except (frappe.PermissionError, frappe.DoesNotExistError, frappe.Redirect):
raise
except:
except Exception:
if not frappe.flags.in_migrate:
frappe.errprint(frappe.utils.get_traceback())
@ -225,7 +221,7 @@ class TemplatePage(BaseTemplatePage):
self.template_path = 'www/{path}.html'.format(path=path)
def set_missing_values(self):
if not "url_prefix" in self.context:
if "url_prefix" not in self.context:
self.context.url_prefix = ""
if self.context.url_prefix and self.context.url_prefix[-1]!='/':

View file

@ -1,5 +1,4 @@
import frappe
from frappe import _
from frappe.utils import cstr
from frappe.website.page_controllers.document_page import DocumentPage