Conditions | 6 |
Total Lines | 21 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
5 | def delete_user(user): |
||
6 | """ |
||
7 | Delete user across DB schemas. |
||
8 | """ |
||
9 | if hasattr(user, 'tenant_set'): |
||
10 | from django_tenants.utils import schema_context # pylint: disable=import-error |
||
11 | |||
12 | # using transactions b/c multiple schemas can refer to the same |
||
13 | # user ID as FK references! |
||
14 | with transaction.atomic(): |
||
15 | # delete user and all of its data across tenants |
||
16 | for tenant in user.tenant_set.all(): |
||
17 | with schema_context(tenant.schema_name): |
||
18 | user.delete() |
||
19 | |||
20 | # then delete everything from the public schema |
||
21 | with schema_context('public'): |
||
22 | user.delete() |
||
23 | |||
24 | else: |
||
25 | user.delete() |
||
26 |