Skip to content

Commit 876b444

Browse files
authored
Merge pull request #282 from rackerlabs/issue-281-add-created-last-updated-fields
Added created and last_updated fields to most models
2 parents 8780362 + 1fc2029 commit 876b444

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

console/django_scantron/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.46.0"
1+
__version__ = "1.47.0"

console/django_scantron/admin.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,34 @@ def _session_data(self, obj):
2020

2121
class ConfigurationAdmin(admin.ModelAdmin):
2222

23-
list_display = ("id", "enable_scan_retention", "scan_retention_in_days")
23+
list_display = ("id", "enable_scan_retention", "scan_retention_in_days", "created", "last_updated")
2424

2525

2626
class EngineAdmin(admin.ModelAdmin):
2727

28-
list_display = ("id", "scan_engine", "description", "api_token", "last_checkin")
28+
list_display = ("id", "scan_engine", "description", "api_token", "last_checkin", "created", "last_updated")
2929
readonly_fields = ("id", "scan_engine", "api_token", "last_checkin")
3030

3131

3232
class EnginePoolAdmin(admin.ModelAdmin):
3333

34-
list_display = ("id", "engine_pool_name")
34+
list_display = ("id", "engine_pool_name", "created", "last_updated")
3535

3636

3737
class GloballyExcludedTargetAdmin(admin.ModelAdmin):
3838

39-
list_display = ("id", "globally_excluded_targets", "note", "last_updated")
39+
list_display = ("id", "globally_excluded_targets", "note", "created", "last_updated")
4040

4141

4242
class ScanCommandAdmin(admin.ModelAdmin):
4343

44-
list_display = ("id", "scan_binary", "scan_command_name", "scan_command")
44+
list_display = ("id", "scan_binary", "scan_command_name", "scan_command", "created", "last_updated")
4545
list_filter = ("scan_binary",)
4646

4747

4848
class ScanAdmin(admin.ModelAdmin):
4949

50-
list_display = ("id", "site", "scan_name", "enable_scan", "start_time", "recurrences")
50+
list_display = ("id", "site", "scan_name", "enable_scan", "start_time", "recurrences", "created", "last_updated")
5151
list_filter = ("enable_scan",)
5252
exclude = ("completed_time", "result_file_base_name", "dtstart")
5353

@@ -67,6 +67,8 @@ class SiteAdmin(admin.ModelAdmin):
6767
"email_alert_addresses",
6868
"email_scan_diff",
6969
"email_scan_diff_addresses",
70+
"created",
71+
"last_updated",
7072
)
7173

7274

console/django_scantron/api/serializers.py

+8-22
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
class ConfigurationSerializer(serializers.ModelSerializer):
2121
class Meta:
2222
model = Configuration
23-
fields = ("id", "enable_scan_retention", "scan_retention_in_days")
23+
fields = ("id", "enable_scan_retention", "scan_retention_in_days", "created", "last_updated")
2424

2525

2626
class EngineSerializer(serializers.ModelSerializer):
2727
class Meta:
2828
model = Engine
29-
fields = ("id", "scan_engine", "description", "api_token", "last_checkin")
29+
fields = ("id", "scan_engine", "description", "api_token", "last_checkin", "created", "last_updated")
3030

3131

3232
class EnginePoolSerializer(serializers.ModelSerializer):
3333
class Meta:
3434
model = EnginePool
35-
fields = ("id", "engine_pool_name", "scan_engines")
35+
fields = ("id", "engine_pool_name", "scan_engines", "created", "last_updated")
3636

3737

3838
class GloballyExcludedTargetSerializer(serializers.ModelSerializer):
@@ -62,18 +62,13 @@ def validate(self, attrs):
6262

6363
class Meta:
6464
model = GloballyExcludedTarget
65-
fields = ("id", "globally_excluded_targets", "note", "last_updated")
65+
fields = ("id", "globally_excluded_targets", "note", "created", "last_updated")
6666

6767

6868
class ScanCommandSerializer(serializers.ModelSerializer):
6969
class Meta:
7070
model = ScanCommand
71-
fields = (
72-
"id",
73-
"scan_binary",
74-
"scan_command_name",
75-
"scan_command",
76-
)
71+
fields = ("id", "scan_binary", "scan_command_name", "scan_command", "created", "last_updated")
7772

7873

7974
class SiteSerializer(serializers.ModelSerializer):
@@ -164,24 +159,15 @@ class Meta:
164159
"email_alert_addresses",
165160
"email_scan_diff",
166161
"email_scan_diff_addresses",
162+
"created",
163+
"last_updated",
167164
)
168165

169166

170167
class ScanSerializer(serializers.ModelSerializer):
171-
# nested relationship
172-
# http://www.django-rest-framework.org/api-guide/relations/#nested-relationships
173-
# site = SiteSerializer(many=False)
174-
175168
class Meta:
176169
model = Scan
177-
fields = (
178-
"id",
179-
"site",
180-
"scan_name",
181-
"enable_scan",
182-
"start_time",
183-
"recurrences",
184-
)
170+
fields = ("id", "site", "scan_name", "enable_scan", "start_time", "recurrences", "created", "last_updated")
185171

186172

187173
class ScheduledScanSerializer(serializers.ModelSerializer):

console/django_scantron/models.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class Configuration(models.Model):
3737
verbose_name="Scan retention in days",
3838
help_text="The number of days to retain scan data, target files, and scan result files.",
3939
)
40+
created = models.DateTimeField(auto_now_add=True)
41+
last_updated = models.DateTimeField(auto_now=True, verbose_name="Last updated")
4042

