-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created gereralized Args/Kwargs model associated with each job type.
Model (not DB) validation prevents more than one of the potential fields from being set. Additional Javascript hides all but one value field in admin interface. Tests need to be written, but according to Factory Boy documentation "All factories for a Django Model should use the DjangoModelFactory base class", so I'll likely address that first.
- Loading branch information
Showing
5 changed files
with
207 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Generated by Django 2.0.7 on 2018-07-23 14:12 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contenttypes', '0002_remove_content_type_name'), | ||
('scheduler', '0006_added_args_kwargs'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='JobArg', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('str_val', models.CharField(blank=True, max_length=255, verbose_name='String Value')), | ||
('int_val', models.IntegerField(blank=True, null=True, verbose_name='Int Value')), | ||
('datetime_val', models.DateTimeField(blank=True, null=True, verbose_name='Datetime Value')), | ||
('arg_name', models.CharField(choices=[('str_val', 'string'), ('int_val', 'int'), ('datetime_val', 'Datetime')], default='str_val', max_length=12, verbose_name='Argument Type')), | ||
('object_id', models.PositiveIntegerField()), | ||
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='JobKwarg', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('str_val', models.CharField(blank=True, max_length=255, verbose_name='String Value')), | ||
('int_val', models.IntegerField(blank=True, null=True, verbose_name='Int Value')), | ||
('datetime_val', models.DateTimeField(blank=True, null=True, verbose_name='Datetime Value')), | ||
('arg_name', models.CharField(choices=[('str_val', 'string'), ('int_val', 'int'), ('datetime_val', 'Datetime')], default='str_val', max_length=12, verbose_name='Argument Type')), | ||
('object_id', models.PositiveIntegerField()), | ||
('key', models.CharField(max_length=255)), | ||
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.RemoveField( | ||
model_name='cronjob', | ||
name='callable_args', | ||
), | ||
migrations.RemoveField( | ||
model_name='cronjob', | ||
name='callable_kwargs', | ||
), | ||
migrations.RemoveField( | ||
model_name='repeatablejob', | ||
name='callable_args', | ||
), | ||
migrations.RemoveField( | ||
model_name='repeatablejob', | ||
name='callable_kwargs', | ||
), | ||
migrations.RemoveField( | ||
model_name='scheduledjob', | ||
name='callable_args', | ||
), | ||
migrations.RemoveField( | ||
model_name='scheduledjob', | ||
name='callable_kwargs', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(function($) { | ||
$(function() { | ||
var updateDisplayedFields = function(row) { | ||
const selectField = row.find('.field-arg_name select'), | ||
strVal = row.find('.field-str_val'), | ||
intVal = row.find('.field-int_val'), | ||
datetimeVal = row.find('.field-datetime_val'); | ||
|
||
var showRow = function(selector) { | ||
selector.show(); | ||
selector.find('label').addClass('required') | ||
}; | ||
var hideRow = function(selector) { | ||
selector.hide(); | ||
selector.find(':input').val(''); | ||
}; | ||
|
||
var toggleVerified = function(value) { | ||
value === 'str_val' ? showRow(strVal) : hideRow(strVal); | ||
value === 'int_val' ? showRow(intVal) : hideRow(intVal); | ||
value === 'datetime_val' ? showRow(datetimeVal) : hideRow(datetimeVal); | ||
}; | ||
toggleVerified(selectField.val()); | ||
selectField.change(function() { | ||
toggleVerified($(this).val()); | ||
}); | ||
}; | ||
|
||
$(document).on('formset:added', function (event, row, options) { | ||
updateDisplayedFields(row); | ||
}); | ||
|
||
|
||
$('.dynamic-scheduler-jobkwarg-content_type-object_id, ' + | ||
'.dynamic-scheduler-jobarg-content_type-object_id').each(function() { | ||
updateDisplayedFields($(this)); | ||
}); | ||
}); | ||
})(django.jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters