Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 1 | from header import * |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 2 | |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 3 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 4 | |
| 5 | #from core.models.service import Service |
| 6 | from core.models import Service |
| 7 | |
| 8 | |
| 9 | |
| 10 | #from core.models.tenantwithcontainer import TenantWithContainer |
| 11 | from core.models import TenantWithContainer |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 16 | |
| 17 | class ExampleService(Service): |
| 18 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 19 | KIND = "exampleservice" |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 20 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 21 | class Meta: |
| 22 | app_label = "exampleservice" |
| 23 | name = "exampleservice" |
| 24 | verbose_name = "Example Service" |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 25 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 26 | # Primitive Fields (Not Relations) |
| 27 | service_message = CharField( help_text = "Service Message to Display", max_length = 254, null = False, db_index = False, blank = False ) |
| 28 | |
| 29 | |
| 30 | # Relations |
| 31 | |
| 32 | |
| 33 | |
| 34 | pass |
| 35 | |
| 36 | |
| 37 | |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 38 | |
| 39 | class ExampleTenant(TenantWithContainer): |
| 40 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 41 | KIND = "exampleservice" |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 42 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 43 | class Meta: |
| 44 | app_label = "exampleservice" |
| 45 | name = "exampletenant" |
| 46 | verbose_name = "Example Tenant" |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 47 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 48 | # Primitive Fields (Not Relations) |
| 49 | tenant_message = CharField( help_text = "Tenant Message to Display", max_length = 254, null = False, db_index = False, blank = False ) |
| 50 | |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 51 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 52 | # Relations |
| 53 | |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 54 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 55 | def __init__(self, *args, **kwargs): |
| 56 | exampleservice = ExampleService.get_service_objects().all() |
| 57 | if exampleservice: |
| 58 | self._meta.get_field('provider_service').default = exampleservice[0].id |
| 59 | super(ExampleTenant, self).__init__(*args, **kwargs) |
| 60 | |
| 61 | def save(self, *args, **kwargs): |
| 62 | super(ExampleTenant, self).save(*args, **kwargs) |
| 63 | model_policy_exampletenant(self.pk) |
| 64 | |
| 65 | def delete(self, *args, **kwargs): |
| 66 | self.cleanup_container() |
| 67 | super(ExampleTenant, self).delete(*args, **kwargs) |
| 68 | |
| 69 | pass |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 70 | |
| 71 | def model_policy_exampletenant(pk): |
| 72 | with transaction.atomic(): |
| 73 | tenant = ExampleTenant.objects.select_for_update().filter(pk=pk) |
| 74 | if not tenant: |
| 75 | return |
| 76 | tenant = tenant[0] |
| 77 | tenant.manage_container() |
| 78 | |
Sapan Bhatia | ce657e6 | 2017-04-21 14:20:41 +0200 | [diff] [blame^] | 79 | |