4143
class Meta:
4244
verbose_name_plural = "Configuration"
@@ -63,6 +65,8 @@ class Engine(models.Model):
6365
description = models.CharField(unique=False, max_length=255, blank=True, verbose_name="Engine Description")
6466
api_token = models.CharField(unique=True, max_length=40, blank=False, verbose_name="API Key")
6567
last_checkin = models.DateTimeField(blank=True, null=True, verbose_name="Last Engine Check In")
68+
created = models.DateTimeField(auto_now_add=True)
69+
last_updated = models.DateTimeField(auto_now=True, verbose_name="Last updated")
6670

6771
def __str__(self):
6872
return str(self.scan_engine)
@@ -77,6 +81,8 @@ class EnginePool(models.Model):
7781
id = models.AutoField(primary_key=True, verbose_name="Engine Pool ID")
7882
engine_pool_name = models.CharField(unique=True, max_length=255, verbose_name="Engine Pool Name")
7983
scan_engines = models.ManyToManyField(Engine, verbose_name="Scan engines in pool")
84+
created = models.DateTimeField(auto_now_add=True)
85+
last_updated = models.DateTimeField(auto_now=True, verbose_name="Last updated")
8086

8187
def __str__(self):
8288
return str(self.engine_pool_name)
@@ -94,7 +100,7 @@ class GloballyExcludedTarget(models.Model):
94100
# is changed.
95101
globally_excluded_targets = models.CharField(
96102
unique=False,
97-
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
103+
max_length=4_194_304, # 2^22 = 4194304. See note above if this value is changed.
98104
validators=[
99105
RegexValidator(
100106
regex="^[a-zA-Z0-9/\.\:\- ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
@@ -104,6 +110,7 @@ class GloballyExcludedTarget(models.Model):
104110
verbose_name="Globally Excluded Targets",
105111
)
106112
note = models.TextField(unique=False, blank=True, verbose_name="Note")
113+
created = models.DateTimeField(auto_now_add=True)
107114
last_updated = models.DateTimeField(auto_now=True, verbose_name="Last updated")
108115

109116
def clean(self):
@@ -142,6 +149,8 @@ class ScanCommand(models.Model):
142149
scan_binary = models.CharField(max_length=7, choices=SCAN_BINARY, default="nmap", verbose_name="Scan binary")
143150
scan_command_name = models.CharField(unique=True, max_length=255, verbose_name="Scan command name")
144151
scan_command = models.TextField(unique=False, verbose_name="Scan command")
152+
created = models.DateTimeField(auto_now_add=True)
153+
last_updated = models.DateTimeField(auto_now=True, verbose_name="Last updated")
145154

146155
def __str__(self):
147156
return f"{self.scan_binary}||{self.scan_command_name}"
@@ -171,7 +180,7 @@ class Site(models.Model):
171180
# is changed.
172181
targets = models.CharField(
173182
unique=False,
174-
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
183+
max_length=4_194_304, # 2^22 = 4194304. See note above if this value is changed.
175184
validators=[
176185
RegexValidator(
177186
regex="^[a-zA-Z0-9/\.\:\- ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
@@ -186,7 +195,7 @@ class Site(models.Model):
186195
excluded_targets = models.CharField(
187196
unique=False,
188197
blank=True,
189-
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
198+
max_length=4_194_304, # 2^22 = 4194304. See note above if this value is changed.
190199
validators=[
191200
RegexValidator(
192201
regex="^[a-zA-Z0-9/\.\:\- ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
@@ -210,6 +219,8 @@ class Site(models.Model):
210219
email_scan_diff_addresses = models.CharField(
211220
unique=False, blank=True, max_length=4096, verbose_name="Email nmap scan diff addresses, comma separated"
212221
)
222+
created = models.DateTimeField(auto_now_add=True)
223+
last_updated = models.DateTimeField(auto_now=True, verbose_name="Last updated")
213224

214225
def clean(self):
215226
"""Checks for any invalid IPs, IP subnets, or FQDNs in the targets and excluded_targets fields."""
@@ -288,6 +299,8 @@ class Scan(models.Model):
288299
null=True,
289300
verbose_name="dtstart is the seed datetime object for recurrences (automatically modifed)",
290301
)
302+
created = models.DateTimeField(auto_now_add=True)
303+
last_updated = models.DateTimeField(auto_now=True, verbose_name="Last updated")
291304

292305
# dtstart is the seed datetime object when determining scan_scheduler.py's
293306
# scan_occurrences = scan.recurrences.between(beginning_of_today, end_of_today, dtstart=dtstart, inc=True),
@@ -362,7 +375,7 @@ class ScheduledScan(models.Model):
362375
# is changed.
363376
targets = models.CharField(
364377
unique=False,
365-
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
378+
max_length=4_194_304, # 2^22 = 4194304. See note above if this value is changed.
366379
validators=[
367380
RegexValidator(
368381
regex="^[a-zA-Z0-9/\.\: ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
@@ -377,7 +390,7 @@ class ScheduledScan(models.Model):
377390
excluded_targets = models.CharField(
378391
unique=False,
379392
blank=True,
380-
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
393+
max_length=4_194_304, # 2^22 = 4194304. See note above if this value is changed.
381394
validators=[
382395
RegexValidator(
383396
regex="^[a-zA-Z0-9/\.\: ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.

scantron_model_graph.png

10.4 KB
Loading

0 commit comments

Comments
 (0)