<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
import frappe.utils
from frappe.utils.xlsutils import get_xls
from frappe.utils.csvutils import to_csv

max_reports_per_user = 3

class AutoEmailReport(Document):
	def autoname(self):
		self.name = _(self.report)

	def validate(self):
		self.validate_report_count()
		self.validate_emails()

	def validate_emails(self):
		'''Cleanup list of emails'''
		if ',' in self.email_to:
			self.email_to.replace(',', '\n')

		valid = []
		for email in self.email_to.split():
			if email:
				frappe.utils.validate_email_add(email, True)
				valid.append(email)

		self.email_to = '\n'.join(valid)

	def validate_report_count(self):
		'''check that there are only 3 enabled reports per user'''
		count = frappe.db.sql('select count(*) from `tabAuto Email Report` where user=%s and enabled=1', self.user)[0][0]
		if count > max_reports_per_user:
			frappe.throw(_('Only {0} emailed reports are allowed per user').format(max_reports_per_user))

	def get_report_content(self):
		'''Returns file in for the report in given format'''
		report = frappe.get_doc('Report', self.report)
		raw = report.get_data(limit=self.no_of_rows or 100, user = self.user, filters = self.filters)

		if len(raw)==1 and self.send_if_data:
			return None

		if self.format == 'HTML':
			return self.get_html_table(raw)

		elif self.format == 'XLS':
			return get_xls(raw)

		elif self.format == 'CSV':
			return to_csv(raw)

		else:
			frappe.throw(_('Invalid Output Format'))

	def get_html_table(self, data):
		return frappe.render_template('frappe/templates/includes/print_table.html', {<commit_msg>[Minor] Updated condition to validate allowed email report per user (#2386)<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
import frappe.utils
from frappe.utils.xlsutils import get_xls
from frappe.utils.csvutils import to_csv

max_reports_per_user = 3

class AutoEmailReport(Document):
	def autoname(self):
		self.name = _(self.report)

	def validate(self):
		self.validate_report_count()
		self.validate_emails()

	def validate_emails(self):
		'''Cleanup list of emails'''
		if ',' in self.email_to:
			self.email_to.replace(',', '\n')

		valid = []
		for email in self.email_to.split():
			if email:
				frappe.utils.validate_email_add(email, True)
				valid.append(email)

		self.email_to = '\n'.join(valid)

	def validate_report_count(self):
		'''check that there are only 3 enabled reports per user'''
		count = frappe.db.sql('select count(*) from `tabAuto Email Report` where user=%s and enabled=1', self.user)[0][0]
		if count > max_reports_per_user + (-1 if self.flags.in_insert else 0):
			frappe.throw(_('Only {0} emailed reports are allowed per user').format(max_reports_per_user))

	def get_report_content(self):
		'''Returns file in for the report in given format'''
		report = frappe.get_doc('Report', self.report)
		raw = report.get_data(limit=self.no_of_rows or 100, user = self.user, filters = self.filters)

		if len(raw)==1 and self.send_if_data:
			return None

		if self.format == 'HTML':
			return self.get_html_table(raw)

		elif self.format == 'XLS':
			return get_xls(raw)

		elif self.format == 'CSV':
			return to_csv(raw)

		else:
			frappe.throw(_('Invalid Output Format'))

	def get_html_table(self, data):
		return frappe.render_template('frappe/templates/includes/print_table.html', {
{'fraction_non_alphanumeric': 0.12128450106157113, 'fraction_numerical': 0.009554140127388535, 'mean_word_length': 4.625373134328358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5323283', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1255, 'n_words': 337}