Skip to content

Models

Django Models

Models for the DCPS app.

Functions:

Name Description
project_timestamp

Updates the last_modified timestamp of a project if it exists.

Enumerations

ViewAccess: Enumeration for view access levels.

Models

UserProfile: A user profile model. Project: Project model. UserProjectAttribute: A user project attribute model. ProjectGroup: A project group model.

ViewAccess

Bases: TextChoices

Enumeration for view access levels.

Attributes: PRIVATE: Represents a private access level. MEMBERS: Represents an access level for members only. PUBLIC: Represents a public access level.

Source code in app/dcsp/app/models.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class ViewAccess(TextChoices):
    """
    Enumeration for view access levels.

    Attributes:
    PRIVATE: Represents a private access level.
    MEMBERS: Represents an access level for members only.
    PUBLIC: Represents a public access level.
    """

    PRIVATE = "PR", "private"
    MEMBERS = "ME", "members"
    PUBLIC = "PU", "public"

    # TODO #61 need to test this
    @classmethod
    def get_label(cls, choice: str) -> str:
        return cls(choice).label

project_timestamp(project_id)

Updates the last_modified timestamp of a project if it exists.

Parameters:

Name Type Description Default
project_id int

The id of the project to update.

required

Returns:

Name Type Description
bool bool

True if the project exists and was updated, False otherwise.

Source code in app/dcsp/app/models.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def project_timestamp(project_id: int) -> bool:
    """Updates the last_modified timestamp of a project if it exists.

    Args:
        project_id (int): The id of the project to update.

    Returns:
        bool: True if the project exists and was updated, False otherwise.
    """
    project: Optional[Project] = None

    if not isinstance(project_id, int):
        raise TypeError("project_id must be an integer")

    if not Project.objects.filter(id=project_id).exists():
        return False

    project = Project.objects.get(id=project_id)
    project.last_modified = timezone.now()
    project.save()
    return True