class SpatialUnitRelationship(RandomIDModel): """ A relationship between spatial units: encodes simple logical terms like ``su1 is-contained-in su2`` or ``su1 is-split-of su2``. May have additional attributes. """ # Possible spatial unit relationship types: TYPE_CHOICES is the # well-known name used by the JSONAttributesField field type to # manage the range of allowed attribute fields. TYPE_CHOICES = (('C', 'is-contained-in'), ('S', 'is-split-of'), ('M', 'is-merge-of')) # All spatial unit relationships are associated with a single # project. project = models.ForeignKey(Project, on_delete=models.CASCADE) # Spatial units in the relationship. su1 = TemporalForeignKey(SpatialUnit, on_delete=bitemporal.CASCADE) su2 = TemporalForeignKey(SpatialUnit, on_delete=bitemporal.CASCADE) # Spatial unit relationship type: used to manage range of allowed # attributes. type = models.CharField(max_length=1, choices=TYPE_CHOICES) # JSON attributes field with management of allowed members. attributes = JSONAttributesField()
class PartyRelationship(RandomIDModel): """ A relationship between parties: encodes simple logical terms like ``party1 is-spouse-of party2`` or ``party1 is-member-of party2``. May have additional type-dependent attributes. """ # Possible party relationship types: TYPE_CHOICES is the # well-known name used by the JSONAttributesField field type to # manage the range of allowed attribute fields. TYPE_CHOICES = (('S', 'is-spouse-of'), ('C', 'is-child-of'), ('M', 'is-member-of')) # All party relationships are associated with a single project. project = models.ForeignKey(Project, on_delete=models.CASCADE) # Parties to the relationship. party1 = TemporalForeignKey(Party, on_delete=bitemporal.CASCADE) party2 = TemporalForeignKey(Party, on_delete=bitemporal.CASCADE) # Party relationship type: used to manage range of allowed attributes. type = models.CharField(max_length=1, choices=TYPE_CHOICES) # JSON attributes field with management of allowed members. attributes = JSONAttributesField()
class Project(Model): name = models.CharField(max_length=200) organization = models.ForeignKey(Organization) country = CountryField() description = models.TextField(null=True) logo = TemporalForeignKey('Resource') urls = ArrayField(models.URLField()) contacts = JSONField() # List of JSON-ised hCard records. geometry = TemporalForeignKey('SpatialUnit') archived = models.BooleanField(default=False)
class Organization(Model): name = models.CharField(max_length=200) description = models.TextField(null=True) logo = TemporalForeignKey('Resource') urls = ArrayField(models.URLField()) contacts = JSONField() # List of JSON-ised hCard records. users = models.ManyToManyField('User') # Members of the organization. archived = models.BooleanField(default=False)
class Questionnaire(Model): raw_form = JSONField() name = models.CharField(max_length=100) label = models.CharField(max_length=200) publish = models.BooleanField(default=True) project = TemporalForeignKey(Project) id_string = models.CharField(max_length=200) form_id = models.PositiveIntegerField()
class Question(Model): TYPE_CHOICES = (('TX', 'text'), ('EN', 'end'), ('PH', 'phonenumber'), ('TD', 'today'), ('ST', 'start'), ('DI', 'deviceid'), ('DA', 'date'), ('DT', 'dateTime'), ('PH', 'photo'), ('S1', 'select one'), ('GE', 'geopoint'), ('NO', 'note'), ('IN', 'integer'), ('DE', 'decimal'), ('SI', 'subscriberid'), ('SA', 'select all that apply'), ('CA', 'calculate'), ('RE', 'repeat'), ('GR', 'group')) name = models.CharField(max_length=100) label = models.CharField(max_length=200) type = models.CharField(max_length=2, choices=TYPE_CHOICES) section = TemporalForeignKey(QuestionSection) group = TemporalForeignKey(QuestionGroup) questionnaire = TemporalForeignKey(Questionnaire) def has_options(self): return self.type in ['S1', 'SA']
class TenureRelationship(RandomIDModel): """ A tenure relationship between a single party and a single spatial unit: has a type and a set of attributes. """ # All tenure relationships are associated with a single project. project = models.ForeignKey(Project) # The party and spatial unit involved in the relationship. party = TemporalForeignKey(Party, on_delete=bitemporal.CASCADE) spatial_unit = TemporalForeignKey(SpatialUnit, on_delete=bitemporal.CASCADE) # Relationship type: used to manage range of allowed attributes. type = TemporalForeignKey(TenureRelationshipType) # JSON attributes field with management of allowed members. attributes = JSONAttributesField()
class TenureRelationshipType(Model): """ Tenure relationship types, e.g. freehold (right), occupancy (right), national park law (restriction), etc. """ TYPE_CHOICES = (('RIGHT', 'Right'), ('RESTR', 'Restriction'), ('RESPO', 'Responsibility')) # All tenure relationship types are associated with a single # project. project = TemporalForeignKey(Project, on_delete=bitemporal.CASCADE) # Basic type: right, restriction or responsibility. type = models.CharField(max_length=5, choices=TYPE_CHOICES, default='RIGHT') # Short name for tenure relationship type (e.g. "freehold", # "easement", "tenancy"). name = models.CharField(max_length=100) # Long human-readable name for relationship type. description = models.TextField()
class QuestionResponse(RandomIDModel): respondent = TemporalForeignKey(QuestionRespondent) question = TemporalForeignKey(Question) answer = models.CharField(max_length=200)
class QuestionRespondent(RandomIDModel): questionnaire = TemporalForeignKey(Questionnaire) uuid = models.UUIDField() ona_data_id = models.CharField(max_length=100)
class RawQuestionnaireData(RandomIDModel): questionnaire = TemporalForeignKey(Questionnaire) data = JSONField(null=True, default=dict())
class QuestionOption(Model): question = TemporalForeignKey(Question) name = models.CharField(max_length=100) label = models.CharField(max_length=200)
class QuestionGroup(Model): name = models.CharField(max_length=100) label = models.CharField(max_length=200) section = TemporalForeignKey(QuestionSection) parent = TemporalForeignKey('self') questionnaire = TemporalForeignKey(Questionnaire)
class QuestionSection(Model): name = models.CharField(max_length=100) label = models.CharField(max_length=200) publish = models.BooleanField(default=True) questionnaire = TemporalForeignKey(Questionnaire)