blob: d257032857083abcc2d77b98db3c363065786c94 [file] [log] [blame]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001from django.db import models
2from core.models import User
3import os
4from django.db import models
5from django.forms.models import model_to_dict
6
7
8# Create your models here.
9
10class HpcCoreBase(models.Model):
11
12 created = models.DateTimeField(auto_now_add=True)
13 updated = models.DateTimeField(auto_now=True)
14
15 class Meta:
16 abstract = True
17 app_label = "hpc"
18
19 def __init__(self, *args, **kwargs):
20 super(HpcCoreBase, self).__init__(*args, **kwargs)
21 self.__initial = self._dict
22
23 @property
24 def diff(self):
25 d1 = self.__initial
26 d2 = self._dict
27 diffs = [(k, (v, d2[k])) for k, v in d1.items() if v != d2[k]]
28 return dict(diffs)
29
30 @property
31 def has_changed(self):
32 return bool(self.diff)
33
34 @property
35 def changed_fields(self):
36 return self.diff.keys()
37
38 def get_field_diff(self, field_name):
39 return self.diff.get(field_name, None)
40
41 def save(self, *args, **kwargs):
42 super(HpcCoreBase, self).save(*args, **kwargs)
43
44 self.__initial = self._dict
45
46 @property
47 def _dict(self):
48 return model_to_dict(self, fields=[field.name for field in
49 self._meta.fields])
50
51
52class ServiceProvider(HpcCoreBase):
53 name = models.CharField(max_length=254,help_text="Service Provider Name")
54 description = models.TextField(max_length=254,null=True, blank=True, help_text="Description of Service Provider")
55 enabled = models.BooleanField(default=True)
56
57 def __unicode__(self): return u'%s' % (self.name)
58
59class ContentProvider(HpcCoreBase):
60 name = models.CharField(max_length=254)
61 enabled = models.BooleanField(default=True)
62 description = models.TextField(max_length=254,null=True, blank=True,help_text="Description of Content Provider")
63 serviceProvider = models.ForeignKey(ServiceProvider)
64
65 # Note user relationships are directed not requiring a role.
66 users = models.ManyToManyField(User)
67
68 def __unicode__(self): return u'%s' % (self.name)
69
70class OriginServer(HpcCoreBase):
71 url = models.URLField()
72 contentProvider = models.ForeignKey(ContentProvider)
73
74 authenticated = models.BooleanField(default=False, help_text="Status for this Site")
75 enabled = models.BooleanField(default=True, help_text="Status for this Site")
76 PROTOCOL_CHOICES = (('http', 'HTTP'),('rtmp', 'RTMP'), ('rtp', 'RTP'),('shout', 'SHOUTcast'))
77 protocol = models.CharField(default="HTTP", max_length = 12, choices=PROTOCOL_CHOICES)
78 redirects = models.BooleanField(default=True, help_text="Indicates whether Origin Server redirects should be used for this Origin Server")
79 description = models.TextField(null=True, blank=True, max_length=255)
80
81 def __unicode__(self): return u'%s' % (self.url)
82
83class CDNPrefix(HpcCoreBase):
84 prefix = models.CharField(max_length=200, help_text="Registered Prefix for Domain")
85 contentProvider = models.ForeignKey(ContentProvider)
86 description = models.TextField(max_length=254,null=True, blank=True,help_text="Description of Content Provider")
87
88 defaultOriginServer = models.ForeignKey(OriginServer)
89 enabled = models.BooleanField(default=True)
90
91 def __unicode__(self): return u'%s' % (self.prefix)
92