blob: af8cdb537c6d2050c853420bff2092302450c8df [file] [log] [blame]
Sapan Bhatiace657e62017-04-21 14:20:41 +02001from header import *
Scott Baker619de672016-06-20 12:49:38 -07002
Scott Baker619de672016-06-20 12:49:38 -07003
Sapan Bhatiace657e62017-04-21 14:20:41 +02004
5#from core.models.service import Service
6from core.models import Service
7
8
9
10#from core.models.tenantwithcontainer import TenantWithContainer
11from core.models import TenantWithContainer
12
13
14
15
Scott Baker619de672016-06-20 12:49:38 -070016
17class ExampleService(Service):
18
Sapan Bhatiace657e62017-04-21 14:20:41 +020019 KIND = "exampleservice"
Scott Baker619de672016-06-20 12:49:38 -070020
Sapan Bhatiace657e62017-04-21 14:20:41 +020021 class Meta:
22 app_label = "exampleservice"
23 name = "exampleservice"
24 verbose_name = "Example Service"
Scott Baker619de672016-06-20 12:49:38 -070025
Sapan Bhatiace657e62017-04-21 14:20:41 +020026 # 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 Baker619de672016-06-20 12:49:38 -070038
39class ExampleTenant(TenantWithContainer):
40
Sapan Bhatiace657e62017-04-21 14:20:41 +020041 KIND = "exampleservice"
Scott Baker619de672016-06-20 12:49:38 -070042
Sapan Bhatiace657e62017-04-21 14:20:41 +020043 class Meta:
44 app_label = "exampleservice"
45 name = "exampletenant"
46 verbose_name = "Example Tenant"
Scott Baker619de672016-06-20 12:49:38 -070047
Sapan Bhatiace657e62017-04-21 14:20:41 +020048 # 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 Baker619de672016-06-20 12:49:38 -070051
Sapan Bhatiace657e62017-04-21 14:20:41 +020052 # Relations
53
Scott Baker619de672016-06-20 12:49:38 -070054
Sapan Bhatiace657e62017-04-21 14:20:41 +020055 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 Baker619de672016-06-20 12:49:38 -070070
71def 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 Bhatiace657e62017-04-21 14:20:41 +020079