|
|
import xml.etree.ElementTree as et
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
ATTR_KEY = 'key'
|
|
|
ATTR_KEY_TYPE = 'type'
|
|
|
ATTR_LOCAL_ID = 'local-id'
|
|
|
|
|
|
|
|
|
class GlobalId(models.Model):
|
|
|
class Meta:
|
|
|
app_label = 'boards'
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
models.Model.__init__(self, *args, **kwargs)
|
|
|
|
|
|
if 'key' in kwargs and 'key_type' in kwargs and 'local_id' in kwargs:
|
|
|
self.key = kwargs['key']
|
|
|
self.key_type = kwargs['key_type']
|
|
|
self.local_id = kwargs['local_id']
|
|
|
|
|
|
key = models.TextField()
|
|
|
key_type = models.TextField()
|
|
|
local_id = models.IntegerField()
|
|
|
|
|
|
def __str__(self):
|
|
|
return '%s / %s / %d' % (self.key_type, self.key, self.local_id)
|
|
|
|
|
|
def to_xml_element(self, element: et.SubElement):
|
|
|
"""
|
|
|
Exports global id to an XML element.
|
|
|
"""
|
|
|
|
|
|
element.set(ATTR_KEY, self.key)
|
|
|
element.set(ATTR_KEY_TYPE, self.key_type)
|
|
|
element.set(ATTR_LOCAL_ID, str(self.local_id))
|
|
|
|
|
|
|
|
|
class Signature(models.Model):
|
|
|
class Meta:
|
|
|
app_label = 'boards'
|
|
|
|
|
|
key_type = models.TextField()
|
|
|
key = models.TextField()
|
|
|
signature = models.TextField()
|
|
|
|