[impact] Limit available functions in jinja environment

This commit is contained in:
Anand Doshi 2014-07-25 12:50:00 +05:30
parent a5437cdac1
commit 62b1cbf003
8 changed files with 22 additions and 19 deletions

View File

@ -9,7 +9,7 @@ from __future__ import unicode_literals
import os, json import os, json
import ast import ast
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
from frappe.utils.datautils import read_csv_content from frappe.utils.csvutils import read_csv_content
from frappe.utils import cstr from frappe.utils import cstr
import frappe import frappe

View File

@ -1,6 +1,6 @@
{ {
"autoname": "JVD.######", "autoname": "JVD.######",
"creation": "2013-02-22 01:27:39.000000", "creation": "2013-02-22 01:27:39",
"docstatus": 0, "docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"fields": [ "fields": [
@ -31,6 +31,7 @@
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Cost Center", "options": "Cost Center",
"permlevel": 0, "permlevel": 0,
"print_hide": 1,
"print_width": "180px", "print_width": "180px",
"search_index": 0, "search_index": 0,
"width": "180px" "width": "180px"
@ -50,6 +51,7 @@
"oldfieldtype": "Data", "oldfieldtype": "Data",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"permlevel": 0, "permlevel": 0,
"print_hide": 1,
"read_only": 1 "read_only": 1
}, },
{ {
@ -158,9 +160,10 @@
], ],
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"modified": "2014-02-03 12:44:31.000000", "modified": "2014-07-25 03:16:51.149899",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Journal Voucher Detail", "name": "Journal Voucher Detail",
"owner": "Administrator" "owner": "Administrator",
"permissions": []
} }

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _, msgprint from frappe import _, msgprint
from frappe.utils import flt, _round from frappe.utils import flt, rounded
from erpnext.setup.utils import get_company_currency from erpnext.setup.utils import get_company_currency
from erpnext.accounts.party import get_party_details from erpnext.accounts.party import get_party_details
@ -118,10 +118,10 @@ class BuyingController(StockController):
self.precision("total_tax")) self.precision("total_tax"))
if self.meta.get_field("rounded_total"): if self.meta.get_field("rounded_total"):
self.rounded_total = _round(self.grand_total) self.rounded_total = rounded(self.grand_total)
if self.meta.get_field("rounded_total_import"): if self.meta.get_field("rounded_total_import"):
self.rounded_total_import = _round(self.grand_total_import) self.rounded_total_import = rounded(self.grand_total_import)
if self.meta.get_field("other_charges_added"): if self.meta.get_field("other_charges_added"):
self.other_charges_added = flt(sum([flt(d.tax_amount) for d in self.tax_doclist self.other_charges_added = flt(sum([flt(d.tax_amount) for d in self.tax_doclist

View File

@ -3,7 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cint, flt, _round, cstr, comma_or from frappe.utils import cint, flt, rounded, cstr, comma_or
from erpnext.setup.utils import get_company_currency from erpnext.setup.utils import get_company_currency
from frappe import _, throw from frappe import _, throw
@ -220,8 +220,8 @@ class SellingController(StockController):
self.net_total_export + flt(self.discount_amount), self.net_total_export + flt(self.discount_amount),
self.precision("other_charges_total_export")) self.precision("other_charges_total_export"))
self.rounded_total = _round(self.grand_total) self.rounded_total = rounded(self.grand_total)
self.rounded_total_export = _round(self.grand_total_export) self.rounded_total_export = rounded(self.grand_total_export)
def apply_discount_amount(self): def apply_discount_amount(self):
if self.discount_amount: if self.discount_amount:

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import add_days, cint, cstr, flt, getdate, nowdate, _round from frappe.utils import add_days, cint, cstr, flt, getdate, nowdate, rounded
from frappe.model.naming import make_autoname from frappe.model.naming import make_autoname
from frappe import msgprint, _ from frappe import msgprint, _
@ -152,7 +152,7 @@ class SalarySlip(TransactionBase):
self.gross_pay = flt(self.arrear_amount) + flt(self.leave_encashment_amount) self.gross_pay = flt(self.arrear_amount) + flt(self.leave_encashment_amount)
for d in self.get("earning_details"): for d in self.get("earning_details"):
if cint(d.e_depends_on_lwp) == 1: if cint(d.e_depends_on_lwp) == 1:
d.e_modified_amount = _round(flt(d.e_amount) * flt(self.payment_days) d.e_modified_amount = rounded(flt(d.e_amount) * flt(self.payment_days)
/ cint(self.total_days_in_month), 2) / cint(self.total_days_in_month), 2)
elif not self.payment_days: elif not self.payment_days:
d.e_modified_amount = 0 d.e_modified_amount = 0
@ -164,7 +164,7 @@ class SalarySlip(TransactionBase):
self.total_deduction = 0 self.total_deduction = 0
for d in self.get('deduction_details'): for d in self.get('deduction_details'):
if cint(d.d_depends_on_lwp) == 1: if cint(d.d_depends_on_lwp) == 1:
d.d_modified_amount = _round(flt(d.d_amount) * flt(self.payment_days) d.d_modified_amount = rounded(flt(d.d_amount) * flt(self.payment_days)
/ cint(self.total_days_in_month), 2) / cint(self.total_days_in_month), 2)
elif not self.payment_days: elif not self.payment_days:
d.d_modified_amount = 0 d.d_modified_amount = 0
@ -177,7 +177,7 @@ class SalarySlip(TransactionBase):
self.calculate_earning_total() self.calculate_earning_total()
self.calculate_ded_total() self.calculate_ded_total()
self.net_pay = flt(self.gross_pay) - flt(self.total_deduction) self.net_pay = flt(self.gross_pay) - flt(self.total_deduction)
self.rounded_total = _round(self.net_pay) self.rounded_total = rounded(self.net_pay)
def on_submit(self): def on_submit(self):
if(self.email_check == 1): if(self.email_check == 1):

View File

@ -7,7 +7,7 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, add_days, date_diff from frappe.utils import cstr, add_days, date_diff
from frappe import _ from frappe import _
from frappe.utils.datautils import UnicodeWriter from frappe.utils.csvutils import UnicodeWriter
from frappe.model.document import Document from frappe.model.document import Document
class UploadAttendance(Document): class UploadAttendance(Document):
@ -96,7 +96,7 @@ def upload():
if not frappe.has_permission("Attendance", "create"): if not frappe.has_permission("Attendance", "create"):
raise frappe.PermissionError raise frappe.PermissionError
from frappe.utils.datautils import read_csv_content_from_uploaded_file from frappe.utils.csvutils import read_csv_content_from_uploaded_file
from frappe.modules import scrub from frappe.modules import scrub
rows = read_csv_content_from_uploaded_file() rows = read_csv_content_from_uploaded_file()
@ -110,7 +110,7 @@ def upload():
ret = [] ret = []
error = False error = False
from frappe.utils.datautils import check_record, import_doc from frappe.utils.csvutils import check_record, import_doc
for i, row in enumerate(rows[5:]): for i, row in enumerate(rows[5:]):
if not row: continue if not row: continue

View File

@ -302,6 +302,6 @@ class StockReconciliation(StockController):
@frappe.whitelist() @frappe.whitelist()
def upload(): def upload():
from frappe.utils.datautils import read_csv_content_from_uploaded_file from frappe.utils.csvutils import read_csv_content_from_uploaded_file
csv_content = read_csv_content_from_uploaded_file() csv_content = read_csv_content_from_uploaded_file()
return filter(lambda x: x and any(x), csv_content) return filter(lambda x: x and any(x), csv_content)

View File

@ -19,7 +19,7 @@ def get_doctypes():
@frappe.whitelist() @frappe.whitelist()
def upload(select_doctype=None, rows=None): def upload(select_doctype=None, rows=None):
from frappe.utils.datautils import read_csv_content_from_uploaded_file from frappe.utils.csvutils import read_csv_content_from_uploaded_file
from frappe.model.rename_doc import rename_doc from frappe.model.rename_doc import rename_doc
if not select_doctype: if not select_doctype: