class ReportPayload models Model b64content models TextField blank Fal

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class ReportPayload(models.Model):
b64content = models.TextField(blank=False, null=False, editable=False)
hsh = models.CharField(blank=False, null=False, editable=False)
format = models.CharField(max_length=50, null=False, blank=False)
report = models.ForeignKey(PrettyReport, related_name='payloads')
def __init__(self, *args, **kwargs):
if 'content' in kwargs:
self.content = content
del(kwargs['content']
super(ReportPayload, self).__init__(*args, **kwargs)
def _get_content(self):
assert(self.hsh == sha.new(self.b64content).digest(), "Content seems to be corrupted")
return base64.b64decode(self.b64content)
def _set_content(self, value):
self.b64content = base64.b64encode(value)
self.hsh = sha.new(self.b64content).digest()
content = property(get_content, set_content)