예제 #1
0
class Survey(ObjectRoot):
    class Meta:
        db_table = "survey"
        ordering = ["-created_at"]

    name = models.CharField(max_length=64)
    definition = JsonYamlField()
    questions = models.ManyToManyField(Question, blank=True)
    is_public = models.BooleanField(default=False)

    objects = AgencyObjectManager()

    def get_definition_items(self):
        def traverse_items(current, all_items=[]):
            yield current
            for item in current.get("items", []):
                yield item

        yield from traverse_items(self.definition)

    def get_related_question_ids(self):
        for item in self.get_definition_items():
            if item.get("type", None) == "question" and "questionId" in item:
                yield (item.get("id", None), item["questionId"])

    def __str__(self):
        return self.name
예제 #2
0
class Question(ObjectRoot):
    class Meta:
        ordering = ["-created_at"]

    title = models.CharField(max_length=64)
    description = models.TextField(default="", blank=True)
    category = models.CharField(choices=QuestionCategory.choices,
                                max_length=32,
                                default=QuestionCategory.TEXT)
    options = ArrayField(models.CharField(max_length=64),
                         null=True,
                         blank=True)
    other = models.BooleanField(default=False)
    refusable = models.BooleanField(default=False)
    rows = models.IntegerField(null=True, blank=True)
    columns = JsonYamlField(null=True, blank=True)
    is_public = models.BooleanField(default=False)

    objects = AgencyObjectManager()

    @property
    def usage_count(self):
        return self.survey_set.count()

    def __str__(self):
        return self.title
예제 #3
0
class Response(ObjectRoot):
    class Meta:
        ordering = ['-created_at']

    respondent_type = models.ForeignKey(ContentType,
                                        null=True,
                                        related_name='responses',
                                        on_delete=models.PROTECT)
    respondent_id = models.UUIDField(primary_key=False)
    respondent = GenericForeignKey('respondent_type', 'respondent_id')
    survey = models.ForeignKey(Survey,
                               related_name='responses',
                               on_delete=models.PROTECT)

    objects = AgencyObjectManager()
예제 #4
0
class Client(ObjectRoot):
    class Meta:
        db_table = 'client'
        ordering = ['-created_at']
        # permissions = [
        #     ("view", "Can change the status of tasks"),
        # ]
    first_name = models.CharField(max_length=64)
    middle_name = models.CharField(max_length=64, default='', blank=True)
    last_name = models.CharField(max_length=64)
    dob = models.DateField()

    objects = AgencyObjectManager()

    @property
    def full_name(self):
        parts = [self.first_name, self.middle_name, self.last_name]
        return ' '.join([p for p in parts if p])

    def __str__(self):
        return self.full_name
예제 #5
0
class Client(ObjectRoot):
    class Meta:
        db_table = "client"
        ordering = ["-created_at"]
        permissions = (
            ("view_client_agency", "Can view client - agency"),
            ("change_client_agency", "Can change client - agency"),
            ("delete_client_agency", "Can delete client - agency"),
            ("view_client_all", "Can view client - globally"),
            ("change_client_all", "Can change client - globally"),
            ("delete_client_all", "Can delete client - globally"),
        )

    first_name = models.CharField(max_length=64)
    middle_name = models.CharField(max_length=64, default="", blank=True)
    last_name = models.CharField(max_length=64)
    dob = models.DateField(
        null=True
    )  # MPR (MPR file does not contain dob column, therefore null=True)
    ssn = models.CharField(max_length=64, blank=True, default="")
    is_new = models.BooleanField(default=True)

    snap_id = models.CharField(max_length=256, blank=True, null=True)
    address = models.OneToOneField(ClientAddress,
                                   on_delete=models.CASCADE,
                                   null=True)

    objects = AgencyObjectManager()

    @property
    def full_name(self):
        parts = [self.first_name, self.middle_name, self.last_name]
        return " ".join([p for p in parts if p])

    def __str__(self):
        return self.full_name
예제 #6
0
class Response(ObjectRoot):
    class Meta:
        ordering = ["-created_at"]

    survey = models.ForeignKey(Survey,
                               related_name="responses",
                               on_delete=models.PROTECT)
    client = models.ForeignKey(Client,
                               related_name="responses",
                               on_delete=models.CASCADE)
    response_context_type = models.ForeignKey(
        ContentType,
        related_name="responses",
        on_delete=models.SET_NULL,
        blank=True,
        null=True,
    )
    response_context_id = models.UUIDField(primary_key=False,
                                           blank=True,
                                           null=True)
    response_context = GenericForeignKey("response_context_type",
                                         "response_context_id")

    objects = AgencyObjectManager()