Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions common/peewee_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import datetime
from enum import Enum

from peewee import SQL
from peewee import AutoField
from peewee import BooleanField
from peewee import CharField
Expand All @@ -16,6 +17,7 @@
from peewee import Model
from peewee import TextField
from peewee import UUIDField
from peewee import fn
from playhouse.postgres_ext import ArrayField
from playhouse.postgres_ext import BinaryJSONField

Expand Down Expand Up @@ -131,6 +133,23 @@ class OperatingSystem(BaseModel):
cves_unpatched_moderate = IntegerField(null=False)
cves_unpatched_low = IntegerField(null=False)

@classmethod
def display_os_format(cls):
"""Expression for OS display string ('Name Major.Minor'), null handled as 'N/A'."""
# OS Name baseline
name_base = fn.COALESCE(cls.name, SQL("'N/A'"))
# Join Name and Major SPACE
name_major = fn.CONCAT_WS(" ", name_base, cls.major)
# Join result and Minor DOT
full_os_sql_string = fn.CONCAT_WS(".", name_major, cls.minor)

return full_os_sql_string

@classmethod
def sort_columns(cls):
"""Columns for sorting by OS, first by name then by major last by minor)"""
return [cls.name, cls.major, cls.minor]

class Meta:
"""operating_system table metadata"""

Expand Down
Loading