<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2019, 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
from frappe.desk.form.linked_with import get_linked_doctypes

class PersonalDataDownloadRequest(Document):
	def after_insert(self):
		if self.user in ['Administrator', 'Guest']:
			frappe.throw(_("This user cannot request to download data"))
		else:
			personal_data = get_unlinked_user_data(self.user)

def get_unlinked_user_data(user):
	""" returns user data not linked to User doctype """
	hooks = frappe.get_hooks("user_privacy_documents")
	data = {}
	for hook in hooks:
		d = frappe.get_all(hook.get('doctype'), {hook.get('email_field'): user},["*"])
		if d:
			data.update({ hook.get('doctype'):d })	
	return data<commit_msg>get linked data of customer<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2019, 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
from frappe.desk.form.linked_with import get_linked_doctypes

class PersonalDataDownloadRequest(Document):
	def after_insert(self):
		if self.user in ['Administrator', 'Guest']:
			frappe.throw(_("This user cannot request to download data"))
		else:
			personal_data = get_unlinked_user_data(self.user)
			personal_data.update(get_linked_user_data(self.user))

def get_unlinked_user_data(user):
	""" returns user data not linked to User doctype """
	hooks = frappe.get_hooks("user_privacy_documents")
	data = {}
	for hook in hooks:
		d = frappe.get_all(hook.get('doctype'), {hook.get('email_field'): user},["*"])
		if d:
			data.update({ hook.get('doctype'):d })	
	return data

def get_linked_user_data(user):
	""" returns user data linked to the User doctype """
	linked_doctypes = get_linked_doctypes("Customer")
	data = {}
	for doctype in linked_doctypes:
		meta = frappe.get_meta(doctype)
		if not meta.issingle:
			d = frappe.get_all(doctype, {linked_doctypes.get(doctype).get('fieldname')[0]: user},["*"])
			if d:
				data.update({ doctype:d })
	return data
{'fraction_non_alphanumeric': 0.12106430155210643, 'fraction_numerical': 0.004878048780487805, 'mean_word_length': 5.390934844192635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3960974', 'n_tokens_mistral': 789, 'n_tokens_neox': 753, 'n_words': 196